Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chromeos / dbus / fake_nfc_adapter_client.h
blob21e76bd375b68ecd2566168576c7a624e712fcdc
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.
5 #ifndef CHROMEOS_DBUS_FAKE_NFC_ADAPTER_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_NFC_ADAPTER_CLIENT_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/nfc_adapter_client.h"
14 #include "chromeos/dbus/nfc_client_helpers.h"
16 namespace chromeos {
18 // FakeNfcAdapterClient simulates the behavior of the NFC adapter objects
19 // and is used both in test cases in place of a mock and on the Linux desktop.
20 class CHROMEOS_EXPORT FakeNfcAdapterClient : public NfcAdapterClient {
21 public:
22 // The object paths for the adapters that are being emulated.
23 static const char kAdapterPath0[];
24 static const char kAdapterPath1[];
26 // Properties structure that provides fake behavior for D-Bus calls.
27 struct Properties : public NfcAdapterClient::Properties {
28 explicit Properties(const PropertyChangedCallback& callback);
29 ~Properties() override;
31 // dbus::PropertySet overrides.
32 void Get(dbus::PropertyBase* property,
33 dbus::PropertySet::GetCallback callback) override;
34 void GetAll() override;
35 void Set(dbus::PropertyBase* property,
36 dbus::PropertySet::SetCallback callback) override;
39 FakeNfcAdapterClient();
40 ~FakeNfcAdapterClient() override;
42 // NfcAdapterClient overrides.
43 void Init(dbus::Bus* bus) override;
44 void AddObserver(Observer* observer) override;
45 void RemoveObserver(Observer* observer) override;
46 std::vector<dbus::ObjectPath> GetAdapters() override;
47 Properties* GetProperties(const dbus::ObjectPath& object_path) override;
48 void StartPollLoop(
49 const dbus::ObjectPath& object_path,
50 const std::string& mode,
51 const base::Closure& callback,
52 const nfc_client_helpers::ErrorCallback& error_callback) override;
53 void StopPollLoop(
54 const dbus::ObjectPath& object_path,
55 const base::Closure& callback,
56 const nfc_client_helpers::ErrorCallback& error_callback) override;
58 // Sets the adapter as |present|. Used for testing.
59 void SetAdapterPresent(bool present);
60 void SetSecondAdapterPresent(bool present);
62 // Tells the FakeNfcAdapterClient to add the device or tag with the given path
63 // to its corresponding list for |kAdapterPath0|, if it is not already in
64 // the list and promptly triggers a property changed signal. This method will
65 // also fail, if the polling property of the adapter is false and will set it
66 // to false on success.
67 void SetDevice(const dbus::ObjectPath& device_path);
68 void SetTag(const dbus::ObjectPath& tag_path);
70 // Tells the FakeNfcAdapterClient to remove the device or tag with the given
71 // path from its corresponding list exposed for |kAdapterPath0|, if it
72 // is in the list. On success, this method will mark the polling property of
73 // the adapter to true.
74 void UnsetDevice(const dbus::ObjectPath& device_path);
75 void UnsetTag(const dbus::ObjectPath& tag_path);
77 // Sets a flag that determines whether FakeNfcAdapterClient should notify
78 // FakeNfcDeviceClient or FakeNfcTagClient to start a pairing simulation as a
79 // result of a call to StartPollLoop(). This is enabled by default. If
80 // enabled, the first call to StartPollLoop, will initiate a tag pairing
81 // simulation. The simulation will alternate between device and tag pairing on
82 // each successive call to StartPollLoop. This behavior, which is meant for
83 // feature development based on fake classes, can be disabled to allow manual
84 // control for unit tests.
85 void EnablePairingOnPoll(bool enabled);
87 private:
88 // Property changed callback passed when we create Properties* structures.
89 void OnPropertyChanged(const dbus::ObjectPath& object_path,
90 const std::string& property_name);
92 // List of observers interested in event notifications from us.
93 base::ObserverList<Observer> observers_;
95 // Fake properties that are returned for the emulated adapters.
96 scoped_ptr<Properties> properties_;
97 scoped_ptr<Properties> second_properties_;
99 // Whether the adapter and second adapter are present or not.
100 bool present_;
101 bool second_present_;
103 // If true, a pairing simulation is initiated on a successful call to
104 // StartPollLoop().
105 bool start_pairing_on_poll_;
107 // If true, device pairing will be simulated on the next call to
108 // StartPollLoop. Otherwise, tag pairing will be simulated.
109 bool device_pairing_;
111 DISALLOW_COPY_AND_ASSIGN(FakeNfcAdapterClient);
114 } // namespace chromeos
116 #endif // CHROMEOS_DBUS_FAKE_NFC_ADAPTER_CLIENT_H_