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; |
+} |
+ |
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) { |
+ g_browser_process->media_file_system_registry()->GetPreferencesAsync( |
+ 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); |
Lei Zhang
2013/05/14 04:12:23
Do we need both this and the SetPreferences() call
Greg Billock
2013/05/14 21:27:13
I think they get touched in different paths. So th
|
+ |
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( |