Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: content/browser/loader/power_save_block_resource_throttle.cc

Issue 12226005: Minimize PowerSaveBlocker usage during uploading data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use OneShotTimer Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/loader/power_save_block_resource_throttle.h" 5 #include "content/browser/loader/power_save_block_resource_throttle.h"
6 6
7 #include "content/public/browser/power_save_blocker.h" 7 #include "content/public/browser/power_save_blocker.h"
8 8
9 namespace content { 9 namespace content {
10 10
11 PowerSaveBlockResourceThrottle::PowerSaveBlockResourceThrottle( 11 namespace {
12 const std::string& reason) { 12
13 power_save_blocker_ = PowerSaveBlocker::Create( 13 const int kPowerSaveBlockDelaySeconds = 30;
14 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, reason); 14
15 } // namespace
16
17 PowerSaveBlockResourceThrottle::PowerSaveBlockResourceThrottle() {
15 } 18 }
16 19
17 PowerSaveBlockResourceThrottle::~PowerSaveBlockResourceThrottle() { 20 PowerSaveBlockResourceThrottle::~PowerSaveBlockResourceThrottle() {
18 } 21 }
19 22
23 void 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
20 void PowerSaveBlockResourceThrottle::WillProcessResponse(bool* defer) { 31 void PowerSaveBlockResourceThrottle::WillProcessResponse(bool* defer) {
21 // Stop blocking power save after request finishes. 32 // Stop blocking power save after request finishes.
22 power_save_blocker_.reset(); 33 power_save_blocker_.reset();
34 timer_.Stop();
35 }
36
37 void PowerSaveBlockResourceThrottle::ActivatePowerSaveBlocker() {
38 power_save_blocker_ = PowerSaveBlocker::Create(
39 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
40 "Uploading data.");
23 } 41 }
24 42
25 } // namespace content 43 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/power_save_block_resource_throttle.h ('k') | content/browser/loader/resource_dispatcher_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698