OLD | NEW |
---|---|
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 bus_->RemoveFilterFunction(&ObjectManager::HandleMessageThunk, this); | 160 bus_->RemoveFilterFunction(&ObjectManager::HandleMessageThunk, this); |
161 | 161 |
162 ScopedDBusError error; | 162 ScopedDBusError error; |
163 bus_->RemoveMatch(match_rule_, error.get()); | 163 bus_->RemoveMatch(match_rule_, error.get()); |
164 if (error.is_set()) | 164 if (error.is_set()) |
165 LOG(ERROR) << "Failed to remove match rule: " << match_rule_; | 165 LOG(ERROR) << "Failed to remove match rule: " << match_rule_; |
166 | 166 |
167 match_rule_.clear(); | 167 match_rule_.clear(); |
168 } | 168 } |
169 | 169 |
170 void ObjectManager::InitializeObjects() { | |
171 DCHECK(bus_); | |
172 DCHECK(object_proxy_); | |
173 DCHECK(setup_success_); | |
174 | |
175 // |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. | |
177 if (cleanup_called_) | |
178 return; | |
179 | |
180 object_proxy_->ConnectToSignal( | |
181 kObjectManagerInterface, | |
182 kObjectManagerInterfacesAdded, | |
183 base::Bind(&ObjectManager::InterfacesAddedReceived, | |
184 weak_ptr_factory_.GetWeakPtr()), | |
185 base::Bind(&ObjectManager::InterfacesAddedConnected, | |
186 weak_ptr_factory_.GetWeakPtr())); | |
187 | |
188 object_proxy_->ConnectToSignal( | |
189 kObjectManagerInterface, | |
190 kObjectManagerInterfacesRemoved, | |
191 base::Bind(&ObjectManager::InterfacesRemovedReceived, | |
192 weak_ptr_factory_.GetWeakPtr()), | |
193 base::Bind(&ObjectManager::InterfacesRemovedConnected, | |
194 weak_ptr_factory_.GetWeakPtr())); | |
195 | |
196 GetManagedObjects(); | |
197 } | |
198 | |
199 bool ObjectManager::SetupMatchRuleAndFilter() { | 170 bool ObjectManager::SetupMatchRuleAndFilter() { |
200 DCHECK(bus_); | 171 DCHECK(bus_); |
201 DCHECK(!setup_success_); | 172 DCHECK(!setup_success_); |
202 bus_->AssertOnDBusThread(); | 173 bus_->AssertOnDBusThread(); |
203 | 174 |
204 if (cleanup_called_) | 175 if (cleanup_called_) |
205 return false; | 176 return false; |
206 | 177 |
207 if (!bus_->Connect() || !bus_->SetUpAsyncOperations()) | 178 if (!bus_->Connect() || !bus_->SetUpAsyncOperations()) |
208 return false; | 179 return false; |
(...skipping 19 matching lines...) Expand all Loading... | |
228 return false; | 199 return false; |
229 } | 200 } |
230 | 201 |
231 match_rule_ = match_rule; | 202 match_rule_ = match_rule; |
232 setup_success_ = true; | 203 setup_success_ = true; |
233 | 204 |
234 return true; | 205 return true; |
235 } | 206 } |
236 | 207 |
237 void ObjectManager::OnSetupMatchRuleAndFilterComplete(bool success) { | 208 void ObjectManager::OnSetupMatchRuleAndFilterComplete(bool success) { |
238 LOG_IF(WARNING, !success) << service_name_ << " " << object_path_.value() | 209 if (!success) { |
239 << ": Failed to set up match rule."; | 210 LOG(WARNING) << service_name_ << " " << object_path_.value() |
240 if (success) | 211 << ": Failed to set up match rule."; |
241 InitializeObjects(); | 212 return; |
213 } | |
214 | |
215 DCHECK(bus_); | |
216 DCHECK(object_proxy_); | |
217 DCHECK(setup_success_); | |
218 | |
219 // |object_proxy_| is no longer valid if the Bus was shut down before this | |
220 // call. Don't initiate any other action from the origin thread. | |
221 if (cleanup_called_) | |
222 return; | |
223 | |
224 object_proxy_->ConnectToSignal( | |
225 kObjectManagerInterface, | |
226 kObjectManagerInterfacesAdded, | |
227 base::Bind(&ObjectManager::InterfacesAddedReceived, | |
228 weak_ptr_factory_.GetWeakPtr()), | |
229 base::Bind(&ObjectManager::InterfacesAddedConnected, | |
230 weak_ptr_factory_.GetWeakPtr())); | |
231 | |
232 object_proxy_->ConnectToSignal( | |
233 kObjectManagerInterface, | |
234 kObjectManagerInterfacesRemoved, | |
235 base::Bind(&ObjectManager::InterfacesRemovedReceived, | |
236 weak_ptr_factory_.GetWeakPtr()), | |
237 base::Bind(&ObjectManager::InterfacesRemovedConnected, | |
238 weak_ptr_factory_.GetWeakPtr())); | |
239 | |
240 object_proxy_->WaitForServiceToBeAvailable( | |
241 base::Bind(&ObjectManager::OnServiceInitiallyAvailable, | |
242 weak_ptr_factory_.GetWeakPtr())); | |
hashimoto
2016/09/02 08:33:06
You can just do this here:
if (!service_name_owne
Daniel Erat
2016/09/02 14:39:27
thanks, i hadn't seen the earlier call to GetServi
| |
243 } | |
244 | |
245 void ObjectManager::OnServiceInitiallyAvailable(bool service_is_available) { | |
246 if (!service_is_available) { | |
247 LOG(WARNING) << service_name_ << " " << object_path_.value() | |
248 << ": Failed to wait for service to become available"; | |
249 return; | |
250 } | |
251 GetManagedObjects(); | |
242 } | 252 } |
243 | 253 |
244 // static | 254 // static |
245 DBusHandlerResult ObjectManager::HandleMessageThunk(DBusConnection* connection, | 255 DBusHandlerResult ObjectManager::HandleMessageThunk(DBusConnection* connection, |
246 DBusMessage* raw_message, | 256 DBusMessage* raw_message, |
247 void* user_data) { | 257 void* user_data) { |
248 ObjectManager* self = reinterpret_cast<ObjectManager*>(user_data); | 258 ObjectManager* self = reinterpret_cast<ObjectManager*>(user_data); |
249 return self->HandleMessage(connection, raw_message); | 259 return self->HandleMessage(connection, raw_message); |
250 } | 260 } |
251 | 261 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 RemoveInterface(object_path, *iiter); | 536 RemoveInterface(object_path, *iiter); |
527 } | 537 } |
528 | 538 |
529 } | 539 } |
530 | 540 |
531 if (!new_owner.empty()) | 541 if (!new_owner.empty()) |
532 GetManagedObjects(); | 542 GetManagedObjects(); |
533 } | 543 } |
534 | 544 |
535 } // namespace dbus | 545 } // namespace dbus |
OLD | NEW |