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

Side by Side Diff: dbus/object_manager.cc

Issue 2239123002: dbus: Make Bus::GetManagedObjects skip unavailable services. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove Bus::GetManagedObjects and BluezDBusManager's call to it Created 4 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/object_manager.h ('k') | device/bluetooth/dbus/bluez_dbus_manager.cc » ('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) 2013 The Chromium Authors. All rights reserved. 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 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/object_manager.h" 5 #include "dbus/object_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 31
32 ObjectManager::ObjectManager(Bus* bus, 32 ObjectManager::ObjectManager(Bus* bus,
33 const std::string& service_name, 33 const std::string& service_name,
34 const ObjectPath& object_path) 34 const ObjectPath& object_path)
35 : bus_(bus), 35 : bus_(bus),
36 service_name_(service_name), 36 service_name_(service_name),
37 object_path_(object_path), 37 object_path_(object_path),
38 setup_success_(false), 38 setup_success_(false),
39 cleanup_called_(false), 39 cleanup_called_(false),
40 service_initially_available_(false),
41 signals_are_connected_(false),
40 weak_ptr_factory_(this) { 42 weak_ptr_factory_(this) {
41 DVLOG(1) << "Creating ObjectManager for " << service_name_ 43 DVLOG(1) << "Creating ObjectManager for " << service_name_
42 << " " << object_path_.value(); 44 << " " << object_path_.value();
43 DCHECK(bus_); 45 DCHECK(bus_);
44 bus_->AssertOnOriginThread(); 46 bus_->AssertOnOriginThread();
45 object_proxy_ = bus_->GetObjectProxy(service_name_, object_path_); 47 object_proxy_ = bus_->GetObjectProxy(service_name_, object_path_);
48 object_proxy_->WaitForServiceToBeAvailable(
49 base::Bind(&ObjectManager::OnServiceInitiallyAvailable,
50 weak_ptr_factory_.GetWeakPtr()));
46 object_proxy_->SetNameOwnerChangedCallback( 51 object_proxy_->SetNameOwnerChangedCallback(
47 base::Bind(&ObjectManager::NameOwnerChanged, 52 base::Bind(&ObjectManager::NameOwnerChanged,
48 weak_ptr_factory_.GetWeakPtr())); 53 weak_ptr_factory_.GetWeakPtr()));
49 54
50 // Set up a match rule and a filter function to handle PropertiesChanged 55 // Set up a match rule and a filter function to handle PropertiesChanged
51 // signals from the service. This is important to avoid any race conditions 56 // signals from the service. This is important to avoid any race conditions
52 // that might cause us to miss PropertiesChanged signals once all objects are 57 // that might cause us to miss PropertiesChanged signals once all objects are
53 // initialized via GetManagedObjects. 58 // initialized via GetManagedObjects.
54 base::PostTaskAndReplyWithResult( 59 base::PostTaskAndReplyWithResult(
55 bus_->GetDBusTaskRunner(), 60 bus_->GetDBusTaskRunner(),
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 bus_->RemoveFilterFunction(&ObjectManager::HandleMessageThunk, this); 165 bus_->RemoveFilterFunction(&ObjectManager::HandleMessageThunk, this);
161 166
162 ScopedDBusError error; 167 ScopedDBusError error;
163 bus_->RemoveMatch(match_rule_, error.get()); 168 bus_->RemoveMatch(match_rule_, error.get());
164 if (error.is_set()) 169 if (error.is_set())
165 LOG(ERROR) << "Failed to remove match rule: " << match_rule_; 170 LOG(ERROR) << "Failed to remove match rule: " << match_rule_;
166 171
167 match_rule_.clear(); 172 match_rule_.clear();
168 } 173 }
169 174
175 void ObjectManager::OnServiceInitiallyAvailable(bool service_is_available) {
176 if (!service_is_available) {
177 LOG(WARNING) << service_name_ << " " << object_path_.value()
178 << ": Failed to wait for service to become available";
179 return;
180 }
181
182 service_initially_available_ = true;
183 if (signals_are_connected_)
184 GetManagedObjects();
185 }
186
170 void ObjectManager::InitializeObjects() { 187 void ObjectManager::InitializeObjects() {
171 DCHECK(bus_); 188 DCHECK(bus_);
172 DCHECK(object_proxy_); 189 DCHECK(object_proxy_);
173 DCHECK(setup_success_); 190 DCHECK(setup_success_);
174 191
175 // |object_proxy_| is no longer valid if the Bus was shut down before this 192 // |object_proxy_| is no longer valid if the Bus was shut down before this
176 // call. Don't initiate any other action from the origin thread. 193 // call. Don't initiate any other action from the origin thread.
177 if (cleanup_called_) 194 if (cleanup_called_)
178 return; 195 return;
179 196
180 object_proxy_->ConnectToSignal( 197 object_proxy_->ConnectToSignal(
181 kObjectManagerInterface, 198 kObjectManagerInterface,
182 kObjectManagerInterfacesAdded, 199 kObjectManagerInterfacesAdded,
183 base::Bind(&ObjectManager::InterfacesAddedReceived, 200 base::Bind(&ObjectManager::InterfacesAddedReceived,
184 weak_ptr_factory_.GetWeakPtr()), 201 weak_ptr_factory_.GetWeakPtr()),
185 base::Bind(&ObjectManager::InterfacesAddedConnected, 202 base::Bind(&ObjectManager::InterfacesAddedConnected,
186 weak_ptr_factory_.GetWeakPtr())); 203 weak_ptr_factory_.GetWeakPtr()));
187 204
188 object_proxy_->ConnectToSignal( 205 object_proxy_->ConnectToSignal(
189 kObjectManagerInterface, 206 kObjectManagerInterface,
190 kObjectManagerInterfacesRemoved, 207 kObjectManagerInterfacesRemoved,
191 base::Bind(&ObjectManager::InterfacesRemovedReceived, 208 base::Bind(&ObjectManager::InterfacesRemovedReceived,
192 weak_ptr_factory_.GetWeakPtr()), 209 weak_ptr_factory_.GetWeakPtr()),
193 base::Bind(&ObjectManager::InterfacesRemovedConnected, 210 base::Bind(&ObjectManager::InterfacesRemovedConnected,
194 weak_ptr_factory_.GetWeakPtr())); 211 weak_ptr_factory_.GetWeakPtr()));
195 212
196 GetManagedObjects(); 213 signals_are_connected_ = true;
214 if (service_initially_available_)
215 GetManagedObjects();
hashimoto 2016/09/01 03:26:07 How about calling WaitForServiceToBeAvailable() he
Daniel Erat 2016/09/01 04:15:55 thanks, that seems like a good suggestion! and no,
197 } 216 }
198 217
199 bool ObjectManager::SetupMatchRuleAndFilter() { 218 bool ObjectManager::SetupMatchRuleAndFilter() {
200 DCHECK(bus_); 219 DCHECK(bus_);
201 DCHECK(!setup_success_); 220 DCHECK(!setup_success_);
202 bus_->AssertOnDBusThread(); 221 bus_->AssertOnDBusThread();
203 222
204 if (cleanup_called_) 223 if (cleanup_called_)
205 return false; 224 return false;
206 225
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 RemoveInterface(object_path, *iiter); 545 RemoveInterface(object_path, *iiter);
527 } 546 }
528 547
529 } 548 }
530 549
531 if (!new_owner.empty()) 550 if (!new_owner.empty())
532 GetManagedObjects(); 551 GetManagedObjects();
533 } 552 }
534 553
535 } // namespace dbus 554 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/object_manager.h ('k') | device/bluetooth/dbus/bluez_dbus_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698