Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: chromeos/dbus/fake_nfc_adapter_client.h

Issue 2292703002: chromeos: Remove unused NFC D-Bus client library (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/dbus/dbus_thread_manager.cc ('k') | chromeos/dbus/fake_nfc_adapter_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium 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
5 #ifndef CHROMEOS_DBUS_FAKE_NFC_ADAPTER_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_NFC_ADAPTER_CLIENT_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/macros.h"
12 #include "base/observer_list.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/nfc_adapter_client.h"
15 #include "chromeos/dbus/nfc_client_helpers.h"
16
17 namespace chromeos {
18
19 // FakeNfcAdapterClient simulates the behavior of the NFC adapter objects
20 // and is used both in test cases in place of a mock and on the Linux desktop.
21 class CHROMEOS_EXPORT FakeNfcAdapterClient : public NfcAdapterClient {
22 public:
23 // The object paths for the adapters that are being emulated.
24 static const char kAdapterPath0[];
25 static const char kAdapterPath1[];
26
27 // Properties structure that provides fake behavior for D-Bus calls.
28 struct Properties : public NfcAdapterClient::Properties {
29 explicit Properties(const PropertyChangedCallback& callback);
30 ~Properties() override;
31
32 // dbus::PropertySet overrides.
33 void Get(dbus::PropertyBase* property,
34 dbus::PropertySet::GetCallback callback) override;
35 void GetAll() override;
36 void Set(dbus::PropertyBase* property,
37 dbus::PropertySet::SetCallback callback) override;
38 };
39
40 FakeNfcAdapterClient();
41 ~FakeNfcAdapterClient() override;
42
43 // NfcAdapterClient overrides.
44 void Init(dbus::Bus* bus) override;
45 void AddObserver(Observer* observer) override;
46 void RemoveObserver(Observer* observer) override;
47 std::vector<dbus::ObjectPath> GetAdapters() override;
48 Properties* GetProperties(const dbus::ObjectPath& object_path) override;
49 void StartPollLoop(
50 const dbus::ObjectPath& object_path,
51 const std::string& mode,
52 const base::Closure& callback,
53 const nfc_client_helpers::ErrorCallback& error_callback) override;
54 void StopPollLoop(
55 const dbus::ObjectPath& object_path,
56 const base::Closure& callback,
57 const nfc_client_helpers::ErrorCallback& error_callback) override;
58
59 // Sets the adapter as |present|. Used for testing.
60 void SetAdapterPresent(bool present);
61 void SetSecondAdapterPresent(bool present);
62
63 // Tells the FakeNfcAdapterClient to add the device or tag with the given path
64 // to its corresponding list for |kAdapterPath0|, if it is not already in
65 // the list and promptly triggers a property changed signal. This method will
66 // also fail, if the polling property of the adapter is false and will set it
67 // to false on success.
68 void SetDevice(const dbus::ObjectPath& device_path);
69 void SetTag(const dbus::ObjectPath& tag_path);
70
71 // Tells the FakeNfcAdapterClient to remove the device or tag with the given
72 // path from its corresponding list exposed for |kAdapterPath0|, if it
73 // is in the list. On success, this method will mark the polling property of
74 // the adapter to true.
75 void UnsetDevice(const dbus::ObjectPath& device_path);
76 void UnsetTag(const dbus::ObjectPath& tag_path);
77
78 // Sets a flag that determines whether FakeNfcAdapterClient should notify
79 // FakeNfcDeviceClient or FakeNfcTagClient to start a pairing simulation as a
80 // result of a call to StartPollLoop(). This is enabled by default. If
81 // enabled, the first call to StartPollLoop, will initiate a tag pairing
82 // simulation. The simulation will alternate between device and tag pairing on
83 // each successive call to StartPollLoop. This behavior, which is meant for
84 // feature development based on fake classes, can be disabled to allow manual
85 // control for unit tests.
86 void EnablePairingOnPoll(bool enabled);
87
88 private:
89 // Property changed callback passed when we create Properties* structures.
90 void OnPropertyChanged(const dbus::ObjectPath& object_path,
91 const std::string& property_name);
92
93 // List of observers interested in event notifications from us.
94 base::ObserverList<Observer> observers_;
95
96 // Fake properties that are returned for the emulated adapters.
97 std::unique_ptr<Properties> properties_;
98 std::unique_ptr<Properties> second_properties_;
99
100 // Whether the adapter and second adapter are present or not.
101 bool present_;
102 bool second_present_;
103
104 // If true, a pairing simulation is initiated on a successful call to
105 // StartPollLoop().
106 bool start_pairing_on_poll_;
107
108 // If true, device pairing will be simulated on the next call to
109 // StartPollLoop. Otherwise, tag pairing will be simulated.
110 bool device_pairing_;
111
112 DISALLOW_COPY_AND_ASSIGN(FakeNfcAdapterClient);
113 };
114
115 } // namespace chromeos
116
117 #endif // CHROMEOS_DBUS_FAKE_NFC_ADAPTER_CLIENT_H_
OLDNEW
« no previous file with comments | « chromeos/dbus/dbus_thread_manager.cc ('k') | chromeos/dbus/fake_nfc_adapter_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698