Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Unified Diff: chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.cc

Issue 14556015: [Media Galleries] Lazily initialize the storage monitor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Improve tracker code Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..4b0655b4aeb321eeb61e4604490cfb9ea8c4592b 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,14 +72,6 @@ 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)
@@ -116,17 +108,18 @@ GalleryWatchStateTracker* GalleryWatchStateTracker::GetForProfile(
void GalleryWatchStateTracker::OnGalleryPermissionChanged(
const std::string& extension_id,
chrome::MediaGalleryPrefId gallery_id,
- bool has_permission) {
+ bool has_permission,
+ chrome::MediaGalleriesPreferences* preferences) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
// Granted gallery permission.
if (has_permission && HasGalleryWatchInfo(extension_id, gallery_id, false)) {
- SetupGalleryWatch(extension_id, gallery_id);
+ SetupGalleryWatch(extension_id, gallery_id, preferences);
return;
}
// Revoked gallery permission.
if (!has_permission && HasGalleryWatchInfo(extension_id, gallery_id, true))
- RemoveGalleryWatch(extension_id, gallery_id);
+ RemoveGalleryWatch(extension_id, gallery_id, preferences);
}
chrome::MediaGalleryPrefIdSet
@@ -148,6 +141,15 @@ GalleryWatchStateTracker::GetAllWatchedGalleryIDsForExtension(
void GalleryWatchStateTracker::RemoveAllGalleryWatchersForExtension(
const std::string& extension_id) {
+ g_browser_process->media_file_system_registry()->GetPreferencesAsync(
+ profile_, base::Bind(
+ &GalleryWatchStateTracker::RemoveAllGalleryWatchersWithPreferences,
vandebo (ex-Chrome) 2013/05/17 22:19:58 Because of this, I think MediaGalleriesPrivateRemo
+ AsWeakPtr(), extension_id));
+}
+
+void GalleryWatchStateTracker::RemoveAllGalleryWatchersWithPreferences(
+ const std::string& extension_id,
+ chrome::MediaGalleriesPreferences* preferences) {
WatchedExtensionsMap::iterator extension_id_iter =
watched_extensions_map_.find(extension_id);
if (extension_id_iter == watched_extensions_map_.end())
@@ -155,7 +157,7 @@ void GalleryWatchStateTracker::RemoveAllGalleryWatchersForExtension(
const WatchedGalleriesMap& galleries = extension_id_iter->second;
for (WatchedGalleriesMap::const_iterator gallery_id_iter = galleries.begin();
gallery_id_iter != galleries.end(); ++gallery_id_iter)
- RemoveGalleryWatch(extension_id, gallery_id_iter->second);
+ RemoveGalleryWatch(extension_id, gallery_id_iter->second, preferences);
watched_extensions_map_.erase(extension_id_iter);
WriteToStorage(extension_id);
}
@@ -246,23 +248,35 @@ void GalleryWatchStateTracker::ReadFromStorage(const std::string& extension_id,
if (!value.get() || !value->GetAsList(&list))
return;
chrome::MediaGalleryPrefIdSet gallery_ids = WatchedGalleryIdsFromValue(list);
+ if (!gallery_ids.empty()) {
+ 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) {
for (chrome::MediaGalleryPrefIdSet::const_iterator id_iter =
gallery_ids.begin();
id_iter != gallery_ids.end(); ++id_iter) {
watched_extensions_map_[extension_id][*id_iter] = false;
- SetupGalleryWatch(extension_id, *id_iter);
+ SetupGalleryWatch(extension_id, *id_iter, preferences);
}
}
void GalleryWatchStateTracker::SetupGalleryWatch(
const std::string& extension_id,
- chrome::MediaGalleryPrefId gallery_id) {
+ chrome::MediaGalleryPrefId gallery_id,
+ chrome::MediaGalleriesPreferences* preferences) {
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));
+ base::FilePath gallery_file_path(preferences->LookUpGalleryPathForExtension(
+ gallery_id, extension, false));
if (gallery_file_path.empty())
return;
MediaGalleriesPrivateEventRouter* router =
@@ -285,13 +299,13 @@ void GalleryWatchStateTracker::SetupGalleryWatch(
void GalleryWatchStateTracker::RemoveGalleryWatch(
const std::string& extension_id,
- chrome::MediaGalleryPrefId gallery_id) {
+ chrome::MediaGalleryPrefId gallery_id,
+ chrome::MediaGalleriesPreferences* preferences) {
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));
+ base::FilePath gallery_file_path(preferences->LookUpGalleryPathForExtension(
+ gallery_id, extension, true));
if (gallery_file_path.empty())
return;
content::BrowserThread::PostTask(

Powered by Google App Engine
This is Rietveld 408576698