blob: a00b91f09d4d1c890448f0a5432b96743a8a583f [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),
22 count_shared_files_result_(0) {}
23
24 virtual ~FakeP2PManager() {}
25
26 // P2PManager overrides.
David Zeuthen92d9c8b2013-09-11 10:58:11 -070027 virtual void SetDevicePolicy(const policy::DevicePolicy* device_policy) {}
28
David Zeuthen3ff6e6e2013-08-06 12:08:57 -070029 virtual bool IsP2PEnabled() {
30 return is_p2p_enabled_;
31 }
32
33 virtual bool EnsureP2PRunning() {
34 return ensure_p2p_running_result_;
35 }
36
37 virtual bool EnsureP2PNotRunning() {
38 return ensure_p2p_not_running_result_;
39 }
40
41 virtual bool PerformHousekeeping() {
42 return perform_housekeeping_result_;
43 }
44
45 virtual void LookupUrlForFile(const std::string& file_id,
46 size_t minimum_size,
47 base::TimeDelta max_time_to_wait,
48 LookupCallback callback) {
49 callback.Run(lookup_url_for_file_result_);
50 }
51
52 virtual bool FileShare(const std::string& file_id,
53 size_t expected_size) {
54 return false;
55 }
56
57 virtual base::FilePath FileGetPath(const std::string& file_id) {
58 return base::FilePath();
59 }
60
61 virtual ssize_t FileGetSize(const std::string& file_id) {
62 return -1;
63 }
64
65 virtual ssize_t FileGetExpectedSize(const std::string& file_id) {
66 return -1;
67 }
68
69 virtual bool FileGetVisible(const std::string& file_id,
70 bool *out_result) {
71 return false;
72 }
73
74 virtual bool FileMakeVisible(const std::string& file_id) {
75 return false;
76 }
77
78 virtual int CountSharedFiles() {
79 return count_shared_files_result_;
80 }
81
82 // Methods for controlling what the fake returns and how it acts.
83 void SetP2PEnabled(bool is_p2p_enabled) {
84 is_p2p_enabled_ = is_p2p_enabled;
85 }
86
87 void SetEnsureP2PRunningResult(bool ensure_p2p_running_result) {
88 ensure_p2p_running_result_ = ensure_p2p_running_result;
89 }
90
91 void SetEnsureP2PNotRunningResult(bool ensure_p2p_not_running_result) {
92 ensure_p2p_not_running_result_ = ensure_p2p_not_running_result;
93 }
94
95 void SetPerformHousekeepingResult(bool perform_housekeeping_result) {
96 perform_housekeeping_result_ = perform_housekeeping_result;
97 }
98
99 void SetCountSharedFilesResult(int count_shared_files_result) {
100 count_shared_files_result_ = count_shared_files_result;
101 }
102
103 void SetLookupUrlForFileResult(const std::string& url) {
104 lookup_url_for_file_result_ = url;
105 }
106
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700107 private:
David Zeuthen3ff6e6e2013-08-06 12:08:57 -0700108 bool is_p2p_enabled_;
109 bool ensure_p2p_running_result_;
110 bool ensure_p2p_not_running_result_;
111 bool perform_housekeeping_result_;
112 int count_shared_files_result_;
113 std::string lookup_url_for_file_result_;
114
115 DISALLOW_COPY_AND_ASSIGN(FakeP2PManager);
116};
117
118} // namespace chromeos_update_engine
119
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700120#endif // UPDATE_ENGINE_FAKE_P2P_MANAGER_H_