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 "content/public/browser/power_save_blocker.h" 8 9 namespace content { 10 11 namespace { 12 13 const int kPowerSaveBlockDelaySeconds = 30; 14 15 } // namespace 16 PowerSaveBlockResourceThrottle()17PowerSaveBlockResourceThrottle::PowerSaveBlockResourceThrottle() { 18 } 19 ~PowerSaveBlockResourceThrottle()20PowerSaveBlockResourceThrottle::~PowerSaveBlockResourceThrottle() { 21 } 22 WillStartRequest(bool * defer)23void 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 WillProcessResponse(bool * defer)31void PowerSaveBlockResourceThrottle::WillProcessResponse(bool* defer) { 32 // Stop blocking power save after request finishes. 33 power_save_blocker_.reset(); 34 timer_.Stop(); 35 } 36 GetNameForLogging() const37const char* PowerSaveBlockResourceThrottle::GetNameForLogging() const { 38 return "PowerSaveBlockResourceThrottle"; 39 } 40 ActivatePowerSaveBlocker()41void PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker() { 42 power_save_blocker_ = PowerSaveBlocker::Create( 43 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 44 "Uploading data."); 45 } 46 47 } // namespace content 48