Chromium Code Reviews| 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> | |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "chrome/browser/tab_contents/background_contents.h" | 15 #include "chrome/browser/tab_contents/background_contents.h" |
| 15 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" | 16 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" |
| 16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/common/window_container_type.h" | 19 #include "content/public/common/window_container_type.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 45 // It is also responsible for tracking the association between | 46 // It is also responsible for tracking the association between |
| 46 // BackgroundContents and their parent app, and shutting them down when the | 47 // BackgroundContents and their parent app, and shutting them down when the |
| 47 // parent app is unloaded. | 48 // parent app is unloaded. |
| 48 class BackgroundContentsService : private content::NotificationObserver, | 49 class BackgroundContentsService : private content::NotificationObserver, |
| 49 public BackgroundContents::Delegate, | 50 public BackgroundContents::Delegate, |
| 50 public BrowserContextKeyedService { | 51 public BrowserContextKeyedService { |
| 51 public: | 52 public: |
| 52 BackgroundContentsService(Profile* profile, const CommandLine* command_line); | 53 BackgroundContentsService(Profile* profile, const CommandLine* command_line); |
| 53 virtual ~BackgroundContentsService(); | 54 virtual ~BackgroundContentsService(); |
| 54 | 55 |
| 56 static void SetCrashDelaysForTesting(const base::TimeDelta& restart_delay, | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit 1: Add comment that explain what this does.
N
anitawoodruff
2013/08/26 21:45:23
Done.
| |
| 57 const base::TimeDelta& crash_window); | |
| 58 | |
| 55 // Returns the BackgroundContents associated with the passed application id, | 59 // Returns the BackgroundContents associated with the passed application id, |
| 56 // or NULL if none. | 60 // or NULL if none. |
| 57 BackgroundContents* GetAppBackgroundContents(const string16& appid); | 61 BackgroundContents* GetAppBackgroundContents(const string16& appid); |
| 58 | 62 |
| 59 // Returns true if there's a registered BackgroundContents for this app. It | 63 // Returns true if there's a registered BackgroundContents for this app. It |
| 60 // is possible for this routine to return true when GetAppBackgroundContents() | 64 // is possible for this routine to return true when GetAppBackgroundContents() |
| 61 // returns false, if the BackgroundContents closed due to the render process | 65 // returns false, if the BackgroundContents closed due to the render process |
| 62 // crashing. | 66 // crashing. |
| 63 bool HasRegisteredBackgroundContents(const string16& appid); | 67 bool HasRegisteredBackgroundContents(const string16& appid); |
| 64 | 68 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 void ShutdownAssociatedBackgroundContents(const string16& appid); | 167 void ShutdownAssociatedBackgroundContents(const string16& appid); |
| 164 | 168 |
| 165 // Returns true if this BackgroundContents is in the contents_list_. | 169 // Returns true if this BackgroundContents is in the contents_list_. |
| 166 bool IsTracked(BackgroundContents* contents) const; | 170 bool IsTracked(BackgroundContents* contents) const; |
| 167 | 171 |
| 168 // Sends out a notification when our association of background contents with | 172 // Sends out a notification when our association of background contents with |
| 169 // apps may have changed (used by BackgroundApplicationListModel to update the | 173 // apps may have changed (used by BackgroundApplicationListModel to update the |
| 170 // set of background apps as new background contents are opened/closed). | 174 // set of background apps as new background contents are opened/closed). |
| 171 void SendChangeNotification(Profile* profile); | 175 void SendChangeNotification(Profile* profile); |
| 172 | 176 |
| 177 static base::TimeDelta restart_delay_; | |
|
bartfab (slow)
2013/08/26 13:26:53
Static initializers are not allowed in Chrome. You
anitawoodruff
2013/08/26 21:45:23
Done. Made them ints, and only convert to TimeDelt
bartfab (slow)
2013/08/27 09:21:29
For PODs, passing by reference is not necessary.
| |
| 178 static base::TimeDelta crash_window_; | |
| 179 | |
| 173 // PrefService used to store list of background pages (or NULL if this is | 180 // PrefService used to store list of background pages (or NULL if this is |
| 174 // running under an incognito profile). | 181 // running under an incognito profile). |
| 175 PrefService* prefs_; | 182 PrefService* prefs_; |
| 176 content::NotificationRegistrar registrar_; | 183 content::NotificationRegistrar registrar_; |
| 177 | 184 |
| 178 // Information we track about each BackgroundContents. | 185 // Information we track about each BackgroundContents. |
| 179 struct BackgroundContentsInfo { | 186 struct BackgroundContentsInfo { |
| 180 // The BackgroundContents whose information we are tracking. | 187 // The BackgroundContents whose information we are tracking. |
| 181 BackgroundContents* contents; | 188 BackgroundContents* contents; |
| 182 // The name of the top level frame for this BackgroundContents. | 189 // The name of the top level frame for this BackgroundContents. |
| 183 string16 frame_name; | 190 string16 frame_name; |
| 184 }; | 191 }; |
| 185 | 192 |
| 186 // Map associating currently loaded BackgroundContents with their parent | 193 // Map associating currently loaded BackgroundContents with their parent |
| 187 // applications. | 194 // applications. |
| 188 // Key: application id | 195 // Key: application id |
| 189 // Value: BackgroundContentsInfo for the BC associated with that application | 196 // Value: BackgroundContentsInfo for the BC associated with that application |
| 190 typedef std::map<string16, BackgroundContentsInfo> BackgroundContentsMap; | 197 typedef std::map<string16, BackgroundContentsInfo> BackgroundContentsMap; |
| 191 BackgroundContentsMap contents_map_; | 198 BackgroundContentsMap contents_map_; |
| 192 | 199 |
| 200 // Map associating extension IDs with their most recent crash timestamps. | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit: Add a note that this is used for force-instal
anitawoodruff
2013/08/26 21:45:23
Done.
| |
| 201 // Key: extension id. | |
| 202 // Value: queue containing up to 5 most recent crash timestamps. | |
| 203 std::map<std::string, std::queue<base::TimeTicks> > extension_crashlog_map_; | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit 1: #include <queue>
Nit 2: #include "base/time
anitawoodruff
2013/08/26 21:45:23
Done Nit 2. <queue> I'd already included on line 9
| |
| 204 | |
| 205 // Map containing ids of extensions for which we have already sent | |
| 206 // 'Extension is misbehaving' notifications. | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit 1: Instead of "sent notifications," better say
anitawoodruff
2013/08/26 21:45:23
Done.
I've changed the wording of comments to say
bartfab (slow)
2013/08/27 09:21:29
The variable naming is OK. Comments are for verbos
| |
| 207 std::set<std::string> misbehaving_extensions_; | |
|
bartfab (slow)
2013/08/26 13:26:53
Nit: #include <set>
anitawoodruff
2013/08/26 21:45:23
Done.
| |
| 208 | |
| 193 DISALLOW_COPY_AND_ASSIGN(BackgroundContentsService); | 209 DISALLOW_COPY_AND_ASSIGN(BackgroundContentsService); |
| 194 }; | 210 }; |
| 195 | 211 |
| 196 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ | 212 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_H_ |
| OLD | NEW |