| 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 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 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 device::PowerSaveBlocker that just runs a callback on | 41 // Stub implementation of device::PowerSaveBlocker that just runs a callback on |
| 42 // destruction. | 42 // destruction. |
| 43 class PowerSaveBlockerStub : public device::PowerSaveBlocker { | 43 class PowerSaveBlockerStub : public device::PowerSaveBlocker { |
| 44 public: | 44 public: |
| 45 explicit PowerSaveBlockerStub(base::Closure unblock_callback) | 45 PowerSaveBlockerStub( |
| 46 : unblock_callback_(unblock_callback) { | 46 base::Closure unblock_callback, |
| 47 } | 47 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 48 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner) |
| 49 : PowerSaveBlocker(PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 50 PowerSaveBlocker::kReasonOther, |
| 51 "test", |
| 52 ui_task_runner, |
| 53 blocking_task_runner), |
| 54 unblock_callback_(unblock_callback) {} |
| 48 | 55 |
| 49 ~PowerSaveBlockerStub() override { unblock_callback_.Run(); } | 56 ~PowerSaveBlockerStub() override { unblock_callback_.Run(); } |
| 50 | 57 |
| 51 private: | 58 private: |
| 52 base::Closure unblock_callback_; | 59 base::Closure unblock_callback_; |
| 53 | 60 |
| 54 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlockerStub); | 61 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlockerStub); |
| 55 }; | 62 }; |
| 56 | 63 |
| 57 // Manages PowerSaveBlockerStub objects. Tests can instantiate this class | 64 // Manages PowerSaveBlockerStub objects. Tests can instantiate this class |
| (...skipping 28 matching lines...) Expand all Loading... |
| 86 return request; | 93 return request; |
| 87 } | 94 } |
| 88 | 95 |
| 89 private: | 96 private: |
| 90 // Creates a new PowerSaveBlockerStub of type |type|. | 97 // Creates a new PowerSaveBlockerStub of type |type|. |
| 91 std::unique_ptr<device::PowerSaveBlocker> CreateStub( | 98 std::unique_ptr<device::PowerSaveBlocker> CreateStub( |
| 92 device::PowerSaveBlocker::PowerSaveBlockerType type, | 99 device::PowerSaveBlocker::PowerSaveBlockerType type, |
| 93 device::PowerSaveBlocker::Reason reason, | 100 device::PowerSaveBlocker::Reason reason, |
| 94 const std::string& description, | 101 const std::string& description, |
| 95 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 102 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 96 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) { | 103 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner) { |
| 97 Request unblock_request = NONE; | 104 Request unblock_request = NONE; |
| 98 switch (type) { | 105 switch (type) { |
| 99 case device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension: | 106 case device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension: |
| 100 requests_.push_back(BLOCK_APP_SUSPENSION); | 107 requests_.push_back(BLOCK_APP_SUSPENSION); |
| 101 unblock_request = UNBLOCK_APP_SUSPENSION; | 108 unblock_request = UNBLOCK_APP_SUSPENSION; |
| 102 break; | 109 break; |
| 103 case device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep: | 110 case device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep: |
| 104 requests_.push_back(BLOCK_DISPLAY_SLEEP); | 111 requests_.push_back(BLOCK_DISPLAY_SLEEP); |
| 105 unblock_request = UNBLOCK_DISPLAY_SLEEP; | 112 unblock_request = UNBLOCK_DISPLAY_SLEEP; |
| 106 break; | 113 break; |
| 107 } | 114 } |
| 108 return std::unique_ptr<device::PowerSaveBlocker>(new PowerSaveBlockerStub( | 115 return std::unique_ptr<device::PowerSaveBlocker>(new PowerSaveBlockerStub( |
| 109 base::Bind(&PowerSaveBlockerStubManager::AppendRequest, | 116 base::Bind(&PowerSaveBlockerStubManager::AppendRequest, |
| 110 weak_ptr_factory_.GetWeakPtr(), unblock_request))); | 117 weak_ptr_factory_.GetWeakPtr(), unblock_request), |
| 118 ui_task_runner, blocking_task_runner)); |
| 111 } | 119 } |
| 112 | 120 |
| 113 void AppendRequest(Request request) { | 121 void AppendRequest(Request request) { |
| 114 requests_.push_back(request); | 122 requests_.push_back(request); |
| 115 } | 123 } |
| 116 | 124 |
| 117 content::BrowserContext* browser_context_; | 125 content::BrowserContext* browser_context_; |
| 118 | 126 |
| 119 // Requests in chronological order. | 127 // Requests in chronological order. |
| 120 std::deque<Request> requests_; | 128 std::deque<Request> requests_; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 EXPECT_EQ(NONE, manager_->PopFirstRequest()); | 277 EXPECT_EQ(NONE, manager_->PopFirstRequest()); |
| 270 | 278 |
| 271 // Make the first extension block display-sleep again. | 279 // Make the first extension block display-sleep again. |
| 272 ASSERT_TRUE(CallFunction(REQUEST, kDisplayArgs, extension())); | 280 ASSERT_TRUE(CallFunction(REQUEST, kDisplayArgs, extension())); |
| 273 EXPECT_EQ(BLOCK_DISPLAY_SLEEP, manager_->PopFirstRequest()); | 281 EXPECT_EQ(BLOCK_DISPLAY_SLEEP, manager_->PopFirstRequest()); |
| 274 EXPECT_EQ(UNBLOCK_APP_SUSPENSION, manager_->PopFirstRequest()); | 282 EXPECT_EQ(UNBLOCK_APP_SUSPENSION, manager_->PopFirstRequest()); |
| 275 EXPECT_EQ(NONE, manager_->PopFirstRequest()); | 283 EXPECT_EQ(NONE, manager_->PopFirstRequest()); |
| 276 } | 284 } |
| 277 | 285 |
| 278 } // namespace extensions | 286 } // namespace extensions |
| OLD | NEW |