| 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 namespace { | 11 namespace { |
| 12 | 12 |
| 13 const int kPowerSaveBlockDelaySeconds = 30; | 13 const int kPowerSaveBlockDelaySeconds = 30; |
| 14 | 14 |
| 15 } // namespace | 15 } // namespace |
| 16 | 16 |
| 17 PowerSaveBlockResourceThrottle::PowerSaveBlockResourceThrottle() { | 17 PowerSaveBlockResourceThrottle::PowerSaveBlockResourceThrottle( |
| 18 } | 18 const std::string& host) |
| 19 : host_(host) {} |
| 19 | 20 |
| 20 PowerSaveBlockResourceThrottle::~PowerSaveBlockResourceThrottle() { | 21 PowerSaveBlockResourceThrottle::~PowerSaveBlockResourceThrottle() { |
| 21 } | 22 } |
| 22 | 23 |
| 23 void PowerSaveBlockResourceThrottle::WillStartRequest(bool* defer) { | 24 void PowerSaveBlockResourceThrottle::WillStartRequest(bool* defer) { |
| 24 // Delay PowerSaveBlocker activation to dismiss small requests. | 25 // Delay PowerSaveBlocker activation to dismiss small requests. |
| 25 timer_.Start(FROM_HERE, | 26 timer_.Start(FROM_HERE, |
| 26 base::TimeDelta::FromSeconds(kPowerSaveBlockDelaySeconds), | 27 base::TimeDelta::FromSeconds(kPowerSaveBlockDelaySeconds), |
| 27 this, | 28 this, |
| 28 &PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker); | 29 &PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker); |
| 29 } | 30 } |
| 30 | 31 |
| 31 void PowerSaveBlockResourceThrottle::WillProcessResponse(bool* defer) { | 32 void PowerSaveBlockResourceThrottle::WillProcessResponse(bool* defer) { |
| 32 // Stop blocking power save after request finishes. | 33 // Stop blocking power save after request finishes. |
| 33 power_save_blocker_.reset(); | 34 power_save_blocker_.reset(); |
| 34 timer_.Stop(); | 35 timer_.Stop(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 const char* PowerSaveBlockResourceThrottle::GetNameForLogging() const { | 38 const char* PowerSaveBlockResourceThrottle::GetNameForLogging() const { |
| 38 return "PowerSaveBlockResourceThrottle"; | 39 return "PowerSaveBlockResourceThrottle"; |
| 39 } | 40 } |
| 40 | 41 |
| 41 void PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker() { | 42 void PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker() { |
| 42 power_save_blocker_ = PowerSaveBlocker::Create( | 43 power_save_blocker_ = PowerSaveBlocker::Create( |
| 43 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 44 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 44 PowerSaveBlocker::kReasonOther, "Uploading data"); | 45 PowerSaveBlocker::kReasonOther, "Uploading data to " + host_); |
| 45 } | 46 } |
| 46 | 47 |
| 47 } // namespace content | 48 } // namespace content |
| OLD | NEW |