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