OLD | NEW |
---|---|
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 "base/bind.h" | |
8 #include "base/memory/weak_ptr.h" | |
9 #include "base/message_loop.h" | |
7 #include "content/public/browser/power_save_blocker.h" | 10 #include "content/public/browser/power_save_blocker.h" |
8 | 11 |
9 namespace content { | 12 namespace content { |
10 | 13 |
11 PowerSaveBlockResourceThrottle::PowerSaveBlockResourceThrottle( | 14 namespace { |
12 const std::string& reason) { | 15 |
13 power_save_blocker_ = PowerSaveBlocker::Create( | 16 const int kPowerSaveBlockDelaySeconds = 30; |
14 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, reason); | 17 |
18 } // namespace | |
19 | |
20 class PowerSaveBlockResourceThrottle::PowerSaveBlockerOwner { | |
darin (slow to review)
2013/02/12 19:20:05
I don't understand why you bothered to create this
hashimoto
2013/02/13 08:02:35
I was trying to introduce more complicated mechani
| |
21 public: | |
22 PowerSaveBlockerOwner() | |
23 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
24 // Delay PowerSaveBlocker activation to dismiss small requests. | |
25 MessageLoop::current()->PostDelayedTask( | |
26 FROM_HERE, | |
27 base::Bind(&PowerSaveBlockerOwner::ActivatePowerSaveBlocker, | |
28 weak_ptr_factory_.GetWeakPtr()), | |
29 base::TimeDelta::FromSeconds(kPowerSaveBlockDelaySeconds)); | |
30 } | |
31 | |
32 ~PowerSaveBlockerOwner() {} | |
33 | |
34 void ActivatePowerSaveBlocker() { | |
35 power_save_blocker_ = PowerSaveBlocker::Create( | |
36 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | |
37 "Uploading data."); | |
38 } | |
39 | |
40 private: | |
41 scoped_ptr<PowerSaveBlocker> power_save_blocker_; | |
42 base::WeakPtrFactory<PowerSaveBlockerOwner> weak_ptr_factory_; | |
43 | |
44 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlockerOwner); | |
45 }; | |
46 | |
47 PowerSaveBlockResourceThrottle::PowerSaveBlockResourceThrottle() { | |
15 } | 48 } |
16 | 49 |
17 PowerSaveBlockResourceThrottle::~PowerSaveBlockResourceThrottle() { | 50 PowerSaveBlockResourceThrottle::~PowerSaveBlockResourceThrottle() { |
18 } | 51 } |
19 | 52 |
53 void PowerSaveBlockResourceThrottle::WillStartRequest(bool* defer) { | |
54 power_save_blocker_owner_.reset(new PowerSaveBlockerOwner()); | |
55 } | |
56 | |
20 void PowerSaveBlockResourceThrottle::WillProcessResponse(bool* defer) { | 57 void PowerSaveBlockResourceThrottle::WillProcessResponse(bool* defer) { |
21 // Stop blocking power save after request finishes. | 58 // Stop blocking power save after request finishes. |
22 power_save_blocker_.reset(); | 59 power_save_blocker_owner_.reset(); |
23 } | 60 } |
24 | 61 |
25 } // namespace content | 62 } // namespace content |
OLD | NEW |