OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/loader/power_save_block_resource_throttle.h" | 5 #include "content/browser/loader/power_save_block_resource_throttle.h" |
6 | 6 |
7 #include "content/public/browser/power_save_blocker.h" | 7 #include "content/public/browser/power_save_blocker.h" |
8 | 8 |
9 namespace content { | 9 namespace content { |
10 | 10 |
11 PowerSaveBlockResourceThrottle::PowerSaveBlockResourceThrottle( | 11 namespace { |
12 const std::string& reason) { | 12 |
13 power_save_blocker_ = PowerSaveBlocker::Create( | 13 const int kPowerSaveBlockDelaySeconds = 30; |
14 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, reason); | 14 |
| 15 } // namespace |
| 16 |
| 17 PowerSaveBlockResourceThrottle::PowerSaveBlockResourceThrottle() { |
15 } | 18 } |
16 | 19 |
17 PowerSaveBlockResourceThrottle::~PowerSaveBlockResourceThrottle() { | 20 PowerSaveBlockResourceThrottle::~PowerSaveBlockResourceThrottle() { |
18 } | 21 } |
19 | 22 |
| 23 void PowerSaveBlockResourceThrottle::WillStartRequest(bool* defer) { |
| 24 // Delay PowerSaveBlocker activation to dismiss small requests. |
| 25 timer_.Start(FROM_HERE, |
| 26 base::TimeDelta::FromSeconds(kPowerSaveBlockDelaySeconds), |
| 27 this, |
| 28 &PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker); |
| 29 } |
| 30 |
20 void PowerSaveBlockResourceThrottle::WillProcessResponse(bool* defer) { | 31 void PowerSaveBlockResourceThrottle::WillProcessResponse(bool* defer) { |
21 // Stop blocking power save after request finishes. | 32 // Stop blocking power save after request finishes. |
22 power_save_blocker_.reset(); | 33 power_save_blocker_.reset(); |
| 34 timer_.Stop(); |
| 35 } |
| 36 |
| 37 void PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker() { |
| 38 power_save_blocker_ = PowerSaveBlocker::Create( |
| 39 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 40 "Uploading data."); |
23 } | 41 } |
24 | 42 |
25 } // namespace content | 43 } // namespace content |
OLD | NEW |