Commit be3dddaa authored by tommycli@chromium.org's avatar tommycli@chromium.org

Media Galleries API: Fix MediaGalleriesPreferences initialization for fresh profiles.

BUG=151701, 295880
R=vandebo@chromium.org

Review URL: https://codereview.chromium.org/25539003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226509 0039d316-1c4b-4281-b951-d872f2087c98
parent d83f7ef2
......@@ -377,10 +377,12 @@ void MediaGalleriesPreferences::EnsureInitialized(base::Closure callback) {
// FinishInitialization.
pre_initialization_callbacks_waiting_ = 3;
// Ensure StorageMonitor is initialized.
// We determine the freshness of the profile here, before any of the finders
// return and add media galleries to it.
StorageMonitor::GetInstance()->EnsureInitialized(
base::Bind(&MediaGalleriesPreferences::OnInitializationCallbackReturned,
weak_factory_.GetWeakPtr()));
base::Bind(&MediaGalleriesPreferences::OnStorageMonitorInit,
weak_factory_.GetWeakPtr(),
APIHasBeenUsed(profile_) /* add_default_galleries */));
// Look for optional default galleries every time.
itunes::ITunesFinder::FindITunesLibrary(
......@@ -417,7 +419,6 @@ void MediaGalleriesPreferences::FinishInitialization() {
StorageMonitor* monitor = StorageMonitor::GetInstance();
DCHECK(monitor->IsInitialized());
AddDefaultGalleriesIfFreshProfile();
InitFromPrefs();
StorageMonitor::GetInstance()->AddObserver(this);
......@@ -447,12 +448,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,
......@@ -515,6 +511,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;
......
......@@ -240,8 +240,8 @@ class MediaGalleriesPreferences : public BrowserContextKeyedService,
void OnInitializationCallbackReturned();
void FinishInitialization();
// Populates the default galleries if this is a fresh profile.
void AddDefaultGalleriesIfFreshProfile();
// Populates the default galleries. Call only on fresh profiles.
void AddDefaultGalleries();
// This is a hack - Some devices (iTunes, Picasa) are singletons in that only
// one instance of that type is supported at a time. As such, the device id
......@@ -254,6 +254,8 @@ class MediaGalleriesPreferences : public BrowserContextKeyedService,
// device id. It returns true if the device id is up to date.
bool UpdateDeviceIDForSingletonType(const std::string& device_id);
void OnStorageMonitorInit(bool add_default_galleries);
// Handle an iPhoto, iTunes, or Picasa finder returning a device ID to us.
void OnFinderDeviceID(const std::string& device_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment