OLD | NEW |
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 "device/generic_sensor/platform_sensor_provider_win.h" | 5 #include "device/generic_sensor/platform_sensor_provider_win.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 sensor_manager_ = sensor_manager; | 24 sensor_manager_ = sensor_manager; |
25 } | 25 } |
26 | 26 |
27 PlatformSensorProviderWin::PlatformSensorProviderWin() = default; | 27 PlatformSensorProviderWin::PlatformSensorProviderWin() = default; |
28 PlatformSensorProviderWin::~PlatformSensorProviderWin() = default; | 28 PlatformSensorProviderWin::~PlatformSensorProviderWin() = default; |
29 | 29 |
30 void PlatformSensorProviderWin::CreateSensorInternal( | 30 void PlatformSensorProviderWin::CreateSensorInternal( |
31 mojom::SensorType type, | 31 mojom::SensorType type, |
32 mojo::ScopedSharedBufferMapping mapping, | 32 mojo::ScopedSharedBufferMapping mapping, |
33 const CreateSensorCallback& callback) { | 33 const CreateSensorCallback& callback) { |
34 DCHECK(CalledOnValidThread()); | 34 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
35 if (!StartSensorThread()) { | 35 if (!StartSensorThread()) { |
36 callback.Run(nullptr); | 36 callback.Run(nullptr); |
37 return; | 37 return; |
38 } | 38 } |
39 | 39 |
40 base::PostTaskAndReplyWithResult( | 40 base::PostTaskAndReplyWithResult( |
41 sensor_thread_->task_runner().get(), FROM_HERE, | 41 sensor_thread_->task_runner().get(), FROM_HERE, |
42 base::Bind(&PlatformSensorProviderWin::CreateSensorReader, | 42 base::Bind(&PlatformSensorProviderWin::CreateSensorReader, |
43 base::Unretained(this), type), | 43 base::Unretained(this), type), |
44 base::Bind(&PlatformSensorProviderWin::SensorReaderCreated, | 44 base::Bind(&PlatformSensorProviderWin::SensorReaderCreated, |
(...skipping 29 matching lines...) Expand all Loading... |
74 sensor_manager_.Reset(); | 74 sensor_manager_.Reset(); |
75 sensor_thread_->Stop(); | 75 sensor_thread_->Stop(); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 void PlatformSensorProviderWin::SensorReaderCreated( | 79 void PlatformSensorProviderWin::SensorReaderCreated( |
80 mojom::SensorType type, | 80 mojom::SensorType type, |
81 mojo::ScopedSharedBufferMapping mapping, | 81 mojo::ScopedSharedBufferMapping mapping, |
82 const CreateSensorCallback& callback, | 82 const CreateSensorCallback& callback, |
83 std::unique_ptr<PlatformSensorReaderWin> sensor_reader) { | 83 std::unique_ptr<PlatformSensorReaderWin> sensor_reader) { |
84 DCHECK(CalledOnValidThread()); | 84 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
85 if (!sensor_reader) { | 85 if (!sensor_reader) { |
86 callback.Run(nullptr); | 86 callback.Run(nullptr); |
87 if (!HasSensors()) | 87 if (!HasSensors()) |
88 StopSensorThread(); | 88 StopSensorThread(); |
89 return; | 89 return; |
90 } | 90 } |
91 | 91 |
92 scoped_refptr<PlatformSensor> sensor = new PlatformSensorWin( | 92 scoped_refptr<PlatformSensor> sensor = new PlatformSensorWin( |
93 type, std::move(mapping), this, sensor_thread_->task_runner(), | 93 type, std::move(mapping), this, sensor_thread_->task_runner(), |
94 std::move(sensor_reader)); | 94 std::move(sensor_reader)); |
95 callback.Run(sensor); | 95 callback.Run(sensor); |
96 } | 96 } |
97 | 97 |
98 std::unique_ptr<PlatformSensorReaderWin> | 98 std::unique_ptr<PlatformSensorReaderWin> |
99 PlatformSensorProviderWin::CreateSensorReader(mojom::SensorType type) { | 99 PlatformSensorProviderWin::CreateSensorReader(mojom::SensorType type) { |
100 DCHECK(sensor_thread_->task_runner()->BelongsToCurrentThread()); | 100 DCHECK(sensor_thread_->task_runner()->BelongsToCurrentThread()); |
101 if (!InitializeSensorManager()) | 101 if (!InitializeSensorManager()) |
102 return nullptr; | 102 return nullptr; |
103 return PlatformSensorReaderWin::Create(type, sensor_manager_); | 103 return PlatformSensorReaderWin::Create(type, sensor_manager_); |
104 } | 104 } |
105 | 105 |
106 } // namespace device | 106 } // namespace device |
OLD | NEW |