OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/wake_lock/wake_lock_provider.h" | 5 #include "device/wake_lock/wake_lock_provider.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "device/wake_lock/wake_lock_service_impl.h" | 9 #include "device/wake_lock/wake_lock_service_impl.h" |
| 10 #include "device/wake_lock/wake_lock_service_impl_for_testing.h" |
10 #include "mojo/public/cpp/bindings/strong_binding.h" | 11 #include "mojo/public/cpp/bindings/strong_binding.h" |
11 | 12 |
12 namespace device { | 13 namespace device { |
13 | 14 |
| 15 bool WakeLockProvider::is_in_service_unittest_ = false; |
| 16 |
14 // static | 17 // static |
15 void WakeLockProvider::Create( | 18 void WakeLockProvider::Create( |
16 mojom::WakeLockProviderRequest request, | 19 mojom::WakeLockProviderRequest request, |
17 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, | 20 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, |
18 const WakeLockContextCallback& native_view_getter) { | 21 const WakeLockContextCallback& native_view_getter) { |
19 mojo::MakeStrongBinding(base::MakeUnique<WakeLockProvider>( | 22 mojo::MakeStrongBinding(base::MakeUnique<WakeLockProvider>( |
20 std::move(file_task_runner), native_view_getter), | 23 std::move(file_task_runner), native_view_getter), |
21 std::move(request)); | 24 std::move(request)); |
22 } | 25 } |
23 | 26 |
(...skipping 13 matching lines...) Expand all Loading... |
37 base::MakeUnique<WakeLockServiceContext>(context_id, file_task_runner_, | 40 base::MakeUnique<WakeLockServiceContext>(context_id, file_task_runner_, |
38 native_view_getter_), | 41 native_view_getter_), |
39 std::move(request)); | 42 std::move(request)); |
40 } | 43 } |
41 | 44 |
42 void WakeLockProvider::GetWakeLockWithoutContext( | 45 void WakeLockProvider::GetWakeLockWithoutContext( |
43 mojom::WakeLockType type, | 46 mojom::WakeLockType type, |
44 mojom::WakeLockReason reason, | 47 mojom::WakeLockReason reason, |
45 const std::string& description, | 48 const std::string& description, |
46 mojom::WakeLockServiceRequest request) { | 49 mojom::WakeLockServiceRequest request) { |
47 // WakeLockServiceImpl owns itself. | 50 if (is_in_service_unittest_) { |
48 new WakeLockServiceImpl(std::move(request), type, reason, description, | 51 // Create WakeLockServiceImplForTesting. |
49 WakeLockServiceContext::WakeLockInvalidContextId, | 52 new WakeLockServiceImplForTesting( |
50 native_view_getter_, file_task_runner_); | 53 std::move(request), type, reason, description, |
| 54 WakeLockServiceContext::WakeLockInvalidContextId, native_view_getter_, |
| 55 file_task_runner_); |
| 56 } else { |
| 57 // WakeLockServiceImpl owns itself. |
| 58 new WakeLockServiceImpl(std::move(request), type, reason, description, |
| 59 WakeLockServiceContext::WakeLockInvalidContextId, |
| 60 native_view_getter_, file_task_runner_); |
| 61 } |
51 } | 62 } |
52 | 63 |
53 } // namespace device | 64 } // namespace device |
OLD | NEW |