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

Side by Side Diff: content/browser/device_sensors/device_sensor_host.cc

Issue 2160913005: Use a ThreadChecker in DeviceSensorHost instead of DCHECK_CURRENTLY_ON. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/device_sensors/device_sensor_host.h" 5 #include "content/browser/device_sensors/device_sensor_host.h"
6 6
7 #include "content/browser/device_sensors/device_sensor_service.h" 7 #include "content/browser/device_sensors/device_sensor_service.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 9
10 namespace content { 10 namespace content {
11 11
12 template <typename MojoInterface, ConsumerType consumer_type> 12 template <typename MojoInterface, ConsumerType consumer_type>
13 void DeviceSensorHost<MojoInterface, consumer_type>::Create( 13 void DeviceSensorHost<MojoInterface, consumer_type>::Create(
14 mojo::InterfaceRequest<MojoInterface> request) { 14 mojo::InterfaceRequest<MojoInterface> request) {
15 new DeviceSensorHost(std::move(request)); 15 new DeviceSensorHost(std::move(request));
16 } 16 }
17 17
18 template <typename MojoInterface, ConsumerType consumer_type> 18 template <typename MojoInterface, ConsumerType consumer_type>
19 DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost( 19 DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost(
20 mojo::InterfaceRequest<MojoInterface> request) 20 mojo::InterfaceRequest<MojoInterface> request)
21 : is_started_(false), binding_(this, std::move(request)) {} 21 : is_started_(false), binding_(this, std::move(request)) {}
22 22
23 template <typename MojoInterface, ConsumerType consumer_type> 23 template <typename MojoInterface, ConsumerType consumer_type>
24 DeviceSensorHost<MojoInterface, consumer_type>::~DeviceSensorHost() { 24 DeviceSensorHost<MojoInterface, consumer_type>::~DeviceSensorHost() {
25 DCHECK_CURRENTLY_ON(BrowserThread::IO); 25 DCHECK(thread_checker_.CalledOnValidThread());
26 if (is_started_) 26 if (is_started_)
27 DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type); 27 DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type);
28 } 28 }
29 29
30 template <typename MojoInterface, ConsumerType consumer_type> 30 template <typename MojoInterface, ConsumerType consumer_type>
31 void DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost:: 31 void DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost::
32 StartPolling(const typename MojoInterface::StartPollingCallback& callback) { 32 StartPolling(const typename MojoInterface::StartPollingCallback& callback) {
33 DCHECK_CURRENTLY_ON(BrowserThread::IO); 33 DCHECK(thread_checker_.CalledOnValidThread());
34 DCHECK(!is_started_); 34 DCHECK(!is_started_);
35 if (is_started_) 35 if (is_started_)
36 return; 36 return;
37 is_started_ = true; 37 is_started_ = true;
38 DeviceSensorService::GetInstance()->AddConsumer(consumer_type); 38 DeviceSensorService::GetInstance()->AddConsumer(consumer_type);
39 callback.Run( 39 callback.Run(
40 DeviceSensorService::GetInstance()->GetSharedMemoryHandle(consumer_type)); 40 DeviceSensorService::GetInstance()->GetSharedMemoryHandle(consumer_type));
41 } 41 }
42 42
43 template <typename MojoInterface, ConsumerType consumer_type> 43 template <typename MojoInterface, ConsumerType consumer_type>
44 void DeviceSensorHost<MojoInterface, 44 void DeviceSensorHost<MojoInterface,
45 consumer_type>::DeviceSensorHost::StopPolling() { 45 consumer_type>::DeviceSensorHost::StopPolling() {
46 DCHECK_CURRENTLY_ON(BrowserThread::IO); 46 DCHECK(thread_checker_.CalledOnValidThread());
47 DCHECK(is_started_); 47 DCHECK(is_started_);
48 if (!is_started_) 48 if (!is_started_)
49 return; 49 return;
50 is_started_ = false; 50 is_started_ = false;
51 DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type); 51 DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type);
52 } 52 }
53 53
54 template class DeviceSensorHost<device::mojom::LightSensor, 54 template class DeviceSensorHost<device::mojom::LightSensor,
55 CONSUMER_TYPE_LIGHT>; 55 CONSUMER_TYPE_LIGHT>;
56 template class DeviceSensorHost<device::mojom::MotionSensor, 56 template class DeviceSensorHost<device::mojom::MotionSensor,
57 CONSUMER_TYPE_MOTION>; 57 CONSUMER_TYPE_MOTION>;
58 template class DeviceSensorHost<device::mojom::OrientationSensor, 58 template class DeviceSensorHost<device::mojom::OrientationSensor,
59 CONSUMER_TYPE_ORIENTATION>; 59 CONSUMER_TYPE_ORIENTATION>;
60 template class DeviceSensorHost<device::mojom::OrientationAbsoluteSensor, 60 template class DeviceSensorHost<device::mojom::OrientationAbsoluteSensor,
61 CONSUMER_TYPE_ORIENTATION_ABSOLUTE>; 61 CONSUMER_TYPE_ORIENTATION_ABSOLUTE>;
62 62
63 } // namespace content 63 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698