blob: 23f200286c3fb99c5100dcdc4baaf63b011d6221 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/loader/power_save_block_resource_throttle.h"
#include "base/profiler/scoped_tracker.h"
#include "content/public/browser/power_save_blocker.h"
namespace content {
namespace {
const int kPowerSaveBlockDelaySeconds = 30;
} // namespace
PowerSaveBlockResourceThrottle::PowerSaveBlockResourceThrottle() {
}
PowerSaveBlockResourceThrottle::~PowerSaveBlockResourceThrottle() {
}
void PowerSaveBlockResourceThrottle::WillStartRequest(bool* defer) {
// Delay PowerSaveBlocker activation to dismiss small requests.
timer_.Start(FROM_HERE,
base::TimeDelta::FromSeconds(kPowerSaveBlockDelaySeconds),
this,
&PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker);
}
void PowerSaveBlockResourceThrottle::WillProcessResponse(bool* defer) {
// TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
tracked_objects::ScopedTracker tracking_profile(
FROM_HERE_WITH_EXPLICIT_FUNCTION(
"422516 PowerSaveBlockResourceThrottle::WillProcessResponse"));
// Stop blocking power save after request finishes.
power_save_blocker_.reset();
timer_.Stop();
}
const char* PowerSaveBlockResourceThrottle::GetNameForLogging() const {
return "PowerSaveBlockResourceThrottle";
}
void PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker() {
power_save_blocker_ = PowerSaveBlocker::Create(
PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
PowerSaveBlocker::kReasonOther, "Uploading data");
}
} // namespace content
|