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

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

Issue 2730333002: Make DeviceSensorService implement MainLoop::DestructionObserver (Closed)
Patch Set: Make DeviceSensorService observes IOThread to shutdown in right time. 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
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 #if !defined(OS_ANDROID)
ke.he 2017/03/08 09:19:55 For Non-Android platform, The strongBinding happen
22 DCHECK(base::MessageLoopForIO::IsCurrent());
23 base::MessageLoop::current()->AddDestructionObserver(this);
24 #endif
25 }
20 26
21 DeviceSensorService::~DeviceSensorService() {} 27 DeviceSensorService::~DeviceSensorService() {}
22 28
23 DeviceSensorService* DeviceSensorService::GetInstance() { 29 DeviceSensorService* DeviceSensorService::GetInstance() {
24 return base::Singleton<DeviceSensorService, base::LeakySingletonTraits< 30 return base::Singleton<DeviceSensorService, base::LeakySingletonTraits<
25 DeviceSensorService>>::get(); 31 DeviceSensorService>>::get();
26 } 32 }
27 33
28 void DeviceSensorService::AddConsumer(ConsumerType consumer_type) { 34 void DeviceSensorService::AddConsumer(ConsumerType consumer_type) {
29 if (!ChangeNumberConsumers(consumer_type, 1)) 35 if (!ChangeNumberConsumers(consumer_type, 1))
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 94 }
89 return 0; 95 return 0;
90 } 96 }
91 97
92 mojo::ScopedSharedBufferHandle DeviceSensorService::GetSharedMemoryHandle( 98 mojo::ScopedSharedBufferHandle DeviceSensorService::GetSharedMemoryHandle(
93 ConsumerType consumer_type) { 99 ConsumerType consumer_type) {
94 DCHECK(thread_checker_.CalledOnValidThread()); 100 DCHECK(thread_checker_.CalledOnValidThread());
95 return data_fetcher_->GetSharedMemoryHandle(consumer_type); 101 return data_fetcher_->GetSharedMemoryHandle(consumer_type);
96 } 102 }
97 103
104 void DeviceSensorService::WillDestroyCurrentMessageLoop() {
105 DCHECK(base::MessageLoopForIO::IsCurrent());
106 base::MessageLoop::current()->RemoveDestructionObserver(this);
107 TRACE_EVENT0("shutdown", "DeviceSensorService::Subsystem:SensorService");
108 Shutdown();
109 }
110
98 void DeviceSensorService::Shutdown() { 111 void DeviceSensorService::Shutdown() {
99 if (data_fetcher_) { 112 if (data_fetcher_) {
100 data_fetcher_->Shutdown(); 113 data_fetcher_->Shutdown();
101 data_fetcher_.reset(); 114 data_fetcher_.reset();
102 } 115 }
103 is_shutdown_ = true; 116 is_shutdown_ = true;
104 } 117 }
105 118
106 void DeviceSensorService::SetDataFetcherForTesting( 119 void DeviceSensorService::SetDataFetcherForTesting(
107 DataFetcherSharedMemory* test_data_fetcher) { 120 DataFetcherSharedMemory* test_data_fetcher) {
108 if (data_fetcher_) 121 if (data_fetcher_)
109 data_fetcher_->Shutdown(); 122 data_fetcher_->Shutdown();
110 data_fetcher_.reset(test_data_fetcher); 123 data_fetcher_.reset(test_data_fetcher);
111 } 124 }
112 125
113 } // namespace device 126 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698