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.
5 #include "content/browser/loader/power_save_block_resource_throttle.h"
7 #include "base/profiler/scoped_tracker.h"
8 #include "content/public/browser/power_save_blocker.h"
14 const int kPowerSaveBlockDelaySeconds
= 30;
18 PowerSaveBlockResourceThrottle::PowerSaveBlockResourceThrottle() {
21 PowerSaveBlockResourceThrottle::~PowerSaveBlockResourceThrottle() {
24 void PowerSaveBlockResourceThrottle::WillStartRequest(bool* defer
) {
25 // Delay PowerSaveBlocker activation to dismiss small requests.
26 timer_
.Start(FROM_HERE
,
27 base::TimeDelta::FromSeconds(kPowerSaveBlockDelaySeconds
),
29 &PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker
);
32 void PowerSaveBlockResourceThrottle::WillProcessResponse(bool* defer
) {
33 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
34 tracked_objects::ScopedTracker
tracking_profile(
35 FROM_HERE_WITH_EXPLICIT_FUNCTION(
36 "422516 PowerSaveBlockResourceThrottle::WillProcessResponse"));
38 // Stop blocking power save after request finishes.
39 power_save_blocker_
.reset();
43 const char* PowerSaveBlockResourceThrottle::GetNameForLogging() const {
44 return "PowerSaveBlockResourceThrottle";
47 void PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker() {
48 power_save_blocker_
= PowerSaveBlocker::Create(
49 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension
,
50 PowerSaveBlocker::kReasonOther
, "Uploading data");
53 } // namespace content