Chromium Code Reviews| Index: chrome/browser/background/background_contents_service.cc |
| diff --git a/chrome/browser/background/background_contents_service.cc b/chrome/browser/background/background_contents_service.cc |
| index 150f8a94b01f44d0e8f8b7d2ff97a6d56ef280aa..11bd78c703f7766cd460e8f2d12c5887d7cdff7a 100644 |
| --- a/chrome/browser/background/background_contents_service.cc |
| +++ b/chrome/browser/background/background_contents_service.cc |
| @@ -216,19 +216,24 @@ void BackgroundContentsService::Observe( |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| switch (type) { |
| - case chrome::NOTIFICATION_EXTENSIONS_READY: |
| - LoadBackgroundContentsFromManifests( |
| - content::Source<Profile>(source).ptr()); |
| - LoadBackgroundContentsFromPrefs(content::Source<Profile>(source).ptr()); |
| + case chrome::NOTIFICATION_EXTENSIONS_READY: { |
| + Profile* profile = content::Source<Profile>(source).ptr(); |
| + LoadBackgroundContentsFromManifests(profile); |
| + LoadBackgroundContentsFromPrefs(profile); |
| + SendChangeNotification(profile); |
| break; |
| + } |
| case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: |
| BackgroundContentsShutdown( |
| content::Details<BackgroundContents>(details).ptr()); |
| + SendChangeNotification(content::Source<Profile>(source).ptr()); |
| break; |
| case chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED: |
| DCHECK(IsTracked(content::Details<BackgroundContents>(details).ptr())); |
| UnregisterBackgroundContents( |
| content::Details<BackgroundContents>(details).ptr()); |
| + // CLOSED is always followed by a DELETED notification so we'll send our |
| + // change notification there. |
| break; |
| case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: { |
| DCHECK(IsTracked(content::Details<BackgroundContents>(details).ptr())); |
| @@ -248,6 +253,7 @@ void BackgroundContentsService::Observe( |
| break; |
| } |
| RegisterBackgroundContents(bgcontents); |
| + SendChangeNotification(profile); |
|
Mihai Parparita -not on Chrome
2012/05/03 00:54:11
Why would a navigation cause the list of backgroun
Andrew T Wilson (Slow)
2012/05/03 07:42:56
It doesn't change the list of background content *
|
| break; |
| } |
| case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| @@ -272,6 +278,7 @@ void BackgroundContentsService::Observe( |
| // Remove any "This extension has crashed" balloons. |
| ScheduleCloseBalloon(extension->id()); |
| + SendChangeNotification(profile); |
| break; |
| } |
| case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: |
| @@ -311,12 +318,15 @@ void BackgroundContentsService::Observe( |
| ShutdownAssociatedBackgroundContents( |
| ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)-> |
| extension->id())); |
| + SendChangeNotification(content::Source<Profile>(source).ptr()); |
| break; |
| case extension_misc::UNLOAD_REASON_UPDATE: { |
| // If there is a manifest specified background page, then shut it down |
| // here, since if the updated extension still has the background page, |
| // then it will be loaded from LOADED callback. Otherwise, leave |
| // BackgroundContents in place. |
| + // We don't call SendChangeNotification here - it will be generated |
| + // from the LOADED callback. |
| const Extension* extension = |
| content::Details<UnloadedExtensionInfo>(details)->extension; |
| if (extension->has_background_page()) |
| @@ -376,6 +386,13 @@ void BackgroundContentsService::LoadBackgroundContentsFromPrefs( |
| } |
| } |
| +void BackgroundContentsService::SendChangeNotification(Profile* profile) { |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_BACKGROUND_CONTENTS_SERVICE_CHANGED, |
| + content::Source<Profile>(profile), |
| + content::Details<BackgroundContentsService>(this)); |
| +} |
| + |
| void BackgroundContentsService::LoadBackgroundContentsForExtension( |
| Profile* profile, |
| const std::string& extension_id) { |
| @@ -510,6 +527,22 @@ void BackgroundContentsService::RegisterBackgroundContents( |
| pref->SetWithoutPathExpansion(UTF16ToUTF8(appid), dict); |
| } |
| +bool BackgroundContentsService::HasRegisteredBackgroundContents( |
| + const string16& app_id) { |
| + if (!prefs_) |
| + return false; |
| + std::string app = UTF16ToUTF8(app_id); |
| + const DictionaryValue* contents = |
| + prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); |
| + // Walk our dictionary looking for any entries with this key. |
|
Mihai Parparita -not on Chrome
2012/05/03 00:54:11
Why not use contents->HasKey(app)?
Andrew T Wilson (Slow)
2012/05/03 07:42:56
Ah, good idea. I should've checked DictionaryValue
|
| + for (DictionaryValue::key_iterator it = contents->begin_keys(); |
| + it != contents->end_keys(); ++it) { |
| + if (*it == app) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| void BackgroundContentsService::UnregisterBackgroundContents( |
| BackgroundContents* background_contents) { |
| if (!prefs_) |