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

Unified Diff: device/generic_sensor/platform_sensor_provider_win.cc

Issue 2865263002: Move //device/generic_sensor to be part of the internal implementation of the Device Service. (Closed)
Patch Set: code rebase Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: device/generic_sensor/platform_sensor_provider_win.cc
diff --git a/device/generic_sensor/platform_sensor_provider_win.cc b/device/generic_sensor/platform_sensor_provider_win.cc
deleted file mode 100644
index e8948375a5e4f10f6e5ac83b90fb85e793f6b86f..0000000000000000000000000000000000000000
--- a/device/generic_sensor/platform_sensor_provider_win.cc
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "device/generic_sensor/platform_sensor_provider_win.h"
-
-#include <objbase.h>
-
-#include "base/memory/ptr_util.h"
-#include "base/memory/singleton.h"
-#include "base/task_runner_util.h"
-#include "base/threading/thread.h"
-#include "device/generic_sensor/platform_sensor_win.h"
-
-namespace device {
-
-// static
-PlatformSensorProviderWin* PlatformSensorProviderWin::GetInstance() {
- return base::Singleton<
- PlatformSensorProviderWin,
- base::LeakySingletonTraits<PlatformSensorProviderWin>>::get();
-}
-
-void PlatformSensorProviderWin::SetSensorManagerForTesting(
- base::win::ScopedComPtr<ISensorManager> sensor_manager) {
- sensor_manager_ = sensor_manager;
-}
-
-PlatformSensorProviderWin::PlatformSensorProviderWin() = default;
-PlatformSensorProviderWin::~PlatformSensorProviderWin() = default;
-
-void PlatformSensorProviderWin::CreateSensorInternal(
- mojom::SensorType type,
- mojo::ScopedSharedBufferMapping mapping,
- const CreateSensorCallback& callback) {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
- if (!StartSensorThread()) {
- callback.Run(nullptr);
- return;
- }
-
- base::PostTaskAndReplyWithResult(
- sensor_thread_->task_runner().get(), FROM_HERE,
- base::Bind(&PlatformSensorProviderWin::CreateSensorReader,
- base::Unretained(this), type),
- base::Bind(&PlatformSensorProviderWin::SensorReaderCreated,
- base::Unretained(this), type, base::Passed(&mapping),
- callback));
-}
-
-bool PlatformSensorProviderWin::InitializeSensorManager() {
- if (sensor_manager_)
- return true;
-
- HRESULT hr = ::CoCreateInstance(CLSID_SensorManager, nullptr, CLSCTX_ALL,
- IID_PPV_ARGS(&sensor_manager_));
- return SUCCEEDED(hr);
-}
-
-void PlatformSensorProviderWin::AllSensorsRemoved() {
- StopSensorThread();
-}
-
-bool PlatformSensorProviderWin::StartSensorThread() {
- if (!sensor_thread_) {
- sensor_thread_ = base::MakeUnique<base::Thread>("Sensor thread");
- sensor_thread_->init_com_with_mta(true);
- }
-
- if (!sensor_thread_->IsRunning())
- return sensor_thread_->Start();
- return true;
-}
-
-void PlatformSensorProviderWin::StopSensorThread() {
- if (sensor_thread_ && sensor_thread_->IsRunning()) {
- sensor_manager_.Reset();
- sensor_thread_->Stop();
- }
-}
-
-void PlatformSensorProviderWin::SensorReaderCreated(
- mojom::SensorType type,
- mojo::ScopedSharedBufferMapping mapping,
- const CreateSensorCallback& callback,
- std::unique_ptr<PlatformSensorReaderWin> sensor_reader) {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
- if (!sensor_reader) {
- callback.Run(nullptr);
- if (!HasSensors())
- StopSensorThread();
- return;
- }
-
- scoped_refptr<PlatformSensor> sensor = new PlatformSensorWin(
- type, std::move(mapping), this, sensor_thread_->task_runner(),
- std::move(sensor_reader));
- callback.Run(sensor);
-}
-
-std::unique_ptr<PlatformSensorReaderWin>
-PlatformSensorProviderWin::CreateSensorReader(mojom::SensorType type) {
- DCHECK(sensor_thread_->task_runner()->BelongsToCurrentThread());
- if (!InitializeSensorManager())
- return nullptr;
- return PlatformSensorReaderWin::Create(type, sensor_manager_);
-}
-
-} // namespace device
« no previous file with comments | « device/generic_sensor/platform_sensor_provider_win.h ('k') | device/generic_sensor/platform_sensor_reader_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698