Roll src/third_party/WebKit 3a0ba1e:fcd7003 (svn 191141:191149)
[chromium-blink-merge.git] / content / browser / loader / power_save_block_resource_throttle.cc
blob23f200286c3fb99c5100dcdc4baaf63b011d6221
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"
10 namespace content {
12 namespace {
14 const int kPowerSaveBlockDelaySeconds = 30;
16 } // namespace
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),
28 this,
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();
40 timer_.Stop();
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