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 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_FAKE_P2P_MANAGER_H_ |
| 6 | #define UPDATE_ENGINE_FAKE_P2P_MANAGER_H_ |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 7 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Alex Deymo | 04f2b38 | 2014-03-21 15:45:17 -0700 | [diff] [blame] | 10 | #include "update_engine/p2p_manager.h" |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 11 | |
| 12 | namespace chromeos_update_engine { |
| 13 | |
| 14 | // A fake implementation of P2PManager. |
| 15 | class FakeP2PManager : public P2PManager { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 16 | public: |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 17 | FakeP2PManager() : |
| 18 | is_p2p_enabled_(false), |
| 19 | ensure_p2p_running_result_(false), |
| 20 | ensure_p2p_not_running_result_(false), |
| 21 | perform_housekeeping_result_(false), |
Gilad Arnold | ccd0957 | 2014-10-27 13:37:50 -0700 | [diff] [blame] | 22 | count_shared_files_result_(0), |
| 23 | set_p2p_enabled_pref_result_(true) {} |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 24 | |
| 25 | virtual ~FakeP2PManager() {} |
| 26 | |
| 27 | // P2PManager overrides. |
David Zeuthen | 92d9c8b | 2013-09-11 10:58:11 -0700 | [diff] [blame] | 28 | virtual void SetDevicePolicy(const policy::DevicePolicy* device_policy) {} |
| 29 | |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 30 | virtual bool IsP2PEnabled() { |
| 31 | return is_p2p_enabled_; |
| 32 | } |
| 33 | |
| 34 | virtual bool EnsureP2PRunning() { |
| 35 | return ensure_p2p_running_result_; |
| 36 | } |
| 37 | |
| 38 | virtual bool EnsureP2PNotRunning() { |
| 39 | return ensure_p2p_not_running_result_; |
| 40 | } |
| 41 | |
| 42 | virtual bool PerformHousekeeping() { |
| 43 | return perform_housekeeping_result_; |
| 44 | } |
| 45 | |
| 46 | virtual void LookupUrlForFile(const std::string& file_id, |
| 47 | size_t minimum_size, |
| 48 | base::TimeDelta max_time_to_wait, |
| 49 | LookupCallback callback) { |
| 50 | callback.Run(lookup_url_for_file_result_); |
| 51 | } |
| 52 | |
| 53 | virtual bool FileShare(const std::string& file_id, |
| 54 | size_t expected_size) { |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | virtual base::FilePath FileGetPath(const std::string& file_id) { |
| 59 | return base::FilePath(); |
| 60 | } |
| 61 | |
| 62 | virtual ssize_t FileGetSize(const std::string& file_id) { |
| 63 | return -1; |
| 64 | } |
| 65 | |
| 66 | virtual ssize_t FileGetExpectedSize(const std::string& file_id) { |
| 67 | return -1; |
| 68 | } |
| 69 | |
| 70 | virtual bool FileGetVisible(const std::string& file_id, |
| 71 | bool *out_result) { |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | virtual bool FileMakeVisible(const std::string& file_id) { |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | virtual int CountSharedFiles() { |
| 80 | return count_shared_files_result_; |
| 81 | } |
| 82 | |
Gilad Arnold | ccd0957 | 2014-10-27 13:37:50 -0700 | [diff] [blame] | 83 | bool SetP2PEnabledPref(bool /* enabled */) override { |
| 84 | return set_p2p_enabled_pref_result_; |
| 85 | } |
| 86 | |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 87 | // Methods for controlling what the fake returns and how it acts. |
| 88 | void SetP2PEnabled(bool is_p2p_enabled) { |
| 89 | is_p2p_enabled_ = is_p2p_enabled; |
| 90 | } |
| 91 | |
| 92 | void SetEnsureP2PRunningResult(bool ensure_p2p_running_result) { |
| 93 | ensure_p2p_running_result_ = ensure_p2p_running_result; |
| 94 | } |
| 95 | |
| 96 | void SetEnsureP2PNotRunningResult(bool ensure_p2p_not_running_result) { |
| 97 | ensure_p2p_not_running_result_ = ensure_p2p_not_running_result; |
| 98 | } |
| 99 | |
| 100 | void SetPerformHousekeepingResult(bool perform_housekeeping_result) { |
| 101 | perform_housekeeping_result_ = perform_housekeeping_result; |
| 102 | } |
| 103 | |
| 104 | void SetCountSharedFilesResult(int count_shared_files_result) { |
| 105 | count_shared_files_result_ = count_shared_files_result; |
| 106 | } |
| 107 | |
Gilad Arnold | ccd0957 | 2014-10-27 13:37:50 -0700 | [diff] [blame] | 108 | void SetSetP2PEnabledPrefResult(bool set_p2p_enabled_pref_result) { |
| 109 | set_p2p_enabled_pref_result_ = set_p2p_enabled_pref_result; |
| 110 | } |
| 111 | |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 112 | void SetLookupUrlForFileResult(const std::string& url) { |
| 113 | lookup_url_for_file_result_ = url; |
| 114 | } |
| 115 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 116 | private: |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 117 | bool is_p2p_enabled_; |
| 118 | bool ensure_p2p_running_result_; |
| 119 | bool ensure_p2p_not_running_result_; |
| 120 | bool perform_housekeeping_result_; |
| 121 | int count_shared_files_result_; |
Gilad Arnold | ccd0957 | 2014-10-27 13:37:50 -0700 | [diff] [blame] | 122 | bool set_p2p_enabled_pref_result_; |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 123 | std::string lookup_url_for_file_result_; |
| 124 | |
| 125 | DISALLOW_COPY_AND_ASSIGN(FakeP2PManager); |
| 126 | }; |
| 127 | |
| 128 | } // namespace chromeos_update_engine |
| 129 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 130 | #endif // UPDATE_ENGINE_FAKE_P2P_MANAGER_H_ |