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

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

Issue 24269007: Media Galleries API: Fix MediaGalleriesPreferences finders race. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge origin Created 7 years, 3 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/media_galleries_private_api.cc
diff --git a/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc b/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc
index 564908a292367baab877b9f78af330befde2bd2a..025aa345e485b35ee0f46ebbc1d67a5c538b1fc2 100644
--- a/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc
+++ b/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc
@@ -63,11 +63,11 @@ bool GetGalleryFilePathAndId(const std::string& gallery_id,
MediaGalleryPrefId pref_id;
if (!base::StringToUint64(gallery_id, &pref_id))
return false;
- MediaFileSystemRegistry* registry =
- g_browser_process->media_file_system_registry();
- base::FilePath file_path(
- registry->GetPreferences(profile)->LookUpGalleryPathForExtension(
- pref_id, extension, false));
+ MediaGalleriesPreferences* preferences =
+ g_browser_process->media_file_system_registry()->GetPreferences(profile);
+ DCHECK(preferences->IsInitialized());
vandebo (ex-Chrome) 2013/09/23 18:35:13 Actually... since preferences checks that its init
tommycli 2013/09/23 20:39:12 Done.
+ base::FilePath file_path(
+ preferences->LookUpGalleryPathForExtension(pref_id, extension, false));
if (file_path.empty())
return false;
*gallery_pref_id = pref_id;
@@ -122,12 +122,14 @@ MediaGalleriesPrivateAPI* MediaGalleriesPrivateAPI::Get(Profile* profile) {
void MediaGalleriesPrivateAPI::OnListenerAdded(
const EventListenerInfo& details) {
- // Start the StorageMonitor if it is not already initialized. After that,
+ // Make sure MediaGalleriesPreferences is initialized. After that,
// try to initialize the event router for the listener.
// This method is called synchronously with the message handler for the
// JS invocation.
- StorageMonitor::GetInstance()->EnsureInitialized(base::Bind(
+ MediaGalleriesPreferences* preferences =
+ g_browser_process->media_file_system_registry()->GetPreferences(profile_);
+ preferences->EnsureInitialized(base::Bind(
&MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker,
weak_ptr_factory_.GetWeakPtr()));
}
@@ -170,15 +172,17 @@ bool MediaGalleriesPrivateAddGalleryWatchFunction::RunImpl() {
AddGalleryWatch::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
- StorageMonitor::GetInstance()->EnsureInitialized(base::Bind(
- &MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit,
+ MediaGalleriesPreferences* preferences =
+ g_browser_process->media_file_system_registry()->GetPreferences(profile_);
+ preferences->EnsureInitialized(base::Bind(
+ &MediaGalleriesPrivateAddGalleryWatchFunction::OnPreferencesInit,
this,
params->gallery_id));
return true;
}
-void MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit(
+void MediaGalleriesPrivateAddGalleryWatchFunction::OnPreferencesInit(
const std::string& pref_id) {
DCHECK(StorageMonitor::GetInstance()->IsInitialized());
base::FilePath gallery_file_path;
@@ -250,14 +254,16 @@ bool MediaGalleriesPrivateRemoveGalleryWatchFunction::RunImpl() {
RemoveGalleryWatch::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
- StorageMonitor::GetInstance()->EnsureInitialized(base::Bind(
- &MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit,
+ MediaGalleriesPreferences* preferences =
+ g_browser_process->media_file_system_registry()->GetPreferences(profile_);
+ preferences->EnsureInitialized(base::Bind(
+ &MediaGalleriesPrivateRemoveGalleryWatchFunction::OnPreferencesInit,
this,
params->gallery_id));
return true;
}
-void MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit(
+void MediaGalleriesPrivateRemoveGalleryWatchFunction::OnPreferencesInit(
const std::string& pref_id) {
DCHECK(StorageMonitor::GetInstance()->IsInitialized());
#if defined(OS_WIN)
@@ -333,19 +339,20 @@ bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() {
if (!render_view_host() || !render_view_host()->GetProcess())
return false;
- StorageMonitor::GetInstance()->EnsureInitialized(base::Bind(
- &MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit,
+ MediaGalleriesPreferences* preferences =
+ g_browser_process->media_file_system_registry()->GetPreferences(profile_);
+ preferences->EnsureInitialized(base::Bind(
+ &MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnPreferencesInit,
this));
return true;
}
-void
-MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit() {
+void MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnPreferencesInit() {
#if defined(OS_WIN)
DCHECK(StorageMonitor::GetInstance()->IsInitialized());
- MediaFileSystemRegistry* registry =
- g_browser_process->media_file_system_registry();
- MediaGalleriesPreferences* preferences = registry->GetPreferences(profile_);
+ MediaGalleriesPreferences* preferences =
+ g_browser_process->media_file_system_registry()->GetPreferences(profile_);
+ DCHECK(preferences->IsInitialized());
GalleryWatchStateTracker* state_tracker =
MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker();
state_tracker->RemoveAllGalleryWatchersForExtension(

Powered by Google App Engine
This is Rietveld 408576698