Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chromeos / dbus / fake_nfc_record_client.h
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_RECORD_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_NFC_RECORD_CLIENT_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/observer_list.h"
10 #include "base/values.h"
11 #include "chromeos/chromeos_export.h"
12 #include "chromeos/dbus/nfc_record_client.h"
13 #include "dbus/object_path.h"
14
15 namespace chromeos {
16
17 // FakeNfcRecordClient simulates the behavior of the NFC record objects and is
18 // used both in test cases in place of a mock and on the Linux desktop.
19 class CHROMEOS_EXPORT FakeNfcRecordClient : public NfcRecordClient {
20  public:
21   // Paths of the records exposed.
22   static const char kDeviceSmartPosterRecordPath[];
23   static const char kDeviceTextRecordPath[];
24   static const char kDeviceUriRecordPath[];
25   static const char kTagRecordPath[];
26
27   // Properties structure that provides fake behavior for D-Bus calls.
28   struct Properties : public NfcRecordClient::Properties {
29     explicit Properties(const PropertyChangedCallback& callback);
30     virtual ~Properties();
31
32     // dbus::PropertySet overrides.
33     virtual void Get(dbus::PropertyBase* property,
34                      dbus::PropertySet::GetCallback callback) override;
35     virtual void GetAll() override;
36     virtual void Set(dbus::PropertyBase* property,
37                      dbus::PropertySet::SetCallback callback) override;
38   };
39
40   FakeNfcRecordClient();
41   virtual ~FakeNfcRecordClient();
42
43   // NfcTagClient overrides.
44   virtual void Init(dbus::Bus* bus) override;
45   virtual void AddObserver(Observer* observer) override;
46   virtual void RemoveObserver(Observer* observer) override;
47   virtual std::vector<dbus::ObjectPath> GetRecordsForDevice(
48       const dbus::ObjectPath& device_path) override;
49   virtual std::vector<dbus::ObjectPath> GetRecordsForTag(
50       const dbus::ObjectPath& tag_path) override;
51   virtual Properties* GetProperties(
52       const dbus::ObjectPath& object_path) override;
53
54   // Adds or removes the fake record objects and notifies the observers.
55   void SetDeviceRecordsVisible(bool visible);
56   void SetTagRecordsVisible(bool visible);
57
58   // Modifies the contents of the tag record. |attributes| should be the
59   // same as the argument to NfcTagClient::Write. Each field will be directly
60   // assigned to the underlying record based on the type property, with
61   // no validity checking. Invalid tag content can be passed here to test
62   // the case where the remote application returns an incorrectly formatted
63   // record.
64   bool WriteTagRecord(const base::DictionaryValue& attributes);
65
66  private:
67   // Property changed callback passed when we create Properties* structures.
68   void OnPropertyChanged(const dbus::ObjectPath& object_path,
69                          const std::string& property_name);
70
71   // Called by Properties* structures when GetAll is called.
72   void OnPropertiesReceived(const dbus::ObjectPath& object_path);
73
74   // If true, the records are currently visible.
75   bool device_records_visible_;
76   bool tag_records_visible_;
77
78   // List of observers interested in event notifications from us.
79   ObserverList<Observer> observers_;
80
81   // Fake properties that are returned for the fake records.
82   scoped_ptr<Properties> device_smart_poster_record_properties_;
83   scoped_ptr<Properties> device_text_record_properties_;
84   scoped_ptr<Properties> device_uri_record_properties_;
85   scoped_ptr<Properties> tag_record_properties_;
86
87   DISALLOW_COPY_AND_ASSIGN(FakeNfcRecordClient);
88 };
89
90 }  // namespace chromeos
91
92 #endif  // CHROMEOS_DBUS_FAKE_NFC_RECORD_CLIENT_H_