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

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

Issue 753313005: Revert of Re-land chromeos: Add non-extension renderers to the freezer cgroup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 <set>
9
10 #include "base/callback.h" 8 #include "base/callback.h"
11 #include "base/cancelable_callback.h" 9 #include "base/cancelable_callback.h"
12 #include "base/macros.h" 10 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
15 #include "base/process/kill.h"
16 #include "base/time/time.h" 13 #include "base/time/time.h"
17 #include "chromeos/chromeos_export.h" 14 #include "chromeos/chromeos_export.h"
18 #include "chromeos/dbus/power_manager_client.h" 15 #include "chromeos/dbus/power_manager_client.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "content/public/browser/render_process_host_observer.h"
22
23 namespace content {
24 class RenderProcessHost;
25 }
26 16
27 namespace chromeos { 17 namespace chromeos {
28 18
29 // 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
30 // 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
31 // PowerManagerClient::Observer on creation and unregisters itself on 21 // PowerManagerClient::Observer on creation and unregisters itself on
32 // destruction. 22 // destruction.
33 class CHROMEOS_EXPORT RendererFreezer 23 class CHROMEOS_EXPORT RendererFreezer : public PowerManagerClient::Observer {
34 : public PowerManagerClient::RenderProcessManagerDelegate,
35 public content::NotificationObserver,
36 public content::RenderProcessHostObserver {
37 public: 24 public:
38 class Delegate { 25 class Delegate {
39 public: 26 public:
40 virtual ~Delegate() {} 27 virtual ~Delegate() {}
41 28
42 // If |frozen| is true, marks the renderer process |handle| to be frozen 29 // Freezes the chrome renderers. Returns true if the operation was
43 // when FreezeRenderers() is called; otherwise marks it to remain unfrozen. 30 // successful.
44 virtual void SetShouldFreezeRenderer(base::ProcessHandle handle,
45 bool frozen) = 0;
46
47 // Freezes the renderers marked for freezing by SetShouldFreezeRenderer().
48 // Returns true if the operation was successful.
49 virtual bool FreezeRenderers() = 0; 31 virtual bool FreezeRenderers() = 0;
50 32
51 // Thaws the chrome renderers that were frozen by the call to 33 // Thaws the chrome renderers. Returns true if the operation was
52 // FreezeRenderers(). Returns true if the operation was successful. 34 // successful.
53 virtual bool ThawRenderers() = 0; 35 virtual bool ThawRenderers() = 0;
54 36
55 // Returns true iff the delegate is capable of freezing renderers. 37 // Returns true iff the delegate is capable of freezing renderers.
56 virtual bool CanFreezeRenderers() = 0; 38 virtual bool CanFreezeRenderers() = 0;
57 }; 39 };
58 40
59 explicit RendererFreezer(scoped_ptr<Delegate> delegate); 41 explicit RendererFreezer(scoped_ptr<Delegate> delegate);
60 ~RendererFreezer() override; 42 virtual ~RendererFreezer();
61 43
62 // PowerManagerClient::RenderProcessManagerDelegate implementation. 44 // PowerManagerClient::Observer implementation
63 void SuspendImminent() override; 45 virtual void SuspendImminent() override;
64 void SuspendDone() override; 46 virtual void SuspendDone(const base::TimeDelta& sleep_duration) override;
65
66 // content::NotificationObserver implementation.
67 void Observe(int type,
68 const content::NotificationSource& source,
69 const content::NotificationDetails& details) override;
70
71 // content::RenderProcessHostObserver overrides.
72 void RenderProcessExited(content::RenderProcessHost* host,
73 base::TerminationStatus status,
74 int exit_code) override;
75 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
76 47
77 private: 48 private:
78 // Called whenever a new renderer process is created. 49 // Called when all asynchronous work is complete and renderers can be frozen.
79 void OnRenderProcessCreated(content::RenderProcessHost* rph); 50 void OnReadyToSuspend(const base::Closure& power_manager_callback);
80 51
81 // Tracks if the renderers are currently frozen. 52 // Used to ensure that renderers do not get frozen if the suspend is canceled.
53 base::CancelableClosure suspend_readiness_callback_;
54
82 bool frozen_; 55 bool frozen_;
83 56
84 // Delegate that takes care of actually freezing and thawing renderers for us.
85 scoped_ptr<Delegate> delegate_; 57 scoped_ptr<Delegate> delegate_;
86 58
87 // Set that keeps track of the RenderProcessHosts for processes that are
88 // hosting GCM extensions.
89 std::set<int> gcm_extension_processes_;
90
91 // Manages notification registrations.
92 content::NotificationRegistrar registrar_;
93
94 base::WeakPtrFactory<RendererFreezer> weak_factory_; 59 base::WeakPtrFactory<RendererFreezer> weak_factory_;
95 60
96 DISALLOW_COPY_AND_ASSIGN(RendererFreezer); 61 DISALLOW_COPY_AND_ASSIGN(RendererFreezer);
97 }; 62 };
98 63
99 } // namespace chromeos 64 } // namespace chromeos
100 65
101 #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