blob: ce214e4d464c8d2debe138bd8f6ba6500736e482 [file] [log] [blame]
David Zeuthen3ff6e6e2013-08-06 12:08:57 -07001// 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 Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_FAKE_P2P_MANAGER_H_
6#define UPDATE_ENGINE_FAKE_P2P_MANAGER_H_
David Zeuthen3ff6e6e2013-08-06 12:08:57 -07007
Alex Vakulenkod2779df2014-06-16 13:19:00 -07008#include <string>
9
Alex Deymo04f2b382014-03-21 15:45:17 -070010#include "update_engine/p2p_manager.h"
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070011
12namespace chromeos_update_engine {
13
14// A fake implementation of P2PManager.
15class FakeP2PManager : public P2PManager {
Alex Vakulenkod2779df2014-06-16 13:19:00 -070016 public:
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070017 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 Arnold4a0321b2014-10-28 15:57:30 -070022 count_shared_files_result_(0) {}
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070023
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070024 // P2PManager overrides.
Alex Deymo610277e2014-11-11 21:18:11 -080025 void SetDevicePolicy(const policy::DevicePolicy* device_policy) override {}
David Zeuthen92d9c8b2013-09-11 10:58:11 -070026
Alex Deymo610277e2014-11-11 21:18:11 -080027 bool IsP2PEnabled() override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070028 return is_p2p_enabled_;
29 }
30
Alex Deymo610277e2014-11-11 21:18:11 -080031 bool EnsureP2PRunning() override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070032 return ensure_p2p_running_result_;
33 }
34
Alex Deymo610277e2014-11-11 21:18:11 -080035 bool EnsureP2PNotRunning() override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070036 return ensure_p2p_not_running_result_;
37 }
38
Alex Deymo610277e2014-11-11 21:18:11 -080039 bool PerformHousekeeping() override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070040 return perform_housekeeping_result_;
41 }
42
Alex Deymo610277e2014-11-11 21:18:11 -080043 void LookupUrlForFile(const std::string& file_id,
44 size_t minimum_size,
45 base::TimeDelta max_time_to_wait,
46 LookupCallback callback) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070047 callback.Run(lookup_url_for_file_result_);
48 }
49
Alex Deymo610277e2014-11-11 21:18:11 -080050 bool FileShare(const std::string& file_id,
51 size_t expected_size) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070052 return false;
53 }
54
Alex Deymo610277e2014-11-11 21:18:11 -080055 base::FilePath FileGetPath(const std::string& file_id) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070056 return base::FilePath();
57 }
58
Alex Deymo610277e2014-11-11 21:18:11 -080059 ssize_t FileGetSize(const std::string& file_id) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070060 return -1;
61 }
62
Alex Deymo610277e2014-11-11 21:18:11 -080063 ssize_t FileGetExpectedSize(const std::string& file_id) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070064 return -1;
65 }
66
Alex Deymo610277e2014-11-11 21:18:11 -080067 bool FileGetVisible(const std::string& file_id,
68 bool *out_result) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070069 return false;
70 }
71
Alex Deymo610277e2014-11-11 21:18:11 -080072 bool FileMakeVisible(const std::string& file_id) override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070073 return false;
74 }
75
Alex Deymo610277e2014-11-11 21:18:11 -080076 int CountSharedFiles() override {
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070077 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 Vakulenkod2779df2014-06-16 13:19:00 -0700105 private:
David Zeuthen3ff6e6e2013-08-06 12:08:57 -0700106 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 Arnoldcf175a02014-07-10 16:48:47 -0700118#endif // UPDATE_ENGINE_FAKE_P2P_MANAGER_H_