summaryrefslogtreecommitdiffstats
path: root/content/browser/loader/power_save_block_resource_throttle.cc
blob: 76afe12de1378718afa032c9722c45b8686d270f (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
// 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 "content/public/browser/power_save_blocker.h"

namespace content {

namespace {

const int kPowerSaveBlockDelaySeconds = 30;

}  // namespace

PowerSaveBlockResourceThrottle::PowerSaveBlockResourceThrottle(
    const std::string& host)
    : host_(host) {}

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) {
  // 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 to " + host_);
}

}  // namespace content