OLD | NEW |
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 "chrome/browser/chromeos/dbus/cros_dbus_service.h" | 5 #include "chrome/browser/chromeos/dbus/cros_dbus_service.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
8 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
9 #include "chrome/browser/chromeos/dbus/proxy_resolution_service_provider.h" | 10 #include "chrome/browser/chromeos/dbus/proxy_resolution_service_provider.h" |
10 #include "chrome/browser/chromeos/system/runtime_environment.h" | 11 #include "chrome/browser/chromeos/system/runtime_environment.h" |
11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
12 #include "dbus/bus.h" | 13 #include "dbus/bus.h" |
13 #include "dbus/exported_object.h" | 14 #include "dbus/exported_object.h" |
14 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
15 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
16 | 17 |
(...skipping 15 matching lines...) Expand all Loading... |
32 // CrosDBusService override. | 33 // CrosDBusService override. |
33 virtual void Start() { | 34 virtual void Start() { |
34 // Make sure we're running on the origin thread (i.e. the UI thread in | 35 // Make sure we're running on the origin thread (i.e. the UI thread in |
35 // production). | 36 // production). |
36 DCHECK(OnOriginThread()); | 37 DCHECK(OnOriginThread()); |
37 | 38 |
38 // Return if the service has been already started. | 39 // Return if the service has been already started. |
39 if (service_started_) | 40 if (service_started_) |
40 return; | 41 return; |
41 | 42 |
| 43 bus_->RequestOwnership(kLibCrosServiceName, |
| 44 base::Bind(&CrosDBusServiceImpl::OnOwnership, |
| 45 base::Unretained(this))); |
| 46 |
42 exported_object_ = bus_->GetExportedObject( | 47 exported_object_ = bus_->GetExportedObject( |
43 kLibCrosServiceName, | |
44 dbus::ObjectPath(kLibCrosServicePath)); | 48 dbus::ObjectPath(kLibCrosServicePath)); |
45 | 49 |
46 for (size_t i = 0; i < service_providers_.size(); ++i) | 50 for (size_t i = 0; i < service_providers_.size(); ++i) |
47 service_providers_[i]->Start(exported_object_); | 51 service_providers_[i]->Start(exported_object_); |
48 | 52 |
49 service_started_ = true; | 53 service_started_ = true; |
50 | 54 |
51 VLOG(1) << "CrosDBusServiceImpl started."; | 55 VLOG(1) << "CrosDBusServiceImpl started."; |
52 } | 56 } |
53 | 57 |
54 // Registers a service provider. This must be done before Start(). | 58 // Registers a service provider. This must be done before Start(). |
55 // |provider| will be owned by CrosDBusService. | 59 // |provider| will be owned by CrosDBusService. |
56 void RegisterServiceProvider(ServiceProviderInterface* provider) { | 60 void RegisterServiceProvider(ServiceProviderInterface* provider) { |
57 service_providers_.push_back(provider); | 61 service_providers_.push_back(provider); |
58 } | 62 } |
59 | 63 |
60 private: | 64 private: |
61 // Returns true if the current thread is on the origin thread. | 65 // Returns true if the current thread is on the origin thread. |
62 bool OnOriginThread() { | 66 bool OnOriginThread() { |
63 return base::PlatformThread::CurrentId() == origin_thread_id_; | 67 return base::PlatformThread::CurrentId() == origin_thread_id_; |
64 } | 68 } |
65 | 69 |
| 70 // Called when an ownership request is completed. |
| 71 void OnOwnership(const std::string& service_name, |
| 72 bool success) { |
| 73 LOG_IF(ERROR, !success) << "Failed to own: " << service_name; |
| 74 } |
| 75 |
66 bool service_started_; | 76 bool service_started_; |
67 base::PlatformThreadId origin_thread_id_; | 77 base::PlatformThreadId origin_thread_id_; |
68 dbus::Bus* bus_; | 78 dbus::Bus* bus_; |
69 scoped_refptr<dbus::ExportedObject> exported_object_; | 79 scoped_refptr<dbus::ExportedObject> exported_object_; |
70 | 80 |
71 // Service providers that form CrosDBusService. | 81 // Service providers that form CrosDBusService. |
72 std::vector<ServiceProviderInterface*> service_providers_; | 82 std::vector<ServiceProviderInterface*> service_providers_; |
73 }; | 83 }; |
74 | 84 |
75 // The stub CrosDBusService implementation used on Linux desktop, | 85 // The stub CrosDBusService implementation used on Linux desktop, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 return service; | 117 return service; |
108 } | 118 } |
109 | 119 |
110 CrosDBusService::~CrosDBusService() { | 120 CrosDBusService::~CrosDBusService() { |
111 } | 121 } |
112 | 122 |
113 CrosDBusService::ServiceProviderInterface::~ServiceProviderInterface() { | 123 CrosDBusService::ServiceProviderInterface::~ServiceProviderInterface() { |
114 } | 124 } |
115 | 125 |
116 } // namespace chromeos | 126 } // namespace chromeos |
OLD | NEW |