OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/power/power_api.h" | 5 #include "extensions/browser/api/power/power_api.h" |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "content/public/browser/power_save_blocker.h" | 14 #include "device/power_save_blocker/power_save_blocker.h" |
15 #include "extensions/browser/api_test_utils.h" | 15 #include "extensions/browser/api_test_utils.h" |
16 #include "extensions/browser/api_unittest.h" | 16 #include "extensions/browser/api_unittest.h" |
17 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
18 #include "extensions/common/test_util.h" | 18 #include "extensions/common/test_util.h" |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Args commonly passed to PowerSaveBlockerStubManager::CallFunction(). | 24 // Args commonly passed to PowerSaveBlockerStubManager::CallFunction(). |
25 const char kDisplayArgs[] = "[\"display\"]"; | 25 const char kDisplayArgs[] = "[\"display\"]"; |
26 const char kSystemArgs[] = "[\"system\"]"; | 26 const char kSystemArgs[] = "[\"system\"]"; |
27 const char kEmptyArgs[] = "[]"; | 27 const char kEmptyArgs[] = "[]"; |
28 | 28 |
29 // Different actions that can be performed as a result of a | 29 // Different actions that can be performed as a result of a |
30 // PowerSaveBlocker being created or destroyed. | 30 // PowerSaveBlocker being created or destroyed. |
31 enum Request { | 31 enum Request { |
32 BLOCK_APP_SUSPENSION, | 32 BLOCK_APP_SUSPENSION, |
33 UNBLOCK_APP_SUSPENSION, | 33 UNBLOCK_APP_SUSPENSION, |
34 BLOCK_DISPLAY_SLEEP, | 34 BLOCK_DISPLAY_SLEEP, |
35 UNBLOCK_DISPLAY_SLEEP, | 35 UNBLOCK_DISPLAY_SLEEP, |
36 // Returned by PowerSaveBlockerStubManager::PopFirstRequest() when no | 36 // Returned by PowerSaveBlockerStubManager::PopFirstRequest() when no |
37 // requests are present. | 37 // requests are present. |
38 NONE, | 38 NONE, |
39 }; | 39 }; |
40 | 40 |
41 // Stub implementation of content::PowerSaveBlocker that just runs a | 41 // Stub implementation of device::PowerSaveBlocker that just runs a callback on |
42 // callback on destruction. | 42 // destruction. |
43 class PowerSaveBlockerStub : public content::PowerSaveBlocker { | 43 class PowerSaveBlockerStub : public device::PowerSaveBlocker { |
44 public: | 44 public: |
45 explicit PowerSaveBlockerStub(base::Closure unblock_callback) | 45 explicit PowerSaveBlockerStub(base::Closure unblock_callback) |
46 : unblock_callback_(unblock_callback) { | 46 : unblock_callback_(unblock_callback) { |
47 } | 47 } |
48 | 48 |
49 ~PowerSaveBlockerStub() override { unblock_callback_.Run(); } | 49 ~PowerSaveBlockerStub() override { unblock_callback_.Run(); } |
50 | 50 |
51 private: | 51 private: |
52 base::Closure unblock_callback_; | 52 base::Closure unblock_callback_; |
53 | 53 |
(...skipping 27 matching lines...) Expand all Loading... |
81 if (requests_.empty()) | 81 if (requests_.empty()) |
82 return NONE; | 82 return NONE; |
83 | 83 |
84 Request request = requests_.front(); | 84 Request request = requests_.front(); |
85 requests_.pop_front(); | 85 requests_.pop_front(); |
86 return request; | 86 return request; |
87 } | 87 } |
88 | 88 |
89 private: | 89 private: |
90 // Creates a new PowerSaveBlockerStub of type |type|. | 90 // Creates a new PowerSaveBlockerStub of type |type|. |
91 std::unique_ptr<content::PowerSaveBlocker> CreateStub( | 91 std::unique_ptr<device::PowerSaveBlocker> CreateStub( |
92 content::PowerSaveBlocker::PowerSaveBlockerType type, | 92 device::PowerSaveBlocker::PowerSaveBlockerType type, |
93 content::PowerSaveBlocker::Reason reason, | 93 device::PowerSaveBlocker::Reason reason, |
94 const std::string& description) { | 94 const std::string& description, |
| 95 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 96 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) { |
95 Request unblock_request = NONE; | 97 Request unblock_request = NONE; |
96 switch (type) { | 98 switch (type) { |
97 case content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension: | 99 case device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension: |
98 requests_.push_back(BLOCK_APP_SUSPENSION); | 100 requests_.push_back(BLOCK_APP_SUSPENSION); |
99 unblock_request = UNBLOCK_APP_SUSPENSION; | 101 unblock_request = UNBLOCK_APP_SUSPENSION; |
100 break; | 102 break; |
101 case content::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep: | 103 case device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep: |
102 requests_.push_back(BLOCK_DISPLAY_SLEEP); | 104 requests_.push_back(BLOCK_DISPLAY_SLEEP); |
103 unblock_request = UNBLOCK_DISPLAY_SLEEP; | 105 unblock_request = UNBLOCK_DISPLAY_SLEEP; |
104 break; | 106 break; |
105 } | 107 } |
106 return std::unique_ptr<content::PowerSaveBlocker>(new PowerSaveBlockerStub( | 108 return std::unique_ptr<device::PowerSaveBlocker>(new PowerSaveBlockerStub( |
107 base::Bind(&PowerSaveBlockerStubManager::AppendRequest, | 109 base::Bind(&PowerSaveBlockerStubManager::AppendRequest, |
108 weak_ptr_factory_.GetWeakPtr(), unblock_request))); | 110 weak_ptr_factory_.GetWeakPtr(), unblock_request))); |
109 } | 111 } |
110 | 112 |
111 void AppendRequest(Request request) { | 113 void AppendRequest(Request request) { |
112 requests_.push_back(request); | 114 requests_.push_back(request); |
113 } | 115 } |
114 | 116 |
115 content::BrowserContext* browser_context_; | 117 content::BrowserContext* browser_context_; |
116 | 118 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 EXPECT_EQ(NONE, manager_->PopFirstRequest()); | 269 EXPECT_EQ(NONE, manager_->PopFirstRequest()); |
268 | 270 |
269 // Make the first extension block display-sleep again. | 271 // Make the first extension block display-sleep again. |
270 ASSERT_TRUE(CallFunction(REQUEST, kDisplayArgs, extension())); | 272 ASSERT_TRUE(CallFunction(REQUEST, kDisplayArgs, extension())); |
271 EXPECT_EQ(BLOCK_DISPLAY_SLEEP, manager_->PopFirstRequest()); | 273 EXPECT_EQ(BLOCK_DISPLAY_SLEEP, manager_->PopFirstRequest()); |
272 EXPECT_EQ(UNBLOCK_APP_SUSPENSION, manager_->PopFirstRequest()); | 274 EXPECT_EQ(UNBLOCK_APP_SUSPENSION, manager_->PopFirstRequest()); |
273 EXPECT_EQ(NONE, manager_->PopFirstRequest()); | 275 EXPECT_EQ(NONE, manager_->PopFirstRequest()); |
274 } | 276 } |
275 | 277 |
276 } // namespace extensions | 278 } // namespace extensions |
OLD | NEW |