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

Side by Side Diff: chrome/browser/chromeos/power/renderer_freezer.h

Issue 543303002: chromeos: power: Refactor RendererFreezer and add tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include base/macros.h Created 6 years, 3 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
OLDNEW
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/macros.h"
11 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
11 #include "base/time/time.h" 13 #include "base/time/time.h"
12 #include "chromeos/chromeos_export.h" 14 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/power_manager_client.h" 15 #include "chromeos/dbus/power_manager_client.h"
14 16
15 namespace chromeos { 17 namespace chromeos {
16 18
17 // Freezes the chrome renderers when the system is about to suspend and thaws 19 // 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 20 // them after the system fully resumes. This class registers itself as a
19 // PowerManagerClient::Observer on creation and unregisters itself on 21 // PowerManagerClient::Observer on creation and unregisters itself on
20 // destruction. 22 // destruction.
21 class CHROMEOS_EXPORT RendererFreezer : public PowerManagerClient::Observer { 23 class CHROMEOS_EXPORT RendererFreezer : public PowerManagerClient::Observer {
22 public: 24 public:
23 RendererFreezer(); 25 class Delegate {
26 public:
27 virtual ~Delegate() {}
28
29 // Freezes the chrome renderers. Returns true if the operation was
30 // successful.
31 virtual bool FreezeRenderers() = 0;
32
33 // Thaws the chrome renderers. Returns true if the operation was
34 // successful.
35 virtual bool ThawRenderers() = 0;
36
37 // Returns true iff the delegate is capable of freezing renderers.
38 virtual bool CanFreezeRenderers() = 0;
39 };
40
41 explicit RendererFreezer(scoped_ptr<Delegate> delegate);
24 virtual ~RendererFreezer(); 42 virtual ~RendererFreezer();
25 43
26 // PowerManagerClient::Observer implementation 44 // PowerManagerClient::Observer implementation
27 virtual void SuspendImminent() OVERRIDE; 45 virtual void SuspendImminent() OVERRIDE;
28 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE; 46 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE;
29 47
30 private: 48 private:
31 void OnReadyToSuspend(); 49 // Called when all asynchronous work is complete and renderers can be frozen.
50 void OnReadyToSuspend(const base::Closure& power_manager_callback);
32 51
33 base::FilePath state_path_; 52 // Used to ensure that renderers do not get frozen if the suspend is canceled.
34 bool enabled_; 53 base::CancelableClosure suspend_readiness_callback_;
54
35 bool frozen_; 55 bool frozen_;
36 56
37 // Callback used to asynchronously report suspend readiness. 57 scoped_ptr<Delegate> delegate_;
38 base::Closure suspend_readiness_callback_;
39 58
40 base::WeakPtrFactory<RendererFreezer> weak_factory_; 59 base::WeakPtrFactory<RendererFreezer> weak_factory_;
41 60
42 DISALLOW_COPY_AND_ASSIGN(RendererFreezer); 61 DISALLOW_COPY_AND_ASSIGN(RendererFreezer);
43 }; 62 };
44 63
45 } // namespace chromeos 64 } // namespace chromeos
46 65
47 #endif // CHROME_BROWSER_CHROMEOS_POWER_RENDERER_FREEZER_H_ 66 #endif // CHROME_BROWSER_CHROMEOS_POWER_RENDERER_FREEZER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/power/freezer_cgroup_process_manager.cc ('k') | chrome/browser/chromeos/power/renderer_freezer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698