blob: a8cf4ea62ab5406e58311933239eccf969cd169a [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2013 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070016
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_FAKE_P2P_MANAGER_H_
18#define UPDATE_ENGINE_FAKE_P2P_MANAGER_H_
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070019
Alex Vakulenkod2779df2014-06-16 13:19:00 -070020#include <string>
21
Alex Deymo04f2b382014-03-21 15:45:17 -070022#include "update_engine/p2p_manager.h"
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070023
24namespace chromeos_update_engine {
25
26// A fake implementation of P2PManager.
27class FakeP2PManager : public P2PManager {
Alex Vakulenkod2779df2014-06-16 13:19:00 -070028 public:
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070029 FakeP2PManager() :
30 is_p2p_enabled_(false),
31 ensure_p2p_running_result_(false),
32 ensure_p2p_not_running_result_(false),
33 perform_housekeeping_result_(false),
Gilad Arnold4a0321b2014-10-28 15:57:30 -070034 count_shared_files_result_(0) {}
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070035
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070036 // P2PManager overrides.
Alex Deymo610277e2014-11-11 21:18:11 -080037 void SetDevicePolicy(const policy::DevicePolicy* device_policy) override {}
David Zeuthen92d9c8b2013-09-11 10:58:11 -070038
Alex Deymo610277e2014-11-11 21:18:11 -080039 bool IsP2PEnabled() override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070040 return is_p2p_enabled_;
41 }
42
Alex Deymo610277e2014-11-11 21:18:11 -080043 bool EnsureP2PRunning() override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070044 return ensure_p2p_running_result_;
45 }
46
Alex Deymo610277e2014-11-11 21:18:11 -080047 bool EnsureP2PNotRunning() override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070048 return ensure_p2p_not_running_result_;
49 }
50
Alex Deymo610277e2014-11-11 21:18:11 -080051 bool PerformHousekeeping() override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070052 return perform_housekeeping_result_;
53 }
54
Alex Deymo610277e2014-11-11 21:18:11 -080055 void LookupUrlForFile(const std::string& file_id,
56 size_t minimum_size,
57 base::TimeDelta max_time_to_wait,
58 LookupCallback callback) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070059 callback.Run(lookup_url_for_file_result_);
60 }
61
Alex Deymo610277e2014-11-11 21:18:11 -080062 bool FileShare(const std::string& file_id,
63 size_t expected_size) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070064 return false;
65 }
66
Alex Deymo610277e2014-11-11 21:18:11 -080067 base::FilePath FileGetPath(const std::string& file_id) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070068 return base::FilePath();
69 }
70
Alex Deymo610277e2014-11-11 21:18:11 -080071 ssize_t FileGetSize(const std::string& file_id) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070072 return -1;
73 }
74
Alex Deymo610277e2014-11-11 21:18:11 -080075 ssize_t FileGetExpectedSize(const std::string& file_id) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070076 return -1;
77 }
78
Alex Deymo610277e2014-11-11 21:18:11 -080079 bool FileGetVisible(const std::string& file_id,
80 bool *out_result) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070081 return false;
82 }
83
Alex Deymo610277e2014-11-11 21:18:11 -080084 bool FileMakeVisible(const std::string& file_id) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070085 return false;
86 }
87
Alex Deymo610277e2014-11-11 21:18:11 -080088 int CountSharedFiles() override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070089 return count_shared_files_result_;
90 }
91
92 // Methods for controlling what the fake returns and how it acts.
93 void SetP2PEnabled(bool is_p2p_enabled) {
94 is_p2p_enabled_ = is_p2p_enabled;
95 }
96
97 void SetEnsureP2PRunningResult(bool ensure_p2p_running_result) {
98 ensure_p2p_running_result_ = ensure_p2p_running_result;
99 }
100
101 void SetEnsureP2PNotRunningResult(bool ensure_p2p_not_running_result) {
102 ensure_p2p_not_running_result_ = ensure_p2p_not_running_result;
103 }
104
105 void SetPerformHousekeepingResult(bool perform_housekeeping_result) {
106 perform_housekeeping_result_ = perform_housekeeping_result;
107 }
108
109 void SetCountSharedFilesResult(int count_shared_files_result) {
110 count_shared_files_result_ = count_shared_files_result;
111 }
112
113 void SetLookupUrlForFileResult(const std::string& url) {
114 lookup_url_for_file_result_ = url;
115 }
116
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700117 private:
David Zeuthen3ff6e6e2013-08-06 12:08:57 -0700118 bool is_p2p_enabled_;
119 bool ensure_p2p_running_result_;
120 bool ensure_p2p_not_running_result_;
121 bool perform_housekeeping_result_;
122 int count_shared_files_result_;
123 std::string lookup_url_for_file_result_;
124
125 DISALLOW_COPY_AND_ASSIGN(FakeP2PManager);
126};
127
128} // namespace chromeos_update_engine
129
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700130#endif // UPDATE_ENGINE_FAKE_P2P_MANAGER_H_