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

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: Responding to Bartosz' review (take 2) 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/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
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 notification that the app is misbehaving.
anitawoodruff 2013/08/27 09:05:36 *'app/extension', not 'app'- will fix
anitawoodruff 2013/08/27 09:13:03 Done.
62 static void SetCrashDelaysForForceInstalledAppsAndExtensionsForTesting(
63 const int restart_delay_millis, const int crash_window_millis);
bartfab (slow) 2013/08/27 09:21:29 Nit: We tend to use "_in_ms" instead of "_millis".
anitawoodruff 2013/08/27 11:57:39 Done.
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 void ShutdownAssociatedBackgroundContents(const string16& appid); 173 void ShutdownAssociatedBackgroundContents(const string16& appid);
164 174
165 // Returns true if this BackgroundContents is in the contents_list_. 175 // Returns true if this BackgroundContents is in the contents_list_.
166 bool IsTracked(BackgroundContents* contents) const; 176 bool IsTracked(BackgroundContents* contents) const;
167 177
168 // Sends out a notification when our association of background contents with 178 // Sends out a notification when our association of background contents with
169 // apps may have changed (used by BackgroundApplicationListModel to update the 179 // apps may have changed (used by BackgroundApplicationListModel to update the
170 // set of background apps as new background contents are opened/closed). 180 // set of background apps as new background contents are opened/closed).
171 void SendChangeNotification(Profile* profile); 181 void SendChangeNotification(Profile* profile);
172 182
183 // Restarts a force-installed app/extension after a crash. Notifies user if
184 // crash recurs frequently.
185 void RestartForceInstalledExtensionOnCrash(
186 const extensions::Extension* extension, Profile* profile);
187
188 // Delay (in ms) before restarting a force-installed extension that crashed.
189 static int restart_delay_millis_;
190
191 // When a force-installed extension/app crashes, we check if it's in a crash/
bartfab (slow) 2013/08/27 09:21:29 Nit: Some comments say "app/extension," others say
anitawoodruff 2013/08/27 11:57:39 Done.
192 // reload loop by counting how many times it crashed in a given time window.
193 // The duration of that window is calculated by multiplying this value by
194 // the maximum number of crashes and adding on the restart delay * max number
195 // of crashes.
anitawoodruff 2013/08/27 09:05:36 This is the verbose description moved from the .cc
bartfab (slow) 2013/08/27 11:20:14 I think it is clear.
196 static int crash_window_millis_;
197
173 // PrefService used to store list of background pages (or NULL if this is 198 // PrefService used to store list of background pages (or NULL if this is
174 // running under an incognito profile). 199 // running under an incognito profile).
175 PrefService* prefs_; 200 PrefService* prefs_;
176 content::NotificationRegistrar registrar_; 201 content::NotificationRegistrar registrar_;
177 202
178 // Information we track about each BackgroundContents. 203 // Information we track about each BackgroundContents.
179 struct BackgroundContentsInfo { 204 struct BackgroundContentsInfo {
180 // The BackgroundContents whose information we are tracking. 205 // The BackgroundContents whose information we are tracking.
181 BackgroundContents* contents; 206 BackgroundContents* contents;
182 // The name of the top level frame for this BackgroundContents. 207 // The name of the top level frame for this BackgroundContents.
183 string16 frame_name; 208 string16 frame_name;
184 }; 209 };
185 210
186 // Map associating currently loaded BackgroundContents with their parent 211 // Map associating currently loaded BackgroundContents with their parent
187 // applications. 212 // applications.
188 // Key: application id 213 // Key: application id
189 // Value: BackgroundContentsInfo for the BC associated with that application 214 // Value: BackgroundContentsInfo for the BC associated with that application
190 typedef std::map<string16, BackgroundContentsInfo> BackgroundContentsMap; 215 typedef std::map<string16, BackgroundContentsInfo> BackgroundContentsMap;
191 BackgroundContentsMap contents_map_; 216 BackgroundContentsMap contents_map_;
192 217
218 // Map associating IDs of force-installed extensions/apps with their most
219 // recent crash timestamps.
220 // Key: extension/app id.
221 // Value: queue containing up to 5 most recent crash timestamps.
222 std::map<std::string, std::queue<base::TimeTicks> > extension_crashlog_map_;
223
224 // Map containing ids of force-installed apps/extensions for which we have
225 // already shown an 'App/Extension is misbehaving' balloon.
226 std::set<std::string> misbehaving_extensions_;
227
193 DISALLOW_COPY_AND_ASSIGN(BackgroundContentsService); 228 DISALLOW_COPY_AND_ASSIGN(BackgroundContentsService);
194 }; 229 };
195 230
196 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ 231 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698