blob: 9ec0812ae9d270a3663fd97f342dd91bda7366a3 [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 Arnoldccd09572014-10-27 13:37:50 -070022 count_shared_files_result_(0),
23 set_p2p_enabled_pref_result_(true) {}
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070024
25 virtual ~FakeP2PManager() {}
26
27 // P2PManager overrides.
David Zeuthen92d9c8b2013-09-11 10:58:11 -070028 virtual void SetDevicePolicy(const policy::DevicePolicy* device_policy) {}
29
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070030 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 Arnoldccd09572014-10-27 13:37:50 -070083 bool SetP2PEnabledPref(bool /* enabled */) override {
84 return set_p2p_enabled_pref_result_;
85 }
86
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070087 // 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 Arnoldccd09572014-10-27 13:37:50 -0700108 void SetSetP2PEnabledPrefResult(bool set_p2p_enabled_pref_result) {
109 set_p2p_enabled_pref_result_ = set_p2p_enabled_pref_result;
110 }
111
David Zeuthen3ff6e6e2013-08-06 12:08:57 -0700112 void SetLookupUrlForFileResult(const std::string& url) {
113 lookup_url_for_file_result_ = url;
114 }
115
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700116 private:
David Zeuthen3ff6e6e2013-08-06 12:08:57 -0700117 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 Arnoldccd09572014-10-27 13:37:50 -0700122 bool set_p2p_enabled_pref_result_;
David Zeuthen3ff6e6e2013-08-06 12:08:57 -0700123 std::string lookup_url_for_file_result_;
124
125 DISALLOW_COPY_AND_ASSIGN(FakeP2PManager);
126};
127
128} // namespace chromeos_update_engine
129
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700130#endif // UPDATE_ENGINE_FAKE_P2P_MANAGER_H_