| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_LOADER_POWER_SAVE_BLOCK_RESOURCE_THROTTLE_H_ | |
| 6 #define CONTENT_BROWSER_LOADER_POWER_SAVE_BLOCK_RESOURCE_THROTTLE_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/sequenced_task_runner.h" | |
| 15 #include "base/single_thread_task_runner.h" | |
| 16 #include "base/timer/timer.h" | |
| 17 #include "content/public/browser/resource_throttle.h" | |
| 18 | |
| 19 namespace device { | |
| 20 class PowerSaveBlocker; | |
| 21 } // namespace device | |
| 22 | |
| 23 namespace content { | |
| 24 | |
| 25 // This ResourceThrottle blocks power save until large upload request finishes. | |
| 26 class PowerSaveBlockResourceThrottle : public ResourceThrottle { | |
| 27 public: | |
| 28 PowerSaveBlockResourceThrottle( | |
| 29 const std::string& host, | |
| 30 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | |
| 31 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner); | |
| 32 ~PowerSaveBlockResourceThrottle() override; | |
| 33 | |
| 34 // ResourceThrottle overrides: | |
| 35 void WillStartRequest(bool* defer) override; | |
| 36 void WillProcessResponse(bool* defer) override; | |
| 37 const char* GetNameForLogging() const override; | |
| 38 | |
| 39 private: | |
| 40 void ActivatePowerSaveBlocker(); | |
| 41 | |
| 42 const std::string host_; | |
| 43 base::OneShotTimer timer_; | |
| 44 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker_; | |
| 45 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | |
| 46 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner_; | |
| 47 | |
| 48 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlockResourceThrottle); | |
| 49 }; | |
| 50 | |
| 51 } // namespace content | |
| 52 | |
| 53 #endif // CONTENT_BROWSER_LOADER_POWER_SAVE_BLOCK_RESOURCE_THROTTLE_H_ | |
| OLD | NEW |