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

Side by Side Diff: chrome/browser/chromeos/dbus/introspectable_client.cc

Issue 9838085: Move files inside chrome/browser/chromeos/dbus to chromeos/dbus (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: _ Created 8 years, 9 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #include "chrome/browser/chromeos/dbus/introspectable_client.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/bind.h"
11 #include "base/logging.h"
12 #include "base/chromeos/chromeos_version.h"
13 #include "dbus/bus.h"
14 #include "dbus/message.h"
15 #include "dbus/object_path.h"
16 #include "dbus/object_proxy.h"
17
18 namespace {
19
20 // D-Bus specification constants.
21 const char kIntrospectableInterface[] = "org.freedesktop.DBus.Introspectable";
22 const char kIntrospect[] = "Introspect";
23
24 } // namespace
25
26 namespace chromeos {
27
28 // The IntrospectableClient implementation used in production.
29 class IntrospectableClientImpl : public IntrospectableClient {
30 public:
31 explicit IntrospectableClientImpl(dbus::Bus* bus)
32 : weak_ptr_factory_(this),
33 bus_(bus) {
34 DVLOG(1) << "Creating IntrospectableClientImpl";
35 }
36
37 virtual ~IntrospectableClientImpl() {
38 }
39
40 // IntrospectableClient override.
41 virtual void Introspect(const std::string& service_name,
42 const dbus::ObjectPath& object_path,
43 const IntrospectCallback& callback) OVERRIDE {
44 dbus::MethodCall method_call(kIntrospectableInterface, kIntrospect);
45
46 dbus::ObjectProxy* object_proxy = bus_->GetObjectProxy(service_name,
47 object_path);
48
49 object_proxy->CallMethod(
50 &method_call,
51 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
52 base::Bind(&IntrospectableClientImpl::OnIntrospect,
53 weak_ptr_factory_.GetWeakPtr(),
54 service_name, object_path, callback));
55 }
56
57 private:
58 // Called by dbus:: when a response for Introspect() is recieved.
59 void OnIntrospect(const std::string& service_name,
60 const dbus::ObjectPath& object_path,
61 const IntrospectCallback& callback,
62 dbus::Response* response) {
63 // Parse response.
64 bool success = false;
65 std::string xml_data;
66 if (response != NULL) {
67 dbus::MessageReader reader(response);
68 if (!reader.PopString(&xml_data)) {
69 LOG(WARNING) << "Introspect response has incorrect paramters: "
70 << response->ToString();
71 } else {
72 success = true;
73 }
74 }
75
76 // Notify client.
77 callback.Run(service_name, object_path, xml_data, success);
78 }
79
80 // Weak pointer factory for generating 'this' pointers that might live longer
81 // than we do.
82 base::WeakPtrFactory<IntrospectableClientImpl> weak_ptr_factory_;
83
84 dbus::Bus* bus_;
85
86 DISALLOW_COPY_AND_ASSIGN(IntrospectableClientImpl);
87 };
88
89 // The IntrospectableClient implementation used on Linux desktop, which does
90 // nothing.
91 class IntrospectableClientStubImpl : public IntrospectableClient {
92 public:
93 // IntrospectableClient override.
94 virtual void Introspect(const std::string& service_name,
95 const dbus::ObjectPath& object_path,
96 const IntrospectCallback& callback) OVERRIDE {
97 VLOG(1) << "Introspect: " << service_name << " " << object_path.value();
98 callback.Run(service_name, object_path, "", false);
99 }
100 };
101
102 IntrospectableClient::IntrospectableClient() {
103 }
104
105 IntrospectableClient::~IntrospectableClient() {
106 }
107
108 // static
109 IntrospectableClient* IntrospectableClient::Create(dbus::Bus* bus) {
110 if (base::chromeos::IsRunningOnChromeOS()) {
111 return new IntrospectableClientImpl(bus);
112 } else {
113 return new IntrospectableClientStubImpl();
114 }
115 }
116
117 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698