OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ |
6 #define CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ | 6 #define CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <queue> |
| 10 #include <set> |
9 #include <string> | 11 #include <string> |
10 #include <vector> | 12 #include <vector> |
11 | 13 |
12 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
13 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/time/time.h" |
14 #include "chrome/browser/tab_contents/background_contents.h" | 17 #include "chrome/browser/tab_contents/background_contents.h" |
| 18 #include "chrome/common/extensions/extension.h" |
15 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 19 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
16 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
18 #include "content/public/common/window_container_type.h" | 22 #include "content/public/common/window_container_type.h" |
19 #include "ui/base/window_open_disposition.h" | 23 #include "ui/base/window_open_disposition.h" |
20 #include "url/gurl.h" | 24 #include "url/gurl.h" |
21 | 25 |
22 class CommandLine; | 26 class CommandLine; |
23 class PrefService; | 27 class PrefService; |
24 class Profile; | 28 class Profile; |
(...skipping 20 matching lines...) Expand all Loading... |
45 // It is also responsible for tracking the association between | 49 // It is also responsible for tracking the association between |
46 // BackgroundContents and their parent app, and shutting them down when the | 50 // BackgroundContents and their parent app, and shutting them down when the |
47 // parent app is unloaded. | 51 // parent app is unloaded. |
48 class BackgroundContentsService : private content::NotificationObserver, | 52 class BackgroundContentsService : private content::NotificationObserver, |
49 public BackgroundContents::Delegate, | 53 public BackgroundContents::Delegate, |
50 public BrowserContextKeyedService { | 54 public BrowserContextKeyedService { |
51 public: | 55 public: |
52 BackgroundContentsService(Profile* profile, const CommandLine* command_line); | 56 BackgroundContentsService(Profile* profile, const CommandLine* command_line); |
53 virtual ~BackgroundContentsService(); | 57 virtual ~BackgroundContentsService(); |
54 | 58 |
| 59 // Allows tests to reduce the time between a force-installed app/extension |
| 60 // crashing and when we reload it, and the amount of time we wait for further |
| 61 // crashes before showing a balloon saying the app/extension is misbehaving. |
| 62 static void SetCrashDelaysForForceInstalledAppsAndExtensionsForTesting( |
| 63 int restart_delay_in_ms, int crash_window_in_ms); |
| 64 |
55 // Returns the BackgroundContents associated with the passed application id, | 65 // Returns the BackgroundContents associated with the passed application id, |
56 // or NULL if none. | 66 // or NULL if none. |
57 BackgroundContents* GetAppBackgroundContents(const string16& appid); | 67 BackgroundContents* GetAppBackgroundContents(const string16& appid); |
58 | 68 |
59 // Returns true if there's a registered BackgroundContents for this app. It | 69 // Returns true if there's a registered BackgroundContents for this app. It |
60 // is possible for this routine to return true when GetAppBackgroundContents() | 70 // is possible for this routine to return true when GetAppBackgroundContents() |
61 // returns false, if the BackgroundContents closed due to the render process | 71 // returns false, if the BackgroundContents closed due to the render process |
62 // crashing. | 72 // crashing. |
63 bool HasRegisteredBackgroundContents(const string16& appid); | 73 bool HasRegisteredBackgroundContents(const string16& appid); |
64 | 74 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 KillBGContents); | 124 KillBGContents); |
115 | 125 |
116 // Registers for various notifications. | 126 // Registers for various notifications. |
117 void StartObserving(Profile* profile); | 127 void StartObserving(Profile* profile); |
118 | 128 |
119 // content::NotificationObserver implementation. | 129 // content::NotificationObserver implementation. |
120 virtual void Observe(int type, | 130 virtual void Observe(int type, |
121 const content::NotificationSource& source, | 131 const content::NotificationSource& source, |
122 const content::NotificationDetails& details) OVERRIDE; | 132 const content::NotificationDetails& details) OVERRIDE; |
123 | 133 |
| 134 // Restarts a force-installed app/extension after a crash. Notifies user if |
| 135 // crash recurs frequently. |
| 136 void RestartForceInstalledExtensionOnCrash( |
| 137 const extensions::Extension* extension, Profile* profile); |
| 138 |
124 // Loads all registered BackgroundContents at startup. | 139 // Loads all registered BackgroundContents at startup. |
125 void LoadBackgroundContentsFromPrefs(Profile* profile); | 140 void LoadBackgroundContentsFromPrefs(Profile* profile); |
126 | 141 |
127 // Load a BackgroundContent; the settings are read from the provided | 142 // Load a BackgroundContent; the settings are read from the provided |
128 // dictionary. | 143 // dictionary. |
129 void LoadBackgroundContentsFromDictionary( | 144 void LoadBackgroundContentsFromDictionary( |
130 Profile* profile, | 145 Profile* profile, |
131 const std::string& extension_id, | 146 const std::string& extension_id, |
132 const base::DictionaryValue* contents); | 147 const base::DictionaryValue* contents); |
133 | 148 |
(...skipping 29 matching lines...) Expand all Loading... |
163 void ShutdownAssociatedBackgroundContents(const string16& appid); | 178 void ShutdownAssociatedBackgroundContents(const string16& appid); |
164 | 179 |
165 // Returns true if this BackgroundContents is in the contents_list_. | 180 // Returns true if this BackgroundContents is in the contents_list_. |
166 bool IsTracked(BackgroundContents* contents) const; | 181 bool IsTracked(BackgroundContents* contents) const; |
167 | 182 |
168 // Sends out a notification when our association of background contents with | 183 // Sends out a notification when our association of background contents with |
169 // apps may have changed (used by BackgroundApplicationListModel to update the | 184 // apps may have changed (used by BackgroundApplicationListModel to update the |
170 // set of background apps as new background contents are opened/closed). | 185 // set of background apps as new background contents are opened/closed). |
171 void SendChangeNotification(Profile* profile); | 186 void SendChangeNotification(Profile* profile); |
172 | 187 |
| 188 // Delay (in ms) before restarting a force-installed extension that crashed. |
| 189 static int restart_delay_in_ms_; |
| 190 |
| 191 // When a force-installed app/extension crashes, we check if it's in a crash/ |
| 192 // reload loop by checking if the number of crashes exceeds a threshold in a |
| 193 // given time window. The duration of that window is given by: |
| 194 // kMisbehaveCrashCountThreshold * (restart_delay_in_ms + crash_window_in_ms) |
| 195 static int crash_window_in_ms_; |
| 196 |
173 // PrefService used to store list of background pages (or NULL if this is | 197 // PrefService used to store list of background pages (or NULL if this is |
174 // running under an incognito profile). | 198 // running under an incognito profile). |
175 PrefService* prefs_; | 199 PrefService* prefs_; |
176 content::NotificationRegistrar registrar_; | 200 content::NotificationRegistrar registrar_; |
177 | 201 |
178 // Information we track about each BackgroundContents. | 202 // Information we track about each BackgroundContents. |
179 struct BackgroundContentsInfo { | 203 struct BackgroundContentsInfo { |
180 // The BackgroundContents whose information we are tracking. | 204 // The BackgroundContents whose information we are tracking. |
181 BackgroundContents* contents; | 205 BackgroundContents* contents; |
182 // The name of the top level frame for this BackgroundContents. | 206 // The name of the top level frame for this BackgroundContents. |
183 string16 frame_name; | 207 string16 frame_name; |
184 }; | 208 }; |
185 | 209 |
186 // Map associating currently loaded BackgroundContents with their parent | 210 // Map associating currently loaded BackgroundContents with their parent |
187 // applications. | 211 // applications. |
188 // Key: application id | 212 // Key: application id |
189 // Value: BackgroundContentsInfo for the BC associated with that application | 213 // Value: BackgroundContentsInfo for the BC associated with that application |
190 typedef std::map<string16, BackgroundContentsInfo> BackgroundContentsMap; | 214 typedef std::map<string16, BackgroundContentsInfo> BackgroundContentsMap; |
191 BackgroundContentsMap contents_map_; | 215 BackgroundContentsMap contents_map_; |
192 | 216 |
| 217 // Map associating IDs of force-installed extensions/apps with their most |
| 218 // recent crash timestamps. |
| 219 // Key: app/extension id. |
| 220 // Value: queue containing up to 5 most recent crash timestamps. |
| 221 std::map<std::string, std::queue<base::TimeTicks> > extension_crashlog_map_; |
| 222 |
| 223 // Map containing ids of force-installed apps/extensions for which we have |
| 224 // already shown an 'App/Extension is misbehaving' balloon. |
| 225 std::set<std::string> misbehaving_extensions_; |
| 226 |
193 DISALLOW_COPY_AND_ASSIGN(BackgroundContentsService); | 227 DISALLOW_COPY_AND_ASSIGN(BackgroundContentsService); |
194 }; | 228 }; |
195 | 229 |
196 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ | 230 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ |
OLD | NEW |