Don't preload rarely seen large images
[chromium-blink-merge.git] / chromeos / dbus / fake_nfc_manager_client.cc
blob3c8564a2ef626c16f8a02b445f0854c3dcf1ec3b
1 // Copyright (c) 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 #include "chromeos/dbus/fake_nfc_manager_client.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "dbus/object_path.h"
10 #include "third_party/cros_system_api/dbus/service_constants.h"
12 namespace chromeos {
14 const char FakeNfcManagerClient::kDefaultAdapterPath[] = "/fake/nfc0";
16 FakeNfcManagerClient::Properties::Properties(
17 const PropertyChangedCallback& callback)
18 : NfcManagerClient::Properties(NULL, callback) {
21 FakeNfcManagerClient::Properties::~Properties() {
24 void FakeNfcManagerClient::Properties::Get(
25 dbus::PropertyBase* property,
26 dbus::PropertySet::GetCallback callback) {
27 VLOG(1) << "Get " << property->name();
28 callback.Run(false);
31 void FakeNfcManagerClient::Properties::GetAll() {
32 VLOG(1) << "GetAll";
35 void FakeNfcManagerClient::Properties::Set(
36 dbus::PropertyBase* property,
37 dbus::PropertySet::SetCallback callback) {
38 VLOG(1) << "Set " << property->name();
39 callback.Run(false);
42 FakeNfcManagerClient::FakeNfcManagerClient() {
43 properties_.reset(new Properties(base::Bind(
44 &FakeNfcManagerClient::OnPropertyChanged, base::Unretained(this))));
45 AddAdapter(kDefaultAdapterPath);
48 FakeNfcManagerClient::~FakeNfcManagerClient() {
51 void FakeNfcManagerClient::Init(dbus::Bus* bus) {
54 void FakeNfcManagerClient::AddObserver(Observer* observer) {
55 observers_.AddObserver(observer);
58 void FakeNfcManagerClient::RemoveObserver(Observer* observer) {
59 observers_.RemoveObserver(observer);
62 FakeNfcManagerClient::Properties* FakeNfcManagerClient::GetProperties() {
63 return properties_.get();
66 void FakeNfcManagerClient::AddAdapter(const std::string& adapter_path) {
67 VLOG(1) << "Adding NFC adapter: " << adapter_path;
68 dbus::ObjectPath new_adapter(adapter_path);
69 std::pair<std::set<dbus::ObjectPath>::iterator, bool> result =
70 adapters_.insert(new_adapter);
71 if (!result.second) {
72 VLOG(1) << "Adapter \"" << adapter_path << "\" already exists.";
73 return;
75 // Create a vector containing all object paths in the set |adapters_|. This
76 // will copy all members of |adapters_| to |adapters|.
77 std::vector<dbus::ObjectPath> adapters(adapters_.begin(), adapters_.end());
78 properties_->adapters.ReplaceValue(adapters);
79 FOR_EACH_OBSERVER(Observer, observers_, AdapterAdded(new_adapter));
82 void FakeNfcManagerClient::RemoveAdapter(const std::string& adapter_path) {
83 VLOG(1) << "Removing NFC adapter: " << adapter_path;
84 dbus::ObjectPath to_remove(adapter_path);
85 if (adapters_.erase(to_remove) == 0) {
86 VLOG(1) << "No such adapter: \"" << adapter_path << "\"";
87 return;
89 std::vector<dbus::ObjectPath> adapters(adapters_.begin(), adapters_.end());
90 properties_->adapters.ReplaceValue(adapters);
91 FOR_EACH_OBSERVER(Observer, observers_, AdapterRemoved(to_remove));
94 void FakeNfcManagerClient::OnPropertyChanged(
95 const std::string& property_name) {
96 FOR_EACH_OBSERVER(Observer, observers_,
97 ManagerPropertyChanged(property_name));
100 } // namespace chromeos