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

Unified Diff: chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h

Issue 18986012: Media Galleries API Picasa: Make PicasaDataProvider handle async PMP and INI parsing robustly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0039-picasa-import-sandbox-ini-parsing
Patch Set: Created 7 years, 4 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/fileapi/picasa/picasa_data_provider.h
diff --git a/chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h b/chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h
index 5f34d8af4bd7322edd182f228e391346d0d8398c..7170d646ae4eda21a931e4ac49c91136eb87c449 100644
--- a/chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h
+++ b/chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h
@@ -6,10 +6,11 @@
#define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PICASA_DATA_PROVIDER_H_
#include <map>
+#include <queue>
#include <string>
#include <vector>
-#include "base/callback_forward.h"
+#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
@@ -20,44 +21,89 @@
namespace picasa {
class SafePicasaAlbumTableReader;
+class SafePicasaAlbumsIndexer;
// Created and owned by ImportedMediaGalleryRegistryTaskRunnerValues
class PicasaDataProvider {
public:
+ typedef base::Callback<void(bool)> ReadyCallback;
+
+ enum DataType {
+ LIST_OF_ALBUMS_AND_FOLDERS_DATA,
+ ALBUMS_IMAGES_DATA
+ };
+
explicit PicasaDataProvider(const base::FilePath& database_path);
virtual ~PicasaDataProvider();
// Ask the data provider to refresh the data if necessary. |ready_callback|
- // will be called when the data is up to date
+ // will be called when the data is up to date.
// TODO(tommycli): Investigate having the callback return a bool indicating
// success or failure - and handling it intelligently in PicasaFileUtil.
- virtual void RefreshData(const base::Closure& ready_callback);
+ void RefreshData(DataType needed_data, const ReadyCallback& ready_callback);
+ // These methods return scoped_ptrs because we want to return a copy that
+ // will not change to the caller.
scoped_ptr<AlbumMap> GetAlbums();
scoped_ptr<AlbumMap> GetFolders();
- // TODO(tommycli): Implement album contents. GetAlbumContents(...)
-
- protected:
- // Protected for test class usage.
- void OnDataRefreshed(const base::Closure& ready_callback,
- bool parse_success, const std::vector<AlbumInfo>& albums,
- const std::vector<AlbumInfo>& folder);
+ // |error| must be non-NULL.
+ scoped_ptr<AlbumImages> FindAlbumImages(const std::string& key,
+ base::PlatformFileError* error);
private:
+ enum State {
+ STALE_DATA_STATE,
+ INVALID_DATA_STATE,
+ LIST_OF_ALBUMS_AND_FOLDERS_FRESH_STATE,
+ ALBUMS_IMAGES_FRESH_STATE
+ };
+
friend class PicasaFileUtilTest;
- friend class TestPicasaDataProvider;
+ friend class PicasaDataProviderInvalidateSimpleTest;
+ friend class PicasaDataProviderInvalidateInflightTableReaderTest;
+ friend class PicasaDataProviderInvalidateInflightAlbumsIndexerTest;
+
+ // Notifies data provider that any currently cached data is stale.
+ void InvalidateData();
+
+ // Kicks off utility processes needed to fulfill any pending callbacks.
+ void DoRefreshIfNecessary();
+
+ void OnAlbumTableReaderDone(scoped_refptr<SafePicasaAlbumTableReader> reader,
+ bool parse_success,
+ const std::vector<AlbumInfo>& albums,
+ const std::vector<AlbumInfo>& folder);
+
+ void OnAlbumsIndexerDone(scoped_refptr<SafePicasaAlbumsIndexer> indexer,
+ bool success,
+ const picasa::AlbumImagesMap& albums_images);
static std::string DateToPathString(const base::Time& time);
static void UniquifyNames(const std::vector<AlbumInfo>& info_list,
AlbumMap* result_map);
+ // Methods are used in the browser test to tweak internal data for testing.
+ void SetDatabasePathForTesting(const base::FilePath& database_path);
+ void SetAlbumMapsForTesting(const AlbumMap& album_map,
+ const AlbumMap& folder_map);
+
AlbumMap album_map_;
AlbumMap folder_map_;
+ AlbumImagesMap albums_images_;
base::FilePath database_path_;
- bool needs_refresh_;
+ State state_;
+
+ // Callbacks that are waiting for their requested data to be ready.
+ std::queue<ReadyCallback> album_list_ready_callbacks_;
+ std::queue<ReadyCallback> albums_index_ready_callbacks_;
+
+ // Stores the "live" in-flight utility processes. Callbacks from other
+ // (older) utility processes are stale and ignored. Only one of these at a
+ // time should be non-NULL.
scoped_refptr<SafePicasaAlbumTableReader> album_table_reader_;
+ scoped_refptr<SafePicasaAlbumsIndexer> albums_indexer_;
base::WeakPtrFactory<PicasaDataProvider> weak_factory_;

Powered by Google App Engine
This is Rietveld 408576698