David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Alex Deymo | 759c275 | 2014-03-17 21:09:36 -0700 | [diff] [blame] | 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_P2P_MANAGER_H_ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_P2P_MANAGER_H_ |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 7 | |
Alex Deymo | 04f2b38 | 2014-03-21 15:45:17 -0700 | [diff] [blame] | 8 | #include "update_engine/p2p_manager.h" |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 9 | |
| 10 | namespace chromeos_update_engine { |
| 11 | |
| 12 | // A fake implementation of P2PManager. |
| 13 | class FakeP2PManager : public P2PManager { |
| 14 | public: |
| 15 | FakeP2PManager() : |
| 16 | is_p2p_enabled_(false), |
| 17 | ensure_p2p_running_result_(false), |
| 18 | ensure_p2p_not_running_result_(false), |
| 19 | perform_housekeeping_result_(false), |
| 20 | count_shared_files_result_(0) {} |
| 21 | |
| 22 | virtual ~FakeP2PManager() {} |
| 23 | |
| 24 | // P2PManager overrides. |
David Zeuthen | 92d9c8b | 2013-09-11 10:58:11 -0700 | [diff] [blame] | 25 | virtual void SetDevicePolicy(const policy::DevicePolicy* device_policy) {} |
| 26 | |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 27 | virtual bool IsP2PEnabled() { |
| 28 | return is_p2p_enabled_; |
| 29 | } |
| 30 | |
| 31 | virtual bool EnsureP2PRunning() { |
| 32 | return ensure_p2p_running_result_; |
| 33 | } |
| 34 | |
| 35 | virtual bool EnsureP2PNotRunning() { |
| 36 | return ensure_p2p_not_running_result_; |
| 37 | } |
| 38 | |
| 39 | virtual bool PerformHousekeeping() { |
| 40 | return perform_housekeeping_result_; |
| 41 | } |
| 42 | |
| 43 | virtual void LookupUrlForFile(const std::string& file_id, |
| 44 | size_t minimum_size, |
| 45 | base::TimeDelta max_time_to_wait, |
| 46 | LookupCallback callback) { |
| 47 | callback.Run(lookup_url_for_file_result_); |
| 48 | } |
| 49 | |
| 50 | virtual bool FileShare(const std::string& file_id, |
| 51 | size_t expected_size) { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | virtual base::FilePath FileGetPath(const std::string& file_id) { |
| 56 | return base::FilePath(); |
| 57 | } |
| 58 | |
| 59 | virtual ssize_t FileGetSize(const std::string& file_id) { |
| 60 | return -1; |
| 61 | } |
| 62 | |
| 63 | virtual ssize_t FileGetExpectedSize(const std::string& file_id) { |
| 64 | return -1; |
| 65 | } |
| 66 | |
| 67 | virtual bool FileGetVisible(const std::string& file_id, |
| 68 | bool *out_result) { |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | virtual bool FileMakeVisible(const std::string& file_id) { |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | virtual int CountSharedFiles() { |
| 77 | return count_shared_files_result_; |
| 78 | } |
| 79 | |
| 80 | // Methods for controlling what the fake returns and how it acts. |
| 81 | void SetP2PEnabled(bool is_p2p_enabled) { |
| 82 | is_p2p_enabled_ = is_p2p_enabled; |
| 83 | } |
| 84 | |
| 85 | void SetEnsureP2PRunningResult(bool ensure_p2p_running_result) { |
| 86 | ensure_p2p_running_result_ = ensure_p2p_running_result; |
| 87 | } |
| 88 | |
| 89 | void SetEnsureP2PNotRunningResult(bool ensure_p2p_not_running_result) { |
| 90 | ensure_p2p_not_running_result_ = ensure_p2p_not_running_result; |
| 91 | } |
| 92 | |
| 93 | void SetPerformHousekeepingResult(bool perform_housekeeping_result) { |
| 94 | perform_housekeeping_result_ = perform_housekeeping_result; |
| 95 | } |
| 96 | |
| 97 | void SetCountSharedFilesResult(int count_shared_files_result) { |
| 98 | count_shared_files_result_ = count_shared_files_result; |
| 99 | } |
| 100 | |
| 101 | void SetLookupUrlForFileResult(const std::string& url) { |
| 102 | lookup_url_for_file_result_ = url; |
| 103 | } |
| 104 | |
| 105 | private: |
| 106 | bool is_p2p_enabled_; |
| 107 | bool ensure_p2p_running_result_; |
| 108 | bool ensure_p2p_not_running_result_; |
| 109 | bool perform_housekeeping_result_; |
| 110 | int count_shared_files_result_; |
| 111 | std::string lookup_url_for_file_result_; |
| 112 | |
| 113 | DISALLOW_COPY_AND_ASSIGN(FakeP2PManager); |
| 114 | }; |
| 115 | |
| 116 | } // namespace chromeos_update_engine |
| 117 | |
Alex Deymo | 759c275 | 2014-03-17 21:09:36 -0700 | [diff] [blame] | 118 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_P2P_MANAGER_H_ |