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 | 4a0321b | 2014-10-28 15:57:30 -0700 | [diff] [blame] | 22 | count_shared_files_result_(0) {} |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 23 | |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 24 | // P2PManager overrides. |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 25 | void SetDevicePolicy(const policy::DevicePolicy* device_policy) override {} |
David Zeuthen | 92d9c8b | 2013-09-11 10:58:11 -0700 | [diff] [blame] | 26 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 27 | bool IsP2PEnabled() override { |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 28 | return is_p2p_enabled_; |
| 29 | } |
| 30 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 31 | bool EnsureP2PRunning() override { |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 32 | return ensure_p2p_running_result_; |
| 33 | } |
| 34 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 35 | bool EnsureP2PNotRunning() override { |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 36 | return ensure_p2p_not_running_result_; |
| 37 | } |
| 38 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 39 | bool PerformHousekeeping() override { |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 40 | return perform_housekeeping_result_; |
| 41 | } |
| 42 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 43 | void LookupUrlForFile(const std::string& file_id, |
| 44 | size_t minimum_size, |
| 45 | base::TimeDelta max_time_to_wait, |
| 46 | LookupCallback callback) override { |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 47 | callback.Run(lookup_url_for_file_result_); |
| 48 | } |
| 49 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 50 | bool FileShare(const std::string& file_id, |
| 51 | size_t expected_size) override { |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 52 | return false; |
| 53 | } |
| 54 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 55 | base::FilePath FileGetPath(const std::string& file_id) override { |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 56 | return base::FilePath(); |
| 57 | } |
| 58 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 59 | ssize_t FileGetSize(const std::string& file_id) override { |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 60 | return -1; |
| 61 | } |
| 62 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 63 | ssize_t FileGetExpectedSize(const std::string& file_id) override { |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 64 | return -1; |
| 65 | } |
| 66 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 67 | bool FileGetVisible(const std::string& file_id, |
| 68 | bool *out_result) override { |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 69 | return false; |
| 70 | } |
| 71 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 72 | bool FileMakeVisible(const std::string& file_id) override { |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 73 | return false; |
| 74 | } |
| 75 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 76 | int CountSharedFiles() override { |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 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 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 105 | private: |
David Zeuthen | 3ff6e6e | 2013-08-06 12:08:57 -0700 | [diff] [blame] | 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 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 118 | #endif // UPDATE_ENGINE_FAKE_P2P_MANAGER_H_ |