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

Side by Side Diff: dbus/exported_object.cc

Issue 510863002: dbus::ObjectManager: Add a match rule for properties before GetManagedObjects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased; updated BUILD.gn; fixed crash from latest RunLoop changes Created 6 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 | « dbus/dbus.gyp ('k') | dbus/object_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "dbus/exported_object.h" 5 #include "dbus/exported_object.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "dbus/bus.h" 14 #include "dbus/bus.h"
15 #include "dbus/message.h" 15 #include "dbus/message.h"
16 #include "dbus/object_path.h" 16 #include "dbus/object_path.h"
17 #include "dbus/scoped_dbus_error.h" 17 #include "dbus/scoped_dbus_error.h"
18 #include "dbus/util.h"
18 19
19 namespace dbus { 20 namespace dbus {
20 21
21 namespace { 22 namespace {
22 23
23 // Used for success ratio histograms. 1 for success, 0 for failure. 24 // Used for success ratio histograms. 1 for success, 0 for failure.
24 const int kSuccessRatioHistogramMaxValue = 2; 25 const int kSuccessRatioHistogramMaxValue = 2;
25 26
26 // Gets the absolute method name by concatenating the interface name and
27 // the method name. Used for building keys for method_table_ in
28 // ExportedObject.
29 std::string GetAbsoluteMethodName(
30 const std::string& interface_name,
31 const std::string& method_name) {
32 return interface_name + "." + method_name;
33 }
34
35 } // namespace 27 } // namespace
36 28
37 ExportedObject::ExportedObject(Bus* bus, 29 ExportedObject::ExportedObject(Bus* bus,
38 const ObjectPath& object_path) 30 const ObjectPath& object_path)
39 : bus_(bus), 31 : bus_(bus),
40 object_path_(object_path), 32 object_path_(object_path),
41 object_is_registered_(false) { 33 object_is_registered_(false) {
42 } 34 }
43 35
44 ExportedObject::~ExportedObject() { 36 ExportedObject::~ExportedObject() {
45 DCHECK(!object_is_registered_); 37 DCHECK(!object_is_registered_);
46 } 38 }
47 39
48 bool ExportedObject::ExportMethodAndBlock( 40 bool ExportedObject::ExportMethodAndBlock(
49 const std::string& interface_name, 41 const std::string& interface_name,
50 const std::string& method_name, 42 const std::string& method_name,
51 MethodCallCallback method_call_callback) { 43 MethodCallCallback method_call_callback) {
52 bus_->AssertOnDBusThread(); 44 bus_->AssertOnDBusThread();
53 45
54 // Check if the method is already exported. 46 // Check if the method is already exported.
55 const std::string absolute_method_name = 47 const std::string absolute_method_name =
56 GetAbsoluteMethodName(interface_name, method_name); 48 GetAbsoluteMemberName(interface_name, method_name);
57 if (method_table_.find(absolute_method_name) != method_table_.end()) { 49 if (method_table_.find(absolute_method_name) != method_table_.end()) {
58 LOG(ERROR) << absolute_method_name << " is already exported"; 50 LOG(ERROR) << absolute_method_name << " is already exported";
59 return false; 51 return false;
60 } 52 }
61 53
62 if (!bus_->Connect()) 54 if (!bus_->Connect())
63 return false; 55 return false;
64 if (!bus_->SetUpAsyncOperations()) 56 if (!bus_->SetUpAsyncOperations())
65 return false; 57 return false;
66 if (!Register()) 58 if (!Register())
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 const std::string interface = method_call->GetInterface(); 188 const std::string interface = method_call->GetInterface();
197 const std::string member = method_call->GetMember(); 189 const std::string member = method_call->GetMember();
198 190
199 if (interface.empty()) { 191 if (interface.empty()) {
200 // We don't support method calls without interface. 192 // We don't support method calls without interface.
201 LOG(WARNING) << "Interface is missing: " << method_call->ToString(); 193 LOG(WARNING) << "Interface is missing: " << method_call->ToString();
202 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 194 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
203 } 195 }
204 196
205 // Check if we know about the method. 197 // Check if we know about the method.
206 const std::string absolute_method_name = GetAbsoluteMethodName( 198 const std::string absolute_method_name = GetAbsoluteMemberName(
207 interface, member); 199 interface, member);
208 MethodTable::const_iterator iter = method_table_.find(absolute_method_name); 200 MethodTable::const_iterator iter = method_table_.find(absolute_method_name);
209 if (iter == method_table_.end()) { 201 if (iter == method_table_.end()) {
210 // Don't know about the method. 202 // Don't know about the method.
211 LOG(WARNING) << "Unknown method: " << method_call->ToString(); 203 LOG(WARNING) << "Unknown method: " << method_call->ToString();
212 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 204 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
213 } 205 }
214 206
215 const base::TimeTicks start_time = base::TimeTicks::Now(); 207 const base::TimeTicks start_time = base::TimeTicks::Now();
216 if (bus_->HasDBusThread()) { 208 if (bus_->HasDBusThread()) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 return self->HandleMessage(connection, raw_message); 302 return self->HandleMessage(connection, raw_message);
311 } 303 }
312 304
313 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection, 305 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection,
314 void* user_data) { 306 void* user_data) {
315 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data); 307 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data);
316 return self->OnUnregistered(connection); 308 return self->OnUnregistered(connection);
317 } 309 }
318 310
319 } // namespace dbus 311 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/dbus.gyp ('k') | dbus/object_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698