| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/loader/power_save_block_resource_throttle.h" | |
| 6 | |
| 7 #include "device/power_save_blocker/power_save_blocker.h" | |
| 8 | |
| 9 namespace content { | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 const int kPowerSaveBlockDelaySeconds = 30; | |
| 14 | |
| 15 } // namespace | |
| 16 | |
| 17 PowerSaveBlockResourceThrottle::PowerSaveBlockResourceThrottle( | |
| 18 const std::string& host, | |
| 19 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | |
| 20 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner) | |
| 21 : host_(host), | |
| 22 ui_task_runner_(ui_task_runner), | |
| 23 blocking_task_runner_(blocking_task_runner) {} | |
| 24 | |
| 25 PowerSaveBlockResourceThrottle::~PowerSaveBlockResourceThrottle() { | |
| 26 } | |
| 27 | |
| 28 void PowerSaveBlockResourceThrottle::WillStartRequest(bool* defer) { | |
| 29 // Delay PowerSaveBlocker activation to dismiss small requests. | |
| 30 timer_.Start(FROM_HERE, | |
| 31 base::TimeDelta::FromSeconds(kPowerSaveBlockDelaySeconds), | |
| 32 this, | |
| 33 &PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker); | |
| 34 } | |
| 35 | |
| 36 void PowerSaveBlockResourceThrottle::WillProcessResponse(bool* defer) { | |
| 37 // Stop blocking power save after request finishes. | |
| 38 power_save_blocker_.reset(); | |
| 39 timer_.Stop(); | |
| 40 } | |
| 41 | |
| 42 const char* PowerSaveBlockResourceThrottle::GetNameForLogging() const { | |
| 43 return "PowerSaveBlockResourceThrottle"; | |
| 44 } | |
| 45 | |
| 46 void PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker() { | |
| 47 power_save_blocker_.reset(new device::PowerSaveBlocker( | |
| 48 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | |
| 49 device::PowerSaveBlocker::kReasonOther, "Uploading data to " + host_, | |
| 50 ui_task_runner_, blocking_task_runner_)); | |
| 51 } | |
| 52 | |
| 53 } // namespace content | |
| OLD | NEW |