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

Side by Side Diff: dbus/test_service.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: Addressed comments by satorux@; added unit test. 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
« dbus/bus.h ('K') | « dbus/test_service.h ('k') | no next file » | 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/test_service.h" 5 #include "dbus/test_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/test/test_timeouts.h" 8 #include "base/test/test_timeouts.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "dbus/bus.h" 10 #include "dbus/bus.h"
11 #include "dbus/exported_object.h" 11 #include "dbus/exported_object.h"
12 #include "dbus/message.h" 12 #include "dbus/message.h"
13 #include "dbus/object_manager.h" 13 #include "dbus/object_manager.h"
14 #include "dbus/object_path.h" 14 #include "dbus/object_path.h"
15 #include "dbus/property.h" 15 #include "dbus/property.h"
16 16
17 namespace { 17 namespace {
18 18
19 void EmptyCallback(bool /* success */) { 19 void EmptyCallback(bool /* success */) {
20 } 20 }
21 21
22 } // namespace 22 } // namespace
23 23
24 namespace dbus { 24 namespace dbus {
25 25
26 // Echo, SlowEcho, AsyncEcho, BrokenMethod, GetAll, Get, Set, PerformAction, 26 // Echo, SlowEcho, AsyncEcho, BrokenMethod, GetAll, Get, Set, PerformAction,
27 // GetManagedObjects. 27 // GetManagedObjects
28 const int TestService::kNumMethodsToExport = 9; 28 const int TestService::kNumMethodsToExport = 9;
29 29
30 TestService::Options::Options() 30 TestService::Options::Options()
31 : request_ownership_options(Bus::REQUIRE_PRIMARY) { 31 : request_ownership_options(Bus::REQUIRE_PRIMARY) {
32 } 32 }
33 33
34 TestService::Options::~Options() { 34 TestService::Options::~Options() {
35 } 35 }
36 36
37 TestService::TestService(const Options& options) 37 TestService::TestService(const Options& options)
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 void TestService::ReleaseOwnershipInternal( 153 void TestService::ReleaseOwnershipInternal(
154 base::Closure callback) { 154 base::Closure callback) {
155 bus_->ReleaseOwnership("org.chromium.TestService"); 155 bus_->ReleaseOwnership("org.chromium.TestService");
156 has_ownership_ = false; 156 has_ownership_ = false;
157 157
158 bus_->GetOriginTaskRunner()->PostTask( 158 bus_->GetOriginTaskRunner()->PostTask(
159 FROM_HERE, 159 FROM_HERE,
160 callback); 160 callback);
161 } 161 }
162 162
163 void TestService::SetSendImmediatePropertiesChanged() {
164 send_immediate_properties_changed_ = true;
165 }
166
163 void TestService::OnExported(const std::string& interface_name, 167 void TestService::OnExported(const std::string& interface_name,
164 const std::string& method_name, 168 const std::string& method_name,
165 bool success) { 169 bool success) {
166 if (!success) { 170 if (!success) {
167 LOG(ERROR) << "Failed to export: " << interface_name << "." 171 LOG(ERROR) << "Failed to export: " << interface_name << "."
168 << method_name; 172 << method_name;
169 // Returning here will make WaitUntilServiceIsStarted() to time out 173 // Returning here will make WaitUntilServiceIsStarted() to time out
170 // and return false. 174 // and return false.
171 return; 175 return;
172 } 176 }
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 else if (action == "ReleaseOwnership") { 482 else if (action == "ReleaseOwnership") {
479 ReleaseOwnership(base::Bind(&TestService::PerformActionResponse, 483 ReleaseOwnership(base::Bind(&TestService::PerformActionResponse,
480 base::Unretained(this), 484 base::Unretained(this),
481 method_call, response_sender)); 485 method_call, response_sender));
482 return; 486 return;
483 } else if (action == "Ownership") { 487 } else if (action == "Ownership") {
484 ReleaseOwnership(base::Bind(&TestService::OwnershipReleased, 488 ReleaseOwnership(base::Bind(&TestService::OwnershipReleased,
485 base::Unretained(this), 489 base::Unretained(this),
486 method_call, response_sender)); 490 method_call, response_sender));
487 return; 491 return;
488 } 492 } else if (action == "SetSendImmediatePropertiesChanged")
493 SetSendImmediatePropertiesChanged();
satorux1 2014/08/29 05:20:53 please add {} and while you are at it, please add
armansito 2014/08/29 16:17:08 Done.
489 494
490 scoped_ptr<Response> response = Response::FromMethodCall(method_call); 495 scoped_ptr<Response> response = Response::FromMethodCall(method_call);
491 response_sender.Run(response.Pass()); 496 response_sender.Run(response.Pass());
492 } 497 }
493 498
494 void TestService::PerformActionResponse( 499 void TestService::PerformActionResponse(
495 MethodCall* method_call, 500 MethodCall* method_call,
496 ExportedObject::ResponseSender response_sender) { 501 ExportedObject::ResponseSender response_sender) {
497 scoped_ptr<Response> response = Response::FromMethodCall(method_call); 502 scoped_ptr<Response> response = Response::FromMethodCall(method_call);
498 response_sender.Run(response.Pass()); 503 response_sender.Run(response.Pass());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 object_dict_entry_writer.AppendString("org.chromium.TestInterface"); 554 object_dict_entry_writer.AppendString("org.chromium.TestInterface");
550 AddPropertiesToWriter(&object_dict_entry_writer); 555 AddPropertiesToWriter(&object_dict_entry_writer);
551 object_array_writer.CloseContainer(&object_dict_entry_writer); 556 object_array_writer.CloseContainer(&object_dict_entry_writer);
552 557
553 dict_entry_writer.CloseContainer(&object_array_writer); 558 dict_entry_writer.CloseContainer(&object_array_writer);
554 559
555 array_writer.CloseContainer(&dict_entry_writer); 560 array_writer.CloseContainer(&dict_entry_writer);
556 writer.CloseContainer(&array_writer); 561 writer.CloseContainer(&array_writer);
557 562
558 response_sender.Run(response.Pass()); 563 response_sender.Run(response.Pass());
564
565 if (send_immediate_properties_changed_)
566 SendPropertyChangedSignal("ChangedTestServiceName");
559 } 567 }
560 568
561 void TestService::AddPropertiesToWriter(MessageWriter* writer) { 569 void TestService::AddPropertiesToWriter(MessageWriter* writer) {
562 // The properties response is a dictionary of strings identifying the 570 // The properties response is a dictionary of strings identifying the
563 // property and a variant containing the property value. We return all 571 // property and a variant containing the property value. We return all
564 // of the properties, thus the response is: 572 // of the properties, thus the response is:
565 // 573 //
566 // { 574 // {
567 // "Name": Variant<"TestService">, 575 // "Name": Variant<"TestService">,
568 // "Version": Variant<10>, 576 // "Version": Variant<10>,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 array_writer.OpenDictEntry(&dict_entry_writer); 694 array_writer.OpenDictEntry(&dict_entry_writer);
687 dict_entry_writer.AppendString("Name"); 695 dict_entry_writer.AppendString("Name");
688 dict_entry_writer.AppendVariantOfString(name); 696 dict_entry_writer.AppendVariantOfString(name);
689 array_writer.CloseContainer(&dict_entry_writer); 697 array_writer.CloseContainer(&dict_entry_writer);
690 writer.CloseContainer(&array_writer); 698 writer.CloseContainer(&array_writer);
691 699
692 exported_object_->SendSignal(&signal); 700 exported_object_->SendSignal(&signal);
693 } 701 }
694 702
695 } // namespace dbus 703 } // namespace dbus
OLDNEW
« dbus/bus.h ('K') | « dbus/test_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698