OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_CHROMEOS_POWER_RENDERER_FREEZER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POWER_RENDERER_FREEZER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_POWER_RENDERER_FREEZER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POWER_RENDERER_FREEZER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/files/file_path.h" | 9 #include "base/cancelable_callback.h" |
| 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "chromeos/chromeos_export.h" | 13 #include "chromeos/chromeos_export.h" |
13 #include "chromeos/dbus/power_manager_client.h" | 14 #include "chromeos/dbus/power_manager_client.h" |
14 | 15 |
15 namespace chromeos { | 16 namespace chromeos { |
16 | 17 |
17 // Freezes the chrome renderers when the system is about to suspend and thaws | 18 // Freezes the chrome renderers when the system is about to suspend and thaws |
18 // them after the system fully resumes. This class registers itself as a | 19 // them after the system fully resumes. This class registers itself as a |
19 // PowerManagerClient::Observer on creation and unregisters itself on | 20 // PowerManagerClient::Observer on creation and unregisters itself on |
20 // destruction. | 21 // destruction. |
21 class CHROMEOS_EXPORT RendererFreezer : public PowerManagerClient::Observer { | 22 class CHROMEOS_EXPORT RendererFreezer : public PowerManagerClient::Observer { |
22 public: | 23 public: |
23 RendererFreezer(); | 24 class Delegate { |
| 25 public: |
| 26 virtual ~Delegate() {} |
| 27 |
| 28 // Freezes the chrome renderers. Returns true if the operation was |
| 29 // successful. |
| 30 virtual bool FreezeRenderers() = 0; |
| 31 |
| 32 // Thaws the chrome renderers. Returns true if the operation was |
| 33 // successful. |
| 34 virtual bool ThawRenderers() = 0; |
| 35 |
| 36 // Returns true iff the delegate is capable of freezing renderers. |
| 37 virtual bool CanFreezeRenderers() = 0; |
| 38 }; |
| 39 |
| 40 explicit RendererFreezer(scoped_ptr<Delegate> delegate); |
24 virtual ~RendererFreezer(); | 41 virtual ~RendererFreezer(); |
25 | 42 |
26 // PowerManagerClient::Observer implementation | 43 // PowerManagerClient::Observer implementation |
27 virtual void SuspendImminent() OVERRIDE; | 44 virtual void SuspendImminent() OVERRIDE; |
28 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE; | 45 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE; |
29 | 46 |
30 private: | 47 private: |
31 void OnReadyToSuspend(); | 48 // Called when all asynchronous work is complete and renderers can be frozen. |
| 49 void OnReadyToSuspend(const base::Closure& power_manager_callback); |
32 | 50 |
33 base::FilePath state_path_; | 51 // Used to ensure that renderers do not get frozen if the suspend is canceled. |
34 bool enabled_; | 52 base::CancelableClosure suspend_readiness_callback_; |
| 53 |
35 bool frozen_; | 54 bool frozen_; |
36 | 55 |
37 // Callback used to asynchronously report suspend readiness. | 56 scoped_ptr<Delegate> delegate_; |
38 base::Closure suspend_readiness_callback_; | |
39 | 57 |
40 base::WeakPtrFactory<RendererFreezer> weak_factory_; | 58 base::WeakPtrFactory<RendererFreezer> weak_factory_; |
41 | 59 |
42 DISALLOW_COPY_AND_ASSIGN(RendererFreezer); | 60 DISALLOW_COPY_AND_ASSIGN(RendererFreezer); |
43 }; | 61 }; |
44 | 62 |
45 } // namespace chromeos | 63 } // namespace chromeos |
46 | 64 |
47 #endif // CHROME_BROWSER_CHROMEOS_POWER_RENDERER_FREEZER_H_ | 65 #endif // CHROME_BROWSER_CHROMEOS_POWER_RENDERER_FREEZER_H_ |
OLD | NEW |