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

Side by Side Diff: services/device/device_service.cc

Issue 2734943003: Device Service: Decouple Wake Lock from //content (Closed)
Patch Set: Response to review + 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
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 "services/device/device_service.h" 5 #include "services/device/device_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "device/wake_lock/wake_lock_context_provider.h"
12 #include "services/device/fingerprint/fingerprint.h" 13 #include "services/device/fingerprint/fingerprint.h"
13 #include "services/device/power_monitor/power_monitor_message_broadcaster.h" 14 #include "services/device/power_monitor/power_monitor_message_broadcaster.h"
14 #include "services/device/time_zone_monitor/time_zone_monitor.h" 15 #include "services/device/time_zone_monitor/time_zone_monitor.h"
15 #include "services/service_manager/public/cpp/connection.h" 16 #include "services/service_manager/public/cpp/connection.h"
16 #include "services/service_manager/public/cpp/interface_registry.h" 17 #include "services/service_manager/public/cpp/interface_registry.h"
18 #include "ui/gfx/native_widget_types.h"
17 19
18 #if defined(OS_ANDROID) 20 #if defined(OS_ANDROID)
19 #include "services/device/android/register_jni.h" 21 #include "services/device/android/register_jni.h"
20 #include "services/device/screen_orientation/screen_orientation_listener_android .h" 22 #include "services/device/screen_orientation/screen_orientation_listener_android .h"
21 #endif 23 #endif
22 24
23 namespace device { 25 namespace device {
24 26
27 #if defined(OS_ANDROID)
25 std::unique_ptr<service_manager::Service> CreateDeviceService( 28 std::unique_ptr<service_manager::Service> CreateDeviceService(
26 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, 29 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
27 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) { 30 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
28 #if defined(OS_ANDROID) 31 WakeLockContextCallback wake_lock_context_callback) {
dcheng 2017/03/17 06:55:26 Nit: std::move() the callback if you want to pass
blundell 2017/03/17 12:28:22 Done.
29 if (!EnsureJniRegistered()) { 32 if (!EnsureJniRegistered()) {
30 DLOG(ERROR) << "Failed to register JNI for Device Service"; 33 DLOG(ERROR) << "Failed to register JNI for Device Service";
31 return nullptr; 34 return nullptr;
32 } 35 }
33 #endif
34 36
35 return base::MakeUnique<DeviceService>(std::move(file_task_runner), 37 return base::MakeUnique<DeviceService>(std::move(file_task_runner),
38 std::move(io_task_runner),
dcheng 2017/03/17 06:55:26 Nit: #include <utility> for std::move
blundell 2017/03/17 12:28:22 Done.
39 wake_lock_context_callback);
40 }
41 #else
42 std::unique_ptr<service_manager::Service> CreateDeviceService(
43 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
44 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) {
45 return base::MakeUnique<DeviceService>(std::move(file_task_runner),
36 std::move(io_task_runner)); 46 std::move(io_task_runner));
37 } 47 }
48 #endif
38 49
50 #if defined(OS_ANDROID)
51 DeviceService::DeviceService(
52 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
53 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
54 WakeLockContextCallback wake_lock_context_callback)
55 : file_task_runner_(std::move(file_task_runner)),
56 io_task_runner_(std::move(io_task_runner)),
57 wake_lock_context_callback_(wake_lock_context_callback) {}
58 #else
39 DeviceService::DeviceService( 59 DeviceService::DeviceService(
40 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, 60 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
41 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) 61 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
42 : file_task_runner_(std::move(file_task_runner)), 62 : file_task_runner_(std::move(file_task_runner)),
43 io_task_runner_(std::move(io_task_runner)) {} 63 io_task_runner_(std::move(io_task_runner)) {}
64 #endif
44 65
45 DeviceService::~DeviceService() {} 66 DeviceService::~DeviceService() {}
46 67
47 void DeviceService::OnStart() {} 68 void DeviceService::OnStart() {}
48 69
49 bool DeviceService::OnConnect(const service_manager::ServiceInfo& remote_info, 70 bool DeviceService::OnConnect(const service_manager::ServiceInfo& remote_info,
50 service_manager::InterfaceRegistry* registry) { 71 service_manager::InterfaceRegistry* registry) {
51 registry->AddInterface<mojom::Fingerprint>(this); 72 registry->AddInterface<mojom::Fingerprint>(this);
52 registry->AddInterface<mojom::PowerMonitor>(this); 73 registry->AddInterface<mojom::PowerMonitor>(this);
53 registry->AddInterface<mojom::ScreenOrientationListener>(this); 74 registry->AddInterface<mojom::ScreenOrientationListener>(this);
54 registry->AddInterface<mojom::TimeZoneMonitor>(this); 75 registry->AddInterface<mojom::TimeZoneMonitor>(this);
76 registry->AddInterface<mojom::WakeLockContextProvider>(this);
55 77
56 return true; 78 return true;
57 } 79 }
58 80
59 void DeviceService::Create(const service_manager::Identity& remote_identity, 81 void DeviceService::Create(const service_manager::Identity& remote_identity,
60 mojom::FingerprintRequest request) { 82 mojom::FingerprintRequest request) {
61 Fingerprint::Create(std::move(request)); 83 Fingerprint::Create(std::move(request));
62 } 84 }
63 85
64 void DeviceService::Create(const service_manager::Identity& remote_identity, 86 void DeviceService::Create(const service_manager::Identity& remote_identity,
(...skipping 16 matching lines...) Expand all
81 #endif 103 #endif
82 } 104 }
83 105
84 void DeviceService::Create(const service_manager::Identity& remote_identity, 106 void DeviceService::Create(const service_manager::Identity& remote_identity,
85 mojom::TimeZoneMonitorRequest request) { 107 mojom::TimeZoneMonitorRequest request) {
86 if (!time_zone_monitor_) 108 if (!time_zone_monitor_)
87 time_zone_monitor_ = TimeZoneMonitor::Create(file_task_runner_); 109 time_zone_monitor_ = TimeZoneMonitor::Create(file_task_runner_);
88 time_zone_monitor_->Bind(std::move(request)); 110 time_zone_monitor_->Bind(std::move(request));
89 } 111 }
90 112
113 void DeviceService::Create(const service_manager::Identity& remote_identity,
114 mojom::WakeLockContextProviderRequest request) {
115 WakeLockContextProvider::Create(std::move(request), file_task_runner_,
116 wake_lock_context_callback_);
117 }
118
91 } // namespace device 119 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698