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 #include "chrome/browser/background/background_contents_service.h" | 5 #include "chrome/browser/background/background_contents_service.h" |
| 6 | 6 |
| 7 #include "apps/app_load_service.h" | 7 #include "apps/app_load_service.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/background/background_contents_service_factory.h" | 16 #include "chrome/browser/background/background_contents_service_factory.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/extensions/extension_host.h" | 19 #include "chrome/browser/extensions/extension_host.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/browser/extensions/extension_system.h" | 21 #include "chrome/browser/extensions/extension_system.h" |
| 22 #include "chrome/browser/extensions/image_loader.h" | 22 #include "chrome/browser/extensions/image_loader.h" |
| 23 #include "chrome/browser/notifications/desktop_notification_service.h" | 23 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 24 #include "chrome/browser/notifications/notification.h" | 24 #include "chrome/browser/notifications/notification.h" |
| 25 #include "chrome/browser/notifications/notification_delegate.h" | |
| 25 #include "chrome/browser/notifications/notification_ui_manager.h" | 26 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 26 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 27 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/browser_finder.h" | 30 #include "chrome/browser/ui/browser_finder.h" |
| 30 #include "chrome/browser/ui/browser_tabstrip.h" | 31 #include "chrome/browser/ui/browser_tabstrip.h" |
| 31 #include "chrome/browser/ui/host_desktop.h" | 32 #include "chrome/browser/ui/host_desktop.h" |
| 32 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/extensions/background_info.h" | 34 #include "chrome/common/extensions/background_info.h" |
| 34 #include "chrome/common/extensions/extension.h" | 35 #include "chrome/common/extensions/extension.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 47 #include "ui/gfx/image/image.h" | 48 #include "ui/gfx/image/image.h" |
| 48 | 49 |
| 49 using content::SiteInstance; | 50 using content::SiteInstance; |
| 50 using content::WebContents; | 51 using content::WebContents; |
| 51 using extensions::BackgroundInfo; | 52 using extensions::BackgroundInfo; |
| 52 using extensions::Extension; | 53 using extensions::Extension; |
| 53 using extensions::UnloadedExtensionInfo; | 54 using extensions::UnloadedExtensionInfo; |
| 54 | 55 |
| 55 namespace { | 56 namespace { |
| 56 | 57 |
| 57 const char kNotificationPrefix[] = "app.background.crashed."; | 58 const char kCrashNotificationPrefix[] = "app.background.crashed."; |
| 59 const char kMisbehaveNotificationPrefix[] = "app.background.misbehaved."; | |
| 58 | 60 |
| 59 void CloseBalloon(const std::string& id) { | 61 // Number of recent crashes of a force-installed extensions/app that will |
|
bartfab (slow)
2013/08/27 15:37:44
Nit: s:extension/app:app/extension:
anitawoodruff
2013/08/27 17:34:29
Done.
| |
| 60 g_browser_process->notification_ui_manager()->CancelById(id); | 62 // trigger an 'App/Extension is misbehaving' balloon. |
| 63 const unsigned int kMisbehaveCrashCountThreshold = 5; | |
| 64 | |
| 65 void CloseBalloon(const std::string& balloon_id) { | |
| 66 g_browser_process->notification_ui_manager()-> | |
| 67 CancelById(balloon_id); | |
| 61 } | 68 } |
| 62 | 69 |
| 63 void ScheduleCloseBalloon(const std::string& extension_id) { | 70 // Closes the balloon with this id. |
| 71 void ScheduleCloseBalloon(const std::string& balloon_id) { | |
| 64 if (!base::MessageLoop::current()) // For unit_tests | 72 if (!base::MessageLoop::current()) // For unit_tests |
| 65 return; | 73 return; |
| 66 base::MessageLoop::current()->PostTask( | 74 base::MessageLoop::current()->PostTask( |
| 67 FROM_HERE, base::Bind(&CloseBalloon, kNotificationPrefix + extension_id)); | 75 FROM_HERE, base::Bind(&CloseBalloon, balloon_id)); |
| 68 } | 76 } |
| 69 | 77 |
| 78 // Closes the crash notification balloon for the app/extension with this id. | |
| 79 void ScheduleCloseCrashBalloon(const std::string& extension_id) { | |
| 80 ScheduleCloseBalloon(kCrashNotificationPrefix + extension_id); | |
| 81 } | |
| 82 | |
| 83 // Closes all notification balloons relating to the app/extension with this id. | |
| 84 void ScheduleCloseBalloons(const std::string& extension_id) { | |
| 85 ScheduleCloseBalloon(kMisbehaveNotificationPrefix + extension_id); | |
| 86 ScheduleCloseBalloon(kCrashNotificationPrefix + extension_id); | |
| 87 } | |
| 88 | |
| 89 // Delegate for the 'app/extension has crashed' popup balloon. Restarts the | |
| 90 // app/extension when the balloon is clicked. | |
| 70 class CrashNotificationDelegate : public NotificationDelegate { | 91 class CrashNotificationDelegate : public NotificationDelegate { |
| 71 public: | 92 public: |
| 72 CrashNotificationDelegate(Profile* profile, | 93 CrashNotificationDelegate(Profile* profile, |
| 73 const Extension* extension) | 94 const Extension* extension) |
| 74 : profile_(profile), | 95 : profile_(profile), |
| 75 is_hosted_app_(extension->is_hosted_app()), | 96 is_hosted_app_(extension->is_hosted_app()), |
| 76 is_platform_app_(extension->is_platform_app()), | 97 is_platform_app_(extension->is_platform_app()), |
| 77 extension_id_(extension->id()) { | 98 extension_id_(extension->id()) { |
| 78 } | 99 } |
| 79 | 100 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 100 service->LoadBackgroundContentsForExtension(profile_, | 121 service->LoadBackgroundContentsForExtension(profile_, |
| 101 copied_extension_id); | 122 copied_extension_id); |
| 102 } else if (is_platform_app_) { | 123 } else if (is_platform_app_) { |
| 103 apps::AppLoadService::Get(profile_)-> | 124 apps::AppLoadService::Get(profile_)-> |
| 104 RestartApplication(copied_extension_id); | 125 RestartApplication(copied_extension_id); |
| 105 } else { | 126 } else { |
| 106 extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 127 extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
| 107 ReloadExtension(copied_extension_id); | 128 ReloadExtension(copied_extension_id); |
| 108 } | 129 } |
| 109 | 130 |
| 110 // Closing the balloon here should be OK, but it causes a crash on Mac | 131 // Closing the 'app/extension has crashed' balloon here should be OK, but it |
| 111 // http://crbug.com/78167 | 132 // causes a crash on Mac (http://crbug.com/78167). |
| 112 ScheduleCloseBalloon(copied_extension_id); | 133 ScheduleCloseCrashBalloon(copied_extension_id); |
| 113 } | 134 } |
| 114 | 135 |
| 115 virtual bool HasClickedListener() OVERRIDE { return true; } | 136 virtual bool HasClickedListener() OVERRIDE { return true; } |
| 116 | 137 |
| 117 virtual std::string id() const OVERRIDE { | 138 virtual std::string id() const OVERRIDE { |
| 118 return kNotificationPrefix + extension_id_; | 139 return kCrashNotificationPrefix + extension_id_; |
| 119 } | 140 } |
| 120 | 141 |
| 121 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { | 142 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { |
| 122 return NULL; | 143 return NULL; |
| 123 } | 144 } |
| 124 | 145 |
| 125 private: | 146 private: |
| 126 virtual ~CrashNotificationDelegate() {} | 147 virtual ~CrashNotificationDelegate() {} |
| 127 | 148 |
| 128 Profile* profile_; | 149 Profile* profile_; |
| 129 bool is_hosted_app_; | 150 bool is_hosted_app_; |
| 130 bool is_platform_app_; | 151 bool is_platform_app_; |
| 131 std::string extension_id_; | 152 std::string extension_id_; |
| 132 | 153 |
| 133 DISALLOW_COPY_AND_ASSIGN(CrashNotificationDelegate); | 154 DISALLOW_COPY_AND_ASSIGN(CrashNotificationDelegate); |
| 134 }; | 155 }; |
| 135 | 156 |
| 157 // Empty delegate for the 'app/extension is misbehaving' popup balloon. which is | |
|
bartfab (slow)
2013/08/27 15:37:44
Nit: s/./,/
anitawoodruff
2013/08/27 17:34:29
Done.
| |
| 158 // triggered if a force-installed app/extension gets stuck in a crash/reload | |
| 159 // cycle. Doesn't do anything on click because force-installed apps/extensions | |
| 160 // get restarted automatically. | |
| 161 class MisbehaveNotificationDelegate : public NotificationDelegate { | |
| 162 public: | |
| 163 explicit MisbehaveNotificationDelegate(const Extension* extension) | |
| 164 : extension_id_(extension->id()) { | |
| 165 } | |
| 166 | |
| 167 virtual void Display() OVERRIDE {} | |
| 168 | |
| 169 virtual void Error() OVERRIDE {} | |
| 170 | |
| 171 virtual void Close(bool by_user) OVERRIDE {} | |
| 172 | |
| 173 virtual void Click() OVERRIDE {} | |
| 174 | |
| 175 virtual bool HasClickedListener() OVERRIDE { return true; } | |
| 176 | |
| 177 virtual std::string id() const OVERRIDE { | |
| 178 return kMisbehaveNotificationPrefix + extension_id_; | |
| 179 } | |
| 180 | |
| 181 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { | |
| 182 return NULL; | |
| 183 } | |
| 184 | |
| 185 private: | |
| 186 virtual ~MisbehaveNotificationDelegate() {} | |
| 187 | |
| 188 std::string extension_id_; | |
| 189 | |
| 190 DISALLOW_COPY_AND_ASSIGN(MisbehaveNotificationDelegate); | |
| 191 }; | |
| 192 | |
| 136 #if defined(ENABLE_NOTIFICATIONS) | 193 #if defined(ENABLE_NOTIFICATIONS) |
| 137 void NotificationImageReady( | 194 void NotificationImageReady( |
| 138 const std::string extension_name, | 195 const std::string extension_name, |
| 139 const string16 message, | 196 const string16 message, |
| 140 const GURL extension_url, | 197 const GURL extension_url, |
| 141 scoped_refptr<CrashNotificationDelegate> delegate, | 198 scoped_refptr<NotificationDelegate> delegate, |
| 142 Profile* profile, | 199 Profile* profile, |
| 143 const gfx::Image& icon) { | 200 const gfx::Image& icon) { |
| 144 gfx::Image notification_icon(icon); | 201 gfx::Image notification_icon(icon); |
| 145 if (icon.IsEmpty()) { | 202 if (icon.IsEmpty()) { |
| 146 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 203 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 147 notification_icon = rb.GetImageNamed(IDR_EXTENSION_DEFAULT_ICON); | 204 notification_icon = rb.GetImageNamed(IDR_EXTENSION_DEFAULT_ICON); |
| 148 } | 205 } |
| 149 string16 title; // no notification title | 206 string16 title; // no notification title |
| 150 DesktopNotificationService::AddIconNotification(extension_url, | 207 DesktopNotificationService::AddIconNotification(extension_url, |
| 151 title, | 208 title, |
| 152 message, | 209 message, |
| 153 notification_icon, | 210 notification_icon, |
| 154 string16(), | 211 string16(), |
| 155 delegate.get(), | 212 delegate.get(), |
| 156 profile); | 213 profile); |
| 157 } | 214 } |
| 158 #endif | 215 #endif |
| 159 | 216 |
| 160 void ShowBalloon(const Extension* extension, Profile* profile) { | 217 // Show a popup notification balloon with a crash message for a given app/ |
| 218 // extension. If |force_installed| is true we show an 'App/extension | |
| 219 // is misbehaving' message instead of a crash message. | |
| 220 void ShowBalloon(const Extension* extension, Profile* profile, | |
| 221 const bool force_installed) { | |
| 161 #if defined(ENABLE_NOTIFICATIONS) | 222 #if defined(ENABLE_NOTIFICATIONS) |
| 162 string16 message = l10n_util::GetStringFUTF16( | 223 string16 message; |
| 163 extension->is_app() ? IDS_BACKGROUND_CRASHED_APP_BALLOON_MESSAGE : | 224 scoped_refptr<NotificationDelegate> delegate; |
| 164 IDS_BACKGROUND_CRASHED_EXTENSION_BALLOON_MESSAGE, | 225 if (force_installed) { |
| 165 UTF8ToUTF16(extension->name())); | 226 message = l10n_util::GetStringFUTF16( |
| 166 | 227 extension->is_app() ? |
| 228 IDS_BACKGROUND_MISBEHAVING_APP_BALLOON_MESSAGE : | |
| 229 IDS_BACKGROUND_MISBEHAVING_EXTENSION_BALLOON_MESSAGE, | |
| 230 UTF8ToUTF16(extension->name())); | |
| 231 delegate = new MisbehaveNotificationDelegate(extension); | |
| 232 } else { | |
| 233 message = l10n_util::GetStringFUTF16( | |
| 234 extension->is_app() ? IDS_BACKGROUND_CRASHED_APP_BALLOON_MESSAGE : | |
| 235 IDS_BACKGROUND_CRASHED_EXTENSION_BALLOON_MESSAGE, | |
| 236 UTF8ToUTF16(extension->name())); | |
| 237 delegate = new CrashNotificationDelegate(profile, extension); | |
| 238 } | |
| 167 extension_misc::ExtensionIcons size(extension_misc::EXTENSION_ICON_MEDIUM); | 239 extension_misc::ExtensionIcons size(extension_misc::EXTENSION_ICON_MEDIUM); |
| 168 extensions::ExtensionResource resource = | 240 extensions::ExtensionResource resource = |
| 169 extensions::IconsInfo::GetIconResource( | 241 extensions::IconsInfo::GetIconResource( |
| 170 extension, size, ExtensionIconSet::MATCH_SMALLER); | 242 extension, size, ExtensionIconSet::MATCH_SMALLER); |
| 171 scoped_refptr<CrashNotificationDelegate> delegate = | |
| 172 new CrashNotificationDelegate(profile, extension); | |
| 173 // We can't just load the image in the Observe method below because, despite | 243 // We can't just load the image in the Observe method below because, despite |
| 174 // what this method is called, it may call the callback synchronously. | 244 // what this method is called, it may call the callback synchronously. |
| 175 // However, it's possible that the extension went away during the interim, | 245 // However, it's possible that the extension went away during the interim, |
| 176 // so we'll bind all the pertinent data here. | 246 // so we'll bind all the pertinent data here. |
| 177 extensions::ImageLoader::Get(profile)->LoadImageAsync( | 247 extensions::ImageLoader::Get(profile)->LoadImageAsync( |
| 178 extension, | 248 extension, |
| 179 resource, | 249 resource, |
| 180 gfx::Size(size, size), | 250 gfx::Size(size, size), |
| 181 base::Bind( | 251 base::Bind( |
| 182 &NotificationImageReady, | 252 &NotificationImageReady, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 198 // | 268 // |
| 199 // kRegisteredBackgroundContents: | 269 // kRegisteredBackgroundContents: |
| 200 // DictionaryValue { | 270 // DictionaryValue { |
| 201 // <appid_1>: { "url": <url1>, "name": <frame_name> }, | 271 // <appid_1>: { "url": <url1>, "name": <frame_name> }, |
| 202 // <appid_2>: { "url": <url2>, "name": <frame_name> }, | 272 // <appid_2>: { "url": <url2>, "name": <frame_name> }, |
| 203 // ... etc ... | 273 // ... etc ... |
| 204 // } | 274 // } |
| 205 const char kUrlKey[] = "url"; | 275 const char kUrlKey[] = "url"; |
| 206 const char kFrameNameKey[] = "name"; | 276 const char kFrameNameKey[] = "name"; |
| 207 | 277 |
| 278 int BackgroundContentsService::restart_delay_millis_ = 3000; // 3 seconds. | |
|
bartfab (slow)
2013/08/27 15:37:44
Nit: s/millis/in_ms/
anitawoodruff
2013/08/27 17:34:29
Done.
| |
| 279 int BackgroundContentsService::crash_window_millis_ = 1000; // 1 second. | |
|
bartfab (slow)
2013/08/27 15:37:44
Nit: s/millis/in_ms/
anitawoodruff
2013/08/27 17:34:29
Done.
| |
| 280 | |
| 208 BackgroundContentsService::BackgroundContentsService( | 281 BackgroundContentsService::BackgroundContentsService( |
| 209 Profile* profile, const CommandLine* command_line) | 282 Profile* profile, const CommandLine* command_line) |
| 210 : prefs_(NULL) { | 283 : prefs_(NULL), weak_factory_(this) { |
| 211 // Don't load/store preferences if the proper switch is not enabled, or if | 284 // Don't load/store preferences if the proper switch is not enabled, or if |
| 212 // the parent profile is incognito. | 285 // the parent profile is incognito. |
| 213 if (!profile->IsOffTheRecord() && | 286 if (!profile->IsOffTheRecord() && |
| 214 !command_line->HasSwitch(switches::kDisableRestoreBackgroundContents)) | 287 !command_line->HasSwitch(switches::kDisableRestoreBackgroundContents)) |
| 215 prefs_ = profile->GetPrefs(); | 288 prefs_ = profile->GetPrefs(); |
| 216 | 289 |
| 217 // Listen for events to tell us when to load/unload persisted background | 290 // Listen for events to tell us when to load/unload persisted background |
| 218 // contents. | 291 // contents. |
| 219 StartObserving(profile); | 292 StartObserving(profile); |
| 220 } | 293 } |
| 221 | 294 |
| 222 BackgroundContentsService::~BackgroundContentsService() { | 295 BackgroundContentsService::~BackgroundContentsService() { |
| 223 // BackgroundContents should be shutdown before we go away, as otherwise | 296 // BackgroundContents should be shutdown before we go away, as otherwise |
| 224 // our browser process refcount will be off. | 297 // our browser process refcount will be off. |
| 225 DCHECK(contents_map_.empty()); | 298 DCHECK(contents_map_.empty()); |
| 226 } | 299 } |
| 227 | 300 |
| 301 // static | |
| 302 void BackgroundContentsService:: | |
| 303 SetCrashDelaysForForceInstalledAppsAndExtensionsForTesting( | |
| 304 const int restart_delay_in_ms, | |
| 305 const int crash_window_in_ms) { | |
| 306 restart_delay_millis_ = restart_delay_in_ms; | |
| 307 crash_window_millis_ = crash_window_in_ms; | |
| 308 } | |
| 309 | |
| 228 std::vector<BackgroundContents*> | 310 std::vector<BackgroundContents*> |
| 229 BackgroundContentsService::GetBackgroundContents() const | 311 BackgroundContentsService::GetBackgroundContents() const |
| 230 { | 312 { |
| 231 std::vector<BackgroundContents*> contents; | 313 std::vector<BackgroundContents*> contents; |
| 232 for (BackgroundContentsMap::const_iterator it = contents_map_.begin(); | 314 for (BackgroundContentsMap::const_iterator it = contents_map_.begin(); |
| 233 it != contents_map_.end(); ++it) | 315 it != contents_map_.end(); ++it) |
| 234 contents.push_back(it->second.contents); | 316 contents.push_back(it->second.contents); |
| 235 return contents; | 317 return contents; |
| 236 } | 318 } |
| 237 | 319 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 if (service && service->is_ready()) { | 424 if (service && service->is_ready()) { |
| 343 // Now load the manifest-specified background page. If service isn't | 425 // Now load the manifest-specified background page. If service isn't |
| 344 // ready, then the background page will be loaded from the | 426 // ready, then the background page will be loaded from the |
| 345 // EXTENSIONS_READY callback. | 427 // EXTENSIONS_READY callback. |
| 346 LoadBackgroundContents(profile, | 428 LoadBackgroundContents(profile, |
| 347 BackgroundInfo::GetBackgroundURL(extension), | 429 BackgroundInfo::GetBackgroundURL(extension), |
| 348 ASCIIToUTF16("background"), | 430 ASCIIToUTF16("background"), |
| 349 UTF8ToUTF16(extension->id())); | 431 UTF8ToUTF16(extension->id())); |
| 350 } | 432 } |
| 351 } | 433 } |
| 352 | |
|
bartfab (slow)
2013/08/27 15:37:44
Nit: Any reason to remove this line?
anitawoodruff
2013/08/27 17:34:29
Replaced.
| |
| 353 // Remove any "This extension has crashed" balloons. | 434 // Remove any "This extension has crashed" balloons. |
| 354 ScheduleCloseBalloon(extension->id()); | 435 ScheduleCloseCrashBalloon(extension->id()); |
| 355 SendChangeNotification(profile); | 436 SendChangeNotification(profile); |
| 356 break; | 437 break; |
| 357 } | 438 } |
| 358 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: | 439 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: |
| 359 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED: { | 440 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED: { |
| 360 Profile* profile = content::Source<Profile>(source).ptr(); | 441 Profile* profile = content::Source<Profile>(source).ptr(); |
| 361 const Extension* extension = NULL; | 442 const Extension* extension = NULL; |
| 362 if (type == chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED) { | 443 if (type == chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED) { |
| 363 BackgroundContents* bg = | 444 BackgroundContents* bg = |
| 364 content::Details<BackgroundContents>(details).ptr(); | 445 content::Details<BackgroundContents>(details).ptr(); |
| 365 std::string extension_id = UTF16ToASCII( | 446 std::string extension_id = UTF16ToASCII( |
| 366 BackgroundContentsServiceFactory::GetForProfile(profile)-> | 447 BackgroundContentsServiceFactory::GetForProfile(profile)-> |
| 367 GetParentApplicationId(bg)); | 448 GetParentApplicationId(bg)); |
| 368 extension = | 449 extension = |
| 369 extensions::ExtensionSystem::Get(profile)->extension_service()-> | 450 extensions::ExtensionSystem::Get(profile)->extension_service()-> |
| 370 GetExtensionById(extension_id, false); | 451 GetExtensionById(extension_id, false); |
| 371 } else { | 452 } else { |
| 372 extensions::ExtensionHost* extension_host = | 453 extensions::ExtensionHost* extension_host = |
| 373 content::Details<extensions::ExtensionHost>(details).ptr(); | 454 content::Details<extensions::ExtensionHost>(details).ptr(); |
| 374 extension = extension_host->extension(); | 455 extension = extension_host->extension(); |
| 375 } | 456 } |
| 376 if (!extension) | 457 if (!extension) |
| 377 break; | 458 break; |
| 378 | 459 |
| 379 // When an extension crashes, EXTENSION_PROCESS_TERMINATED is followed by | 460 // When an extension crashes, EXTENSION_PROCESS_TERMINATED is followed by |
| 380 // an EXTENSION_UNLOADED notification. This UNLOADED signal causes all the | 461 // an EXTENSION_UNLOADED notification. This UNLOADED signal causes all the |
| 381 // notifications for this extension to be cancelled by | 462 // notifications for this extension to be cancelled by |
| 382 // DesktopNotificationService. For this reason, instead of showing the | 463 // DesktopNotificationService. For this reason, we post the crash handling |
| 383 // balloon right now, we schedule it to show a little later. | 464 // code as a task here so that it is not executed before this event. |
|
bartfab (slow)
2013/08/27 15:37:44
Actually, this comment applies to the !force_insta
anitawoodruff
2013/08/27 17:34:29
Done.
| |
| 384 base::MessageLoop::current()->PostTask( | 465 const bool force_installed = extension->location() == |
| 385 FROM_HERE, base::Bind(&ShowBalloon, extension, profile)); | 466 extensions::Manifest::EXTERNAL_POLICY_DOWNLOAD; |
| 467 if (!force_installed) { | |
| 468 // Notify user extension has crashed. | |
| 469 base::MessageLoop::current()->PostTask( | |
| 470 FROM_HERE, base::Bind(&ShowBalloon, extension, profile, false)); | |
| 471 } else { | |
| 472 // Restart the extension; notify user if crash recurs frequently. | |
| 473 RestartForceInstalledExtensionOnCrash(extension, profile); | |
| 474 } | |
| 386 break; | 475 break; |
| 387 } | 476 } |
| 388 case chrome::NOTIFICATION_EXTENSION_UNLOADED: | 477 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| 389 switch (content::Details<UnloadedExtensionInfo>(details)->reason) { | 478 switch (content::Details<UnloadedExtensionInfo>(details)->reason) { |
| 390 case extension_misc::UNLOAD_REASON_DISABLE: // Fall through. | 479 case extension_misc::UNLOAD_REASON_DISABLE: // Fall through. |
| 391 case extension_misc::UNLOAD_REASON_TERMINATE: // Fall through. | 480 case extension_misc::UNLOAD_REASON_TERMINATE: // Fall through. |
| 392 case extension_misc::UNLOAD_REASON_UNINSTALL: // Fall through. | 481 case extension_misc::UNLOAD_REASON_UNINSTALL: // Fall through. |
| 393 case extension_misc::UNLOAD_REASON_BLACKLIST: | 482 case extension_misc::UNLOAD_REASON_BLACKLIST: |
| 394 ShutdownAssociatedBackgroundContents( | 483 ShutdownAssociatedBackgroundContents( |
| 395 ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)-> | 484 ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)-> |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 412 default: | 501 default: |
| 413 NOTREACHED(); | 502 NOTREACHED(); |
| 414 ShutdownAssociatedBackgroundContents( | 503 ShutdownAssociatedBackgroundContents( |
| 415 ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)-> | 504 ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)-> |
| 416 extension->id())); | 505 extension->id())); |
| 417 break; | 506 break; |
| 418 } | 507 } |
| 419 break; | 508 break; |
| 420 | 509 |
| 421 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { | 510 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
| 511 const std::string& extension_id = | |
| 512 content::Details<const Extension>(details).ptr()->id(); | |
| 422 // Remove any "This extension has crashed" balloons. | 513 // Remove any "This extension has crashed" balloons. |
|
bartfab (slow)
2013/08/27 15:37:44
Nit: Update comment.
anitawoodruff
2013/08/27 17:34:29
Done.
| |
| 423 ScheduleCloseBalloon( | 514 ScheduleCloseBalloons(extension_id); |
| 424 content::Details<const Extension>(details).ptr()->id()); | 515 misbehaving_extensions_.erase(extension_id); |
| 516 extension_crashlog_map_.erase(extension_id); | |
| 425 break; | 517 break; |
| 426 } | 518 } |
| 427 | 519 |
| 428 default: | 520 default: |
| 429 NOTREACHED(); | 521 NOTREACHED(); |
| 430 break; | 522 break; |
| 431 } | 523 } |
| 432 } | 524 } |
| 433 | 525 |
| 526 void BackgroundContentsService::RestartForceInstalledExtensionOnCrash( | |
|
bartfab (slow)
2013/08/27 15:37:44
The method order in the .cc file does not seem to
anitawoodruff
2013/08/27 17:34:29
Done.
| |
| 527 const Extension* extension, Profile* profile) { | |
| 528 const std::string& extension_id = extension->id(); | |
| 529 const bool alreadyNotified = misbehaving_extensions_.find(extension_id) != | |
|
bartfab (slow)
2013/08/27 15:37:44
s/alreadyNotified/already_notified/
anitawoodruff
2013/08/27 17:34:29
Done.
| |
| 530 misbehaving_extensions_.end(); | |
| 531 std::queue<base::TimeTicks>& crashes = extension_crashlog_map_[extension_id]; | |
| 532 const base::TimeDelta duration = | |
|
bartfab (slow)
2013/08/27 15:37:44
Nit: |duration| is fairly generic. How about |cras
anitawoodruff
2013/08/27 17:34:29
Changed to 'recent_time_window'.
| |
| 533 base::TimeDelta::FromMilliseconds(kMisbehaveCrashCountThreshold * | |
| 534 (restart_delay_millis_ + crash_window_millis_)); | |
| 535 if (!alreadyNotified) { | |
| 536 // Show a notification if the threshold number of crashes has occurred withi n | |
| 537 // a given duration. | |
| 538 const bool shouldNotify = | |
|
bartfab (slow)
2013/08/27 15:37:44
s/shouldNotify/should_notify/
anitawoodruff
2013/08/27 17:34:29
Done.
| |
| 539 crashes.size() == kMisbehaveCrashCountThreshold - 1 && | |
| 540 base::TimeTicks::Now() - crashes.front() < duration; | |
| 541 if (shouldNotify) { | |
| 542 base::MessageLoop::current()->PostTask(FROM_HERE, | |
| 543 base::Bind(&ShowBalloon, extension, profile, true)); | |
| 544 misbehaving_extensions_.insert(extension_id); | |
| 545 extension_crashlog_map_.erase(extension_id); | |
| 546 } else { | |
| 547 while (!crashes.empty() && | |
| 548 base::TimeTicks::Now() - crashes.front() > duration) { | |
| 549 crashes.pop(); // Remove old timestamps. | |
|
bartfab (slow)
2013/08/27 15:37:44
Nit: Put the comment above the source line.
anitawoodruff
2013/08/27 17:34:29
Done.
| |
| 550 } | |
| 551 crashes.push(base::TimeTicks::Now()); | |
| 552 if (crashes.size() == kMisbehaveCrashCountThreshold) | |
| 553 crashes.pop(); | |
| 554 } | |
| 555 } | |
| 556 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
| 557 base::Bind(&BackgroundContentsService::ReloadExtension, | |
| 558 weak_factory_.GetWeakPtr(), extension_id, profile), | |
| 559 base::TimeDelta::FromMilliseconds(restart_delay_millis_)); | |
| 560 } | |
| 561 | |
| 562 void BackgroundContentsService::ReloadExtension( | |
| 563 const std::string extension_id, Profile* profile) { | |
| 564 extensions::ExtensionSystem* extensionSystem = | |
| 565 extensions::ExtensionSystem::Get(profile); | |
| 566 if (!extensionSystem || !extensionSystem->extension_service()) | |
| 567 return; | |
| 568 if (!extensionSystem->extension_service()-> | |
| 569 GetExtensionById(extension_id, false)) { | |
| 570 // Force-installed app/extension has been removed by policy. | |
|
bartfab (slow)
2013/08/27 15:37:44
Maybe better:
Policy has changed. The app/extensi
anitawoodruff
2013/08/27 17:34:29
Done.
| |
| 571 return; | |
| 572 } | |
| 573 extensionSystem->extension_service()->ReloadExtension(extension_id); | |
| 574 } | |
| 575 | |
| 434 // Loads all background contents whose urls have been stored in prefs. | 576 // Loads all background contents whose urls have been stored in prefs. |
| 435 void BackgroundContentsService::LoadBackgroundContentsFromPrefs( | 577 void BackgroundContentsService::LoadBackgroundContentsFromPrefs( |
| 436 Profile* profile) { | 578 Profile* profile) { |
| 437 if (!prefs_) | 579 if (!prefs_) |
| 438 return; | 580 return; |
| 439 const DictionaryValue* contents = | 581 const DictionaryValue* contents = |
| 440 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); | 582 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); |
| 441 if (!contents) | 583 if (!contents) |
| 442 return; | 584 return; |
| 443 ExtensionService* extensions_service = | 585 ExtensionService* extensions_service = |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 } | 788 } |
| 647 | 789 |
| 648 void BackgroundContentsService::BackgroundContentsOpened( | 790 void BackgroundContentsService::BackgroundContentsOpened( |
| 649 BackgroundContentsOpenedDetails* details) { | 791 BackgroundContentsOpenedDetails* details) { |
| 650 // Add the passed object to our list. Should not already be tracked. | 792 // Add the passed object to our list. Should not already be tracked. |
| 651 DCHECK(!IsTracked(details->contents)); | 793 DCHECK(!IsTracked(details->contents)); |
| 652 DCHECK(!details->application_id.empty()); | 794 DCHECK(!details->application_id.empty()); |
| 653 contents_map_[details->application_id].contents = details->contents; | 795 contents_map_[details->application_id].contents = details->contents; |
| 654 contents_map_[details->application_id].frame_name = details->frame_name; | 796 contents_map_[details->application_id].frame_name = details->frame_name; |
| 655 | 797 |
| 656 ScheduleCloseBalloon(UTF16ToASCII(details->application_id)); | 798 ScheduleCloseCrashBalloon(UTF16ToASCII(details->application_id)); |
| 657 } | 799 } |
| 658 | 800 |
| 659 // Used by test code and debug checks to verify whether a given | 801 // Used by test code and debug checks to verify whether a given |
| 660 // BackgroundContents is being tracked by this instance. | 802 // BackgroundContents is being tracked by this instance. |
| 661 bool BackgroundContentsService::IsTracked( | 803 bool BackgroundContentsService::IsTracked( |
| 662 BackgroundContents* background_contents) const { | 804 BackgroundContents* background_contents) const { |
| 663 return !GetParentApplicationId(background_contents).empty(); | 805 return !GetParentApplicationId(background_contents).empty(); |
| 664 } | 806 } |
| 665 | 807 |
| 666 void BackgroundContentsService::BackgroundContentsShutdown( | 808 void BackgroundContentsService::BackgroundContentsShutdown( |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 694 bool user_gesture, | 836 bool user_gesture, |
| 695 bool* was_blocked) { | 837 bool* was_blocked) { |
| 696 Browser* browser = chrome::FindLastActiveWithProfile( | 838 Browser* browser = chrome::FindLastActiveWithProfile( |
| 697 Profile::FromBrowserContext(new_contents->GetBrowserContext()), | 839 Profile::FromBrowserContext(new_contents->GetBrowserContext()), |
| 698 chrome::GetActiveDesktop()); | 840 chrome::GetActiveDesktop()); |
| 699 if (browser) { | 841 if (browser) { |
| 700 chrome::AddWebContents(browser, NULL, new_contents, disposition, | 842 chrome::AddWebContents(browser, NULL, new_contents, disposition, |
| 701 initial_pos, user_gesture, was_blocked); | 843 initial_pos, user_gesture, was_blocked); |
| 702 } | 844 } |
| 703 } | 845 } |
| OLD | NEW |