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

Unified Diff: chrome/browser/media_galleries/media_file_system_registry.cc

Issue 14556015: [Media Galleries] Lazily initialize the storage monitor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Windows compile tweaks 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/media_galleries/media_file_system_registry.cc
diff --git a/chrome/browser/media_galleries/media_file_system_registry.cc b/chrome/browser/media_galleries/media_file_system_registry.cc
index f210e285e3b16aa2806da8a9f6536f77449e5b43..dbac765b3ffdc6b788d091b2d7bad5cf35e4438c 100644
--- a/chrome/browser/media_galleries/media_file_system_registry.cc
+++ b/chrome/browser/media_galleries/media_file_system_registry.cc
@@ -431,11 +431,24 @@ void MediaFileSystemRegistry::GetMediaFileSystemsForExtension(
const content::RenderViewHost* rvh,
const extensions::Extension* extension,
const MediaFileSystemsCallback& callback) {
+LOG(INFO) << "GetFSForExt";
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Profile* profile =
Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
- MediaGalleriesPreferences* preferences = GetPreferences(profile);
+ GetPreferencesAsync(
+ profile, base::Bind(
+ &MediaFileSystemRegistry::GetMediaFileSystemsPostStorageMonitorInit,
+ base::Unretained(this),
+ rvh, extension, callback));
+}
+
+void MediaFileSystemRegistry::GetMediaFileSystemsPostStorageMonitorInit(
+ const content::RenderViewHost* rvh,
+ const extensions::Extension* extension,
+ const MediaFileSystemsCallback& callback,
+ MediaGalleriesPreferences* preferences) {
+LOG(INFO) << "GetFSForExtPostInit";
MediaGalleryPrefIdSet galleries =
preferences->GalleriesForExtension(*extension);
@@ -444,6 +457,8 @@ void MediaFileSystemRegistry::GetMediaFileSystemsForExtension(
return;
}
+ Profile* profile =
+ Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext());
if (!ContainsKey(pref_change_registrar_map_, profile)) {
PrefChangeRegistrar* pref_registrar = new PrefChangeRegistrar;
pref_registrar->Init(profile->GetPrefs());
@@ -470,8 +485,39 @@ void MediaFileSystemRegistry::GetMediaFileSystemsForExtension(
callback);
}
+void MediaFileSystemRegistry::GetPreferencesAsync(
+ Profile* profile,
+ base::Callback<void(MediaGalleriesPreferences*)> callback) {
+LOG(INFO) << "GetPreferencesAsync";
+ StorageMonitor* monitor = StorageMonitor::GetInstance();
+ if (!monitor) {
Lei Zhang 2013/05/10 05:24:43 Do we want to just make tests that use MediaFSRegi
Greg Billock 2013/05/10 16:20:27 Yes, I think that'd be better. I kind of suspect t
Lei Zhang 2013/05/11 02:12:22 Can you add a TODO so we don't forget?
Greg Billock 2013/05/13 21:20:38 Done.
+ callback.Run(MediaGalleriesPreferencesFactory::GetForProfile(profile));
+ return;
+ }
+
+ if (monitor->IsInitialized()) {
+ callback.Run(GetPreferences(profile));
+ return;
+ }
+
+ monitor->Initialize(
+ base::Bind(&MediaFileSystemRegistry::OnStorageMonitorInitialized,
+ base::Unretained(this),
+ profile, callback));
+
+ // TODO(gbillock): set a timeout here to bail out of init?
+}
+
+void MediaFileSystemRegistry::OnStorageMonitorInitialized(
+ Profile* profile,
+ base::Callback<void(MediaGalleriesPreferences*)> callback) {
+LOG(INFO) << "StorageMonitor inialized...";
+ callback.Run(GetPreferences(profile));
+}
+
MediaGalleriesPreferences* MediaFileSystemRegistry::GetPreferences(
Profile* profile) {
+LOG(INFO) << "MFSR::GetPreferences";
MediaGalleriesPreferences* preferences =
MediaGalleriesPreferencesFactory::GetForProfile(profile);
if (ContainsKey(extension_hosts_map_, profile))
@@ -485,6 +531,7 @@ MediaGalleriesPreferences* MediaFileSystemRegistry::GetPreferences(
StorageMonitor* monitor = StorageMonitor::GetInstance();
if (!monitor)
return preferences;
+ DCHECK(monitor->IsInitialized());
std::vector<StorageInfo> existing_devices = monitor->GetAttachedStorage();
for (size_t i = 0; i < existing_devices.size(); i++) {
if (!MediaStorageUtil::IsMediaDevice(existing_devices[i].device_id))

Powered by Google App Engine
This is Rietveld 408576698