Chromium Code Reviews| Index: chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.cc |
| diff --git a/chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.cc b/chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.cc |
| index e580d9cc2d3153a0de7d5e1697fe589d186e380e..e24823ec76e3f2a95eab60380a3d5f184f1818b4 100644 |
| --- a/chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.cc |
| +++ b/chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.cc |
| @@ -72,18 +72,11 @@ const Extension* GetExtensionById(Profile* profile, |
| return service->GetExtensionById(extension_id, false); |
| } |
| -// Returns the initialized media galleries preferences for the specified |
| -// |profile|. |
| -chrome::MediaGalleriesPreferences* GetMediaGalleryPreferences( |
| - Profile* profile) { |
| - return g_browser_process->media_file_system_registry()->GetPreferences( |
| - profile); |
| -} |
| - |
| } // namespace |
| GalleryWatchStateTracker::GalleryWatchStateTracker(Profile* profile) |
| - : profile_(profile) { |
| + : profile_(profile), |
| + preferences_(NULL) { |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| DCHECK(profile_); |
| registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| @@ -160,6 +153,11 @@ void GalleryWatchStateTracker::RemoveAllGalleryWatchersForExtension( |
| WriteToStorage(extension_id); |
| } |
| +void GalleryWatchStateTracker::SetPreferences( |
| + chrome::MediaGalleriesPreferences* preferences) { |
| + preferences_ = preferences; |
|
Lei Zhang
2013/05/15 22:44:31
Make this a no-op if |preferences_| is already set
Greg Billock
2013/05/16 01:59:58
Actually, this is important. Will the tracker be u
Lei Zhang
2013/05/16 03:35:21
The tracker object is only used by the media galle
|
| +} |
| + |
| void GalleryWatchStateTracker::OnGalleryWatchAdded( |
| const std::string& extension_id, |
| chrome::MediaGalleryPrefId gallery_id) { |
| @@ -246,6 +244,20 @@ void GalleryWatchStateTracker::ReadFromStorage(const std::string& extension_id, |
| if (!value.get() || !value->GetAsList(&list)) |
| return; |
| chrome::MediaGalleryPrefIdSet gallery_ids = WatchedGalleryIdsFromValue(list); |
| + if (gallery_ids.size() > 0) { |
|
Lei Zhang
2013/05/15 22:44:31
You can use set::empty() instead.
Greg Billock
2013/05/16 01:59:58
Done.
|
| + g_browser_process->media_file_system_registry()->GetPreferencesAsync( |
|
Lei Zhang
2013/05/15 22:44:31
How about we check |preferences_|, and if it is al
Greg Billock
2013/05/16 01:59:58
I'd rather always use the same access path -- this
|
| + profile_, |
| + base::Bind(&GalleryWatchStateTracker::ReadFromStorageWithPreferences, |
| + AsWeakPtr(), extension_id, gallery_ids)); |
| + } |
| +} |
| + |
| +void GalleryWatchStateTracker::ReadFromStorageWithPreferences( |
| + const std::string& extension_id, |
| + chrome::MediaGalleryPrefIdSet gallery_ids, |
| + chrome::MediaGalleriesPreferences* preferences) { |
| + SetPreferences(preferences); |
| + |
| for (chrome::MediaGalleryPrefIdSet::const_iterator id_iter = |
| gallery_ids.begin(); |
| id_iter != gallery_ids.end(); ++id_iter) { |
| @@ -260,9 +272,9 @@ void GalleryWatchStateTracker::SetupGalleryWatch( |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| const Extension* extension = GetExtensionById(profile_, extension_id); |
| DCHECK(extension); |
| - base::FilePath gallery_file_path( |
| - GetMediaGalleryPreferences(profile_)->LookUpGalleryPathForExtension( |
| - gallery_id, extension, false)); |
| + DCHECK(preferences_); |
| + base::FilePath gallery_file_path(preferences_->LookUpGalleryPathForExtension( |
| + gallery_id, extension, false)); |
| if (gallery_file_path.empty()) |
| return; |
| MediaGalleriesPrivateEventRouter* router = |
| @@ -289,9 +301,9 @@ void GalleryWatchStateTracker::RemoveGalleryWatch( |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| const Extension* extension = GetExtensionById(profile_, extension_id); |
| DCHECK(extension); |
| - base::FilePath gallery_file_path( |
| - GetMediaGalleryPreferences(profile_)->LookUpGalleryPathForExtension( |
| - gallery_id, extension, true)); |
| + DCHECK(preferences_); |
| + base::FilePath gallery_file_path(preferences_->LookUpGalleryPathForExtension( |
| + gallery_id, extension, true)); |
| if (gallery_file_path.empty()) |
| return; |
| content::BrowserThread::PostTask( |