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

Side by Side Diff: chrome/browser/background/background_contents_service.h

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

Powered by Google App Engine
This is Rietveld 408576698