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

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

Issue 823703004: Tracking push events for lucid sleep (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Kill renderer if it sends a bad message id Created 5 years, 10 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
(Empty)
1 // Copyright 2015 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 CHROME_BROWSER_CHROMEOS_POWER_EXTENSION_EVENT_OBSERVER_H_
6 #define CHROME_BROWSER_CHROMEOS_POWER_EXTENSION_EVENT_OBSERVER_H_
7
8 #include <set>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "base/cancelable_callback.h"
13 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/time/time.h"
18 #include "chromeos/dbus/power_manager_client.h"
19 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_source.h"
23 #include "extensions/browser/extension_host_observer.h"
24 #include "extensions/browser/process_manager_observer.h"
25
26 class Profile;
27
28 namespace extensions {
29 class ExtensionHost;
30 }
31
32 namespace chromeos {
33
34 // This class listens for extension events that should potentially keep the
35 // system awake while they are being processed. Examples include push messages
36 // that arrive from Google's GCM servers and network requests initiated by
37 // extensions while processing the push messages. This class is owned by
38 // WakeOnWifiManager.
39 class ExtensionEventObserver : public content::NotificationObserver,
40 public extensions::ProcessManagerObserver,
41 public extensions::ExtensionHostObserver,
42 public PowerManagerClient::Observer {
43 public:
44 class TestApi {
45 public:
46 ~TestApi();
47
48 // Runs |suspend_readiness_callback_| if it is non-null and then resets it.
49 // Returns true iff it actually ran the callback.
50 bool MaybeRunSuspendReadinessCallback();
51
52 // Returns true if the ExtensionEventObserver will delay suspend attempts
53 // for |host| if host has pending push messages or network requests.
54 bool WillDelaySuspendForExtensionHost(extensions::ExtensionHost* host);
55
56 private:
57 friend class ExtensionEventObserver;
58
59 explicit TestApi(base::WeakPtr<ExtensionEventObserver> parent);
60
61 base::WeakPtr<ExtensionEventObserver> parent_;
62
63 DISALLOW_COPY_AND_ASSIGN(TestApi);
64 };
65
66 ExtensionEventObserver();
67 ~ExtensionEventObserver() override;
68
69 scoped_ptr<TestApi> CreateTestApi();
70
71 // Called by the WakeOnWifiManager to control whether the
72 // ExtensionEventObserver should or should not delay the system suspend.
73 void SetShouldDelaySuspend(bool should_delay);
74
75 // content::NotificationObserver override.
76 void Observe(int type,
77 const content::NotificationSource& source,
78 const content::NotificationDetails& details) override;
79
80 // extensions::ProcessManagerObserver overrides.
81 void OnBackgroundHostCreated(extensions::ExtensionHost* host) override;
82
83 // extensions::ExtensionHostObserver overrides.
84 void OnExtensionHostDestroyed(const extensions::ExtensionHost* host) override;
85 void OnExtensionMessageDispatched(const extensions::ExtensionHost* host,
86 const std::string& event_name,
87 int message_id) override;
88 void OnExtensionMessageAcked(const extensions::ExtensionHost* host,
89 int message_id) override;
90 void OnNetworkRequestStarted(const extensions::ExtensionHost* host,
91 uint64 request_id) override;
92 void OnNetworkRequestDone(const extensions::ExtensionHost* host,
93 uint64 request_id) override;
94
95 // PowerManagerClient::Observer overrides.
96 void SuspendImminent() override;
97 void DarkSuspendImminent() override;
98 void SuspendDone(const base::TimeDelta& duration) override;
99
100 private:
101 friend class TestApi;
102
103 // Called when a new profile is created or destroyed.
104 void OnProfileAdded(Profile* profile);
105 void OnProfileDestroyed(Profile* profile);
106
107 // Called when the system is about to perform a regular suspend or a dark
108 // suspend.
109 void OnSuspendImminent(bool dark_suspend);
110
111 // Reports readiness to suspend to the PowerManagerClient if a suspend is
112 // pending and there are no outstanding events keeping the system awake.
113 void MaybeReportSuspendReadiness();
114
115 struct KeepaliveSources;
116 base::ScopedPtrHashMap<const extensions::ExtensionHost*, KeepaliveSources>
117 keepalive_sources_;
118
119 std::set<Profile*> active_profiles_;
120
121 bool should_delay_suspend_;
122 bool suspend_is_pending_;
123 int suspend_keepalive_count_;
124 base::Closure power_manager_callback_;
125 base::CancelableClosure suspend_readiness_callback_;
126
127 content::NotificationRegistrar registrar_;
128
129 base::WeakPtrFactory<ExtensionEventObserver> weak_factory_;
130
131 DISALLOW_COPY_AND_ASSIGN(ExtensionEventObserver);
132 };
133
134 } // namespace chromeos
135
136 #endif // CHROME_BROWSER_CHROMEOS_POWER_EXTENSION_EVENT_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698