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

Side by Side Diff: device/sensors/device_sensor_service.cc

Issue 2730333002: Make DeviceSensorService implement MainLoop::DestructionObserver (Closed)
Patch Set: code rebase Created 3 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
« no previous file with comments | « device/sensors/device_sensor_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "device/sensors/device_sensor_service.h" 5 #include "device/sensors/device_sensor_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/trace_event/trace_event.h"
10 #include "device/sensors/data_fetcher_shared_memory.h" 11 #include "device/sensors/data_fetcher_shared_memory.h"
11 12
12 namespace device { 13 namespace device {
13 14
14 DeviceSensorService::DeviceSensorService() 15 DeviceSensorService::DeviceSensorService()
15 : num_light_readers_(0), 16 : num_light_readers_(0),
16 num_motion_readers_(0), 17 num_motion_readers_(0),
17 num_orientation_readers_(0), 18 num_orientation_readers_(0),
18 num_orientation_absolute_readers_(0), 19 num_orientation_absolute_readers_(0),
19 is_shutdown_(false) {} 20 is_shutdown_(false) {
21 base::MessageLoop::current()->AddDestructionObserver(this);
22 }
20 23
21 DeviceSensorService::~DeviceSensorService() {} 24 DeviceSensorService::~DeviceSensorService() {}
22 25
23 DeviceSensorService* DeviceSensorService::GetInstance() { 26 DeviceSensorService* DeviceSensorService::GetInstance() {
24 return base::Singleton<DeviceSensorService, base::LeakySingletonTraits< 27 return base::Singleton<DeviceSensorService, base::LeakySingletonTraits<
25 DeviceSensorService>>::get(); 28 DeviceSensorService>>::get();
26 } 29 }
27 30
28 void DeviceSensorService::AddConsumer(ConsumerType consumer_type) { 31 void DeviceSensorService::AddConsumer(ConsumerType consumer_type) {
29 if (!ChangeNumberConsumers(consumer_type, 1)) 32 if (!ChangeNumberConsumers(consumer_type, 1))
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 91 }
89 return 0; 92 return 0;
90 } 93 }
91 94
92 mojo::ScopedSharedBufferHandle DeviceSensorService::GetSharedMemoryHandle( 95 mojo::ScopedSharedBufferHandle DeviceSensorService::GetSharedMemoryHandle(
93 ConsumerType consumer_type) { 96 ConsumerType consumer_type) {
94 DCHECK(thread_checker_.CalledOnValidThread()); 97 DCHECK(thread_checker_.CalledOnValidThread());
95 return data_fetcher_->GetSharedMemoryHandle(consumer_type); 98 return data_fetcher_->GetSharedMemoryHandle(consumer_type);
96 } 99 }
97 100
101 void DeviceSensorService::WillDestroyCurrentMessageLoop() {
102 base::MessageLoop::current()->RemoveDestructionObserver(this);
103 TRACE_EVENT0("shutdown", "DeviceSensorService::Subsystem:SensorService");
104 Shutdown();
105 }
106
98 void DeviceSensorService::Shutdown() { 107 void DeviceSensorService::Shutdown() {
99 if (data_fetcher_) { 108 if (data_fetcher_) {
100 data_fetcher_->Shutdown(); 109 data_fetcher_->Shutdown();
101 data_fetcher_.reset(); 110 data_fetcher_.reset();
102 } 111 }
103 is_shutdown_ = true; 112 is_shutdown_ = true;
104 } 113 }
105 114
106 void DeviceSensorService::SetDataFetcherForTesting( 115 void DeviceSensorService::SetDataFetcherForTesting(
107 DataFetcherSharedMemory* test_data_fetcher) { 116 DataFetcherSharedMemory* test_data_fetcher) {
108 if (data_fetcher_) 117 if (data_fetcher_)
109 data_fetcher_->Shutdown(); 118 data_fetcher_->Shutdown();
110 data_fetcher_.reset(test_data_fetcher); 119 data_fetcher_.reset(test_data_fetcher);
111 } 120 }
112 121
113 } // namespace device 122 } // namespace device
OLDNEW
« no previous file with comments | « device/sensors/device_sensor_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698