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