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

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

Issue 25539003: Media Galleries API: Fix MediaGalleriesPreferences initialization for fresh profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/media_galleries/media_galleries_preferences.cc
diff --git a/chrome/browser/media_galleries/media_galleries_preferences.cc b/chrome/browser/media_galleries/media_galleries_preferences.cc
index 915f918ccd88e8aed1ebc462718aec1e5320d7b2..a6e4d0782665bc94ed06743e46e43f3b9b65350e 100644
--- a/chrome/browser/media_galleries/media_galleries_preferences.cc
+++ b/chrome/browser/media_galleries/media_galleries_preferences.cc
@@ -377,10 +377,12 @@ void MediaGalleriesPreferences::EnsureInitialized(base::Closure callback) {
// FinishInitialization.
pre_initialization_callbacks_waiting_ = 2;
- // Ensure StorageMonitor is initialized.
+ // We determine the freshness of the profile here, before any of the finders
+ // return and add media galleries to it.
+ bool need_to_add_default_galleries = APIHasBeenUsed(profile_);
StorageMonitor::GetInstance()->EnsureInitialized(
- base::Bind(&MediaGalleriesPreferences::OnInitializationCallbackReturned,
- weak_factory_.GetWeakPtr()));
+ base::Bind(&MediaGalleriesPreferences::OnStorageMonitorInit,
+ weak_factory_.GetWeakPtr(), need_to_add_default_galleries));
vandebo (ex-Chrome) 2013/10/01 22:19:01 nit: inline call to APIHasBeenUsed()
tommycli 2013/10/01 23:20:37 Done.
// Look for optional default galleries every time.
itunes::ITunesFinder::FindITunesLibrary(
@@ -420,7 +422,6 @@ void MediaGalleriesPreferences::FinishInitialization() {
StorageMonitor* monitor = StorageMonitor::GetInstance();
DCHECK(monitor->IsInitialized());
- AddDefaultGalleriesIfFreshProfile();
InitFromPrefs();
StorageMonitor::GetInstance()->AddObserver(this);
@@ -450,12 +451,7 @@ void MediaGalleriesPreferences::FinishInitialization() {
on_initialize_callbacks_.clear();
}
-void MediaGalleriesPreferences::AddDefaultGalleriesIfFreshProfile() {
- // Only add defaults the first time.
- if (APIHasBeenUsed(profile_))
- return;
-
- // Fresh profile case.
+void MediaGalleriesPreferences::AddDefaultGalleries() {
const int kDirectoryKeys[] = {
chrome::DIR_USER_MUSIC,
chrome::DIR_USER_PICTURES,
@@ -518,6 +514,13 @@ bool MediaGalleriesPreferences::UpdateDeviceIDForSingletonType(
return false;
}
+void MediaGalleriesPreferences::OnStorageMonitorInit(
+ bool need_to_add_default_galleries) {
+ if (need_to_add_default_galleries)
+ AddDefaultGalleries();
+ OnInitializationCallbackReturned();
+}
+
void MediaGalleriesPreferences::OnFinderDeviceID(const std::string& device_id) {
if (!device_id.empty() && !UpdateDeviceIDForSingletonType(device_id)) {
std::string gallery_name;

Powered by Google App Engine
This is Rietveld 408576698