fake_p2p_manager.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. //
  16. #ifndef UPDATE_ENGINE_FAKE_P2P_MANAGER_H_
  17. #define UPDATE_ENGINE_FAKE_P2P_MANAGER_H_
  18. #include <string>
  19. #include "update_engine/p2p_manager.h"
  20. namespace chromeos_update_engine {
  21. // A fake implementation of P2PManager.
  22. class FakeP2PManager : public P2PManager {
  23. public:
  24. FakeP2PManager()
  25. : is_p2p_enabled_(false),
  26. ensure_p2p_running_result_(false),
  27. ensure_p2p_not_running_result_(false),
  28. perform_housekeeping_result_(false),
  29. count_shared_files_result_(0) {}
  30. // P2PManager overrides.
  31. void SetDevicePolicy(const policy::DevicePolicy* device_policy) override {}
  32. bool IsP2PEnabled() override { return is_p2p_enabled_; }
  33. bool EnsureP2PRunning() override { return ensure_p2p_running_result_; }
  34. bool EnsureP2PNotRunning() override { return ensure_p2p_not_running_result_; }
  35. bool PerformHousekeeping() override { return perform_housekeeping_result_; }
  36. void LookupUrlForFile(const std::string& file_id,
  37. size_t minimum_size,
  38. base::TimeDelta max_time_to_wait,
  39. LookupCallback callback) override {
  40. callback.Run(lookup_url_for_file_result_);
  41. }
  42. bool FileShare(const std::string& file_id, size_t expected_size) override {
  43. return false;
  44. }
  45. base::FilePath FileGetPath(const std::string& file_id) override {
  46. return base::FilePath();
  47. }
  48. ssize_t FileGetSize(const std::string& file_id) override { return -1; }
  49. ssize_t FileGetExpectedSize(const std::string& file_id) override {
  50. return -1;
  51. }
  52. bool FileGetVisible(const std::string& file_id, bool* out_result) override {
  53. return false;
  54. }
  55. bool FileMakeVisible(const std::string& file_id) override { return false; }
  56. int CountSharedFiles() override { return count_shared_files_result_; }
  57. // Methods for controlling what the fake returns and how it acts.
  58. void SetP2PEnabled(bool is_p2p_enabled) { is_p2p_enabled_ = is_p2p_enabled; }
  59. void SetEnsureP2PRunningResult(bool ensure_p2p_running_result) {
  60. ensure_p2p_running_result_ = ensure_p2p_running_result;
  61. }
  62. void SetEnsureP2PNotRunningResult(bool ensure_p2p_not_running_result) {
  63. ensure_p2p_not_running_result_ = ensure_p2p_not_running_result;
  64. }
  65. void SetPerformHousekeepingResult(bool perform_housekeeping_result) {
  66. perform_housekeeping_result_ = perform_housekeeping_result;
  67. }
  68. void SetCountSharedFilesResult(int count_shared_files_result) {
  69. count_shared_files_result_ = count_shared_files_result;
  70. }
  71. void SetLookupUrlForFileResult(const std::string& url) {
  72. lookup_url_for_file_result_ = url;
  73. }
  74. private:
  75. bool is_p2p_enabled_;
  76. bool ensure_p2p_running_result_;
  77. bool ensure_p2p_not_running_result_;
  78. bool perform_housekeeping_result_;
  79. int count_shared_files_result_;
  80. std::string lookup_url_for_file_result_;
  81. DISALLOW_COPY_AND_ASSIGN(FakeP2PManager);
  82. };
  83. } // namespace chromeos_update_engine
  84. #endif // UPDATE_ENGINE_FAKE_P2P_MANAGER_H_