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

Side by Side Diff: chrome/browser/chromeos/dbus/cros_dbus_service.cc

Issue 9839075: chromeos: Separate CrosDBusService Initialize/Shutdown from DBusThreadManager (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased onto ToT Created 8 years, 9 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
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 "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/bind.h"
8 #include "base/chromeos/chromeos_version.h" 8 #include "base/chromeos/chromeos_version.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
11 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h"
11 #include "chrome/browser/chromeos/dbus/proxy_resolution_service_provider.h" 12 #include "chrome/browser/chromeos/dbus/proxy_resolution_service_provider.h"
12 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
13 #include "dbus/bus.h" 14 #include "dbus/bus.h"
14 #include "dbus/exported_object.h" 15 #include "dbus/exported_object.h"
15 #include "dbus/object_path.h" 16 #include "dbus/object_path.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h" 17 #include "third_party/cros_system_api/dbus/service_constants.h"
17 18
18 namespace chromeos { 19 namespace chromeos {
19 20
21 namespace {
22
23 CrosDBusService* g_cros_dbus_service = NULL;
24
25 } // namespace
26
20 // The CrosDBusService implementation used in production, and unit tests. 27 // The CrosDBusService implementation used in production, and unit tests.
21 class CrosDBusServiceImpl : public CrosDBusService { 28 class CrosDBusServiceImpl : public CrosDBusService {
22 public: 29 public:
23 explicit CrosDBusServiceImpl(dbus::Bus* bus) 30 explicit CrosDBusServiceImpl(dbus::Bus* bus)
24 : service_started_(false), 31 : service_started_(false),
25 origin_thread_id_(base::PlatformThread::CurrentId()), 32 origin_thread_id_(base::PlatformThread::CurrentId()),
26 bus_(bus) { 33 bus_(bus) {
27 } 34 }
28 35
29 virtual ~CrosDBusServiceImpl() { 36 virtual ~CrosDBusServiceImpl() {
30 STLDeleteElements(&service_providers_); 37 STLDeleteElements(&service_providers_);
31 } 38 }
32 39
33 // CrosDBusService override. 40 // Starts the D-Bus service.
34 virtual void Start() { 41 void Start() {
35 // Make sure we're running on the origin thread (i.e. the UI thread in 42 // Make sure we're running on the origin thread (i.e. the UI thread in
36 // production). 43 // production).
37 DCHECK(OnOriginThread()); 44 DCHECK(OnOriginThread());
38 45
39 // Return if the service has been already started. 46 // Return if the service has been already started.
40 if (service_started_) 47 if (service_started_)
41 return; 48 return;
42 49
43 bus_->RequestOwnership(kLibCrosServiceName, 50 bus_->RequestOwnership(kLibCrosServiceName,
44 base::Bind(&CrosDBusServiceImpl::OnOwnership, 51 base::Bind(&CrosDBusServiceImpl::OnOwnership,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 91
85 // The stub CrosDBusService implementation used on Linux desktop, 92 // The stub CrosDBusService implementation used on Linux desktop,
86 // which does nothing as of now. 93 // which does nothing as of now.
87 class CrosDBusServiceStubImpl : public CrosDBusService { 94 class CrosDBusServiceStubImpl : public CrosDBusService {
88 public: 95 public:
89 CrosDBusServiceStubImpl() { 96 CrosDBusServiceStubImpl() {
90 } 97 }
91 98
92 virtual ~CrosDBusServiceStubImpl() { 99 virtual ~CrosDBusServiceStubImpl() {
93 } 100 }
94
95 // CrosDBusService override.
96 virtual void Start() {
97 }
98 }; 101 };
99 102
100 // static 103 // static
101 CrosDBusService* CrosDBusService::Create(dbus::Bus* bus) { 104 void CrosDBusService::Initialize() {
105 if (g_cros_dbus_service) {
106 LOG(WARNING) << "CrosDBusService was already initialized";
107 return;
108 }
102 if (base::chromeos::IsRunningOnChromeOS()) { 109 if (base::chromeos::IsRunningOnChromeOS()) {
110 dbus::Bus* bus = DBusThreadManager::Get()->GetSystemBus();
103 CrosDBusServiceImpl* service = new CrosDBusServiceImpl(bus); 111 CrosDBusServiceImpl* service = new CrosDBusServiceImpl(bus);
104 service->RegisterServiceProvider(ProxyResolutionServiceProvider::Create()); 112 service->RegisterServiceProvider(ProxyResolutionServiceProvider::Create());
105 return service; 113 g_cros_dbus_service = service;
114 service->Start();
106 } else { 115 } else {
107 return new CrosDBusServiceStubImpl; 116 g_cros_dbus_service = new CrosDBusServiceStubImpl;
108 } 117 }
118 VLOG(1) << "CrosDBusService initialized";
109 } 119 }
110 120
111 // static 121 // static
112 CrosDBusService* CrosDBusService::CreateForTesting( 122 void CrosDBusService::InitializeForTesting(
113 dbus::Bus* bus, 123 dbus::Bus* bus,
114 ServiceProviderInterface* proxy_resolution_service) { 124 ServiceProviderInterface* proxy_resolution_service) {
125 if (g_cros_dbus_service) {
126 LOG(WARNING) << "CrosDBusService was already initialized";
127 return;
128 }
115 CrosDBusServiceImpl* service = new CrosDBusServiceImpl(bus); 129 CrosDBusServiceImpl* service = new CrosDBusServiceImpl(bus);
116 service->RegisterServiceProvider(proxy_resolution_service); 130 service->RegisterServiceProvider(proxy_resolution_service);
117 return service; 131 service->Start();
132 g_cros_dbus_service = service;
133 VLOG(1) << "CrosDBusService initialized";
134 }
135
136 // static
137 void CrosDBusService::Shutdown() {
138 delete g_cros_dbus_service;
139 g_cros_dbus_service = NULL;
140 VLOG(1) << "CrosDBusService Shutdown completed";
118 } 141 }
119 142
120 CrosDBusService::~CrosDBusService() { 143 CrosDBusService::~CrosDBusService() {
121 } 144 }
122 145
123 CrosDBusService::ServiceProviderInterface::~ServiceProviderInterface() { 146 CrosDBusService::ServiceProviderInterface::~ServiceProviderInterface() {
124 } 147 }
125 148
126 } // namespace chromeos 149 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/dbus/cros_dbus_service.h ('k') | chrome/browser/chromeos/dbus/cros_dbus_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698