Index: chrome/browser/media_galleries/media_galleries_preferences.h |
diff --git a/chrome/browser/media_galleries/media_galleries_preferences.h b/chrome/browser/media_galleries/media_galleries_preferences.h |
index a65a2beb2664ab5007255952f44e4ad6c06153ba..22b7f0cd2898ce9011cdfa9a7e6c28b693ed2ac6 100644 |
--- a/chrome/browser/media_galleries/media_galleries_preferences.h |
+++ b/chrome/browser/media_galleries/media_galleries_preferences.h |
@@ -10,10 +10,12 @@ |
#include <string> |
#include "base/basictypes.h" |
+#include "base/callback_forward.h" |
#include "base/files/file_path.h" |
#include "base/memory/weak_ptr.h" |
#include "base/observer_list.h" |
#include "base/strings/string16.h" |
+#include "base/threading/thread_checker.h" |
#include "base/time/time.h" |
#include "chrome/browser/storage_monitor/removable_storage_observer.h" |
#include "components/browser_context_keyed_service/browser_context_keyed_service.h" |
@@ -148,6 +150,19 @@ class MediaGalleriesPreferences : public BrowserContextKeyedService, |
explicit MediaGalleriesPreferences(Profile* profile); |
virtual ~MediaGalleriesPreferences(); |
+ // Ensures that the preferences is initialized. The provided callback, if |
+ // non-null, will be called when initialization is complete. If initialization |
+ // has already completed, this callback will be invoked in the calling stack. |
+ // Before the callback is run, other calls may not return the correct results. |
+ // Should be invoked on the UI thread; callbacks will be run on the UI thread. |
+ // This call also ensures that the StorageMonitor is initialized. |
+ // Note for unit tests: This requires an active FILE thread and |
+ // EnsureMediaDirectoriesExists instance to complete reliably. |
+ void EnsureInitialized(base::Closure callback); |
+ |
+ // Return true if the storage monitor has already been initialized. |
+ bool IsInitialized() const; |
+ |
Profile* profile(); |
void AddGalleryChangeObserver(GalleryChangeObserver* observer); |
@@ -201,9 +216,7 @@ class MediaGalleriesPreferences : public BrowserContextKeyedService, |
MediaGalleryPrefId pref_id, |
bool has_permission); |
- const MediaGalleriesPrefInfoMap& known_galleries() const { |
- return known_galleries_; |
- } |
+ const MediaGalleriesPrefInfoMap& known_galleries() const; |
// BrowserContextKeyedService implementation: |
virtual void Shutdown() OVERRIDE; |
@@ -222,6 +235,10 @@ class MediaGalleriesPreferences : public BrowserContextKeyedService, |
typedef std::map<std::string /*device id*/, MediaGalleryPrefIdSet> |
DeviceIdPrefIdsMap; |
+ // These must be called on the UI thread. |
+ void OnInitializationCallbackReturned(); |
+ void FinishInitialization(); |
+ |
// Populates the default galleries if this is a fresh profile. |
void AddDefaultGalleriesIfFreshProfile(); |
@@ -236,11 +253,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); |
- // Try to add an entry for the iTunes 'device'. |
- void OnITunesDeviceID(const std::string& device_id); |
- |
- // Try to add an entry for the Picasa 'device'. |
- void OnPicasaDeviceID(const std::string& device_id); |
+ // Handle an iTunes or Picasa finder returning a device ID to us. |
+ void OnFinderDeviceID(const std::string& device_id); |
// Builds |known_galleries_| from the persistent store. |
void InitFromPrefs(); |
@@ -288,6 +302,14 @@ class MediaGalleriesPreferences : public BrowserContextKeyedService, |
base::WeakPtrFactory<MediaGalleriesPreferences> weak_factory_; |
+ // Used to make sure we call initialize from the same thread as creation. |
+ base::ThreadChecker thread_checker_; |
Lei Zhang
2013/09/21 00:36:06
If we know MediaGalleriesPreferences must run on t
tommycli
2013/09/23 20:39:12
Done.
|
+ |
+ bool initializing_; |
+ bool initialized_; |
+ std::vector<base::Closure> on_initialize_callbacks_; |
+ int pre_initialization_callbacks_waiting_; |
+ |
// The profile that owns |this|. |
Profile* profile_; |