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

Side by Side Diff: chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h

Issue 23499006: Media Galleries API Picasa: Add file watch to invalidate database data on disk write. (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PICASA_DATA_PROVIDER_H_ 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PICASA_DATA_PROVIDER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PICASA_DATA_PROVIDER_H_ 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PICASA_DATA_PROVIDER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback.h" 13 #include "base/basictypes.h"
14 #include "base/callback_forward.h"
14 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/file_path_watcher.h"
15 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
18 #include "base/time/time.h" 20 #include "base/time/time.h"
19 #include "chrome/common/media_galleries/picasa_types.h" 21 #include "chrome/common/media_galleries/picasa_types.h"
20 22
21 namespace picasa { 23 namespace picasa {
22 24
23 class SafePicasaAlbumTableReader; 25 class SafePicasaAlbumTableReader;
24 class SafePicasaAlbumsIndexer; 26 class SafePicasaAlbumsIndexer;
25 27
26 // Created and owned by ImportedMediaGalleryRegistryTaskRunnerValues 28 // Created and owned by ImportedMediaGalleryRegistryTaskRunnerValues
27 class PicasaDataProvider { 29 class PicasaDataProvider {
28 public: 30 public:
29 typedef base::Callback<void(bool)> ReadyCallback; 31 typedef base::Callback<void(bool)> ReadyCallback;
30 32
31 enum DataType { 33 enum DataType {
32 LIST_OF_ALBUMS_AND_FOLDERS_DATA, 34 LIST_OF_ALBUMS_AND_FOLDERS_DATA,
33 ALBUMS_IMAGES_DATA 35 ALBUMS_IMAGES_DATA
34 }; 36 };
35 37
36 explicit PicasaDataProvider(const base::FilePath& database_path); 38 explicit PicasaDataProvider(const base::FilePath& database_path);
37 virtual ~PicasaDataProvider(); 39 virtual ~PicasaDataProvider();
38 40
39 // Ask the data provider to refresh the data if necessary. |ready_callback| 41 // Ask the data provider to refresh the data if necessary. |ready_callback|
40 // will be called when the data is up to date. 42 // will be called when the data is up to date.
41 // TODO(tommycli): Investigate having the callback return a bool indicating
42 // success or failure - and handling it intelligently in PicasaFileUtil.
43 void RefreshData(DataType needed_data, const ReadyCallback& ready_callback); 43 void RefreshData(DataType needed_data, const ReadyCallback& ready_callback);
44 44
45 // These methods return scoped_ptrs because we want to return a copy that 45 // These methods return scoped_ptrs because we want to return a copy that
46 // will not change to the caller. 46 // will not change to the caller.
47 scoped_ptr<AlbumMap> GetAlbums(); 47 scoped_ptr<AlbumMap> GetAlbums();
48 scoped_ptr<AlbumMap> GetFolders(); 48 scoped_ptr<AlbumMap> GetFolders();
49 // |error| must be non-NULL. 49 // |error| must be non-NULL.
50 scoped_ptr<AlbumImages> FindAlbumImages(const std::string& key, 50 scoped_ptr<AlbumImages> FindAlbumImages(const std::string& key,
51 base::PlatformFileError* error); 51 base::PlatformFileError* error);
52 52
53 protected:
54 // Used only for testing to provide a custom temp_dir_path.
55 PicasaDataProvider(const base::FilePath& database_path,
56 const base::FilePath& temp_dir_path);
vandebo (ex-Chrome) 2013/08/29 23:19:22 Probably don't need an explicit temp dir in test.
tommycli 2013/09/03 20:20:43 Done.
57
58 // Notifies data provider that any currently cached data is stale.
59 virtual void InvalidateData();
60
53 private: 61 private:
54 enum State { 62 enum State {
55 STALE_DATA_STATE, 63 STALE_DATA_STATE,
56 INVALID_DATA_STATE, 64 INVALID_DATA_STATE,
57 LIST_OF_ALBUMS_AND_FOLDERS_FRESH_STATE, 65 LIST_OF_ALBUMS_AND_FOLDERS_FRESH_STATE,
58 ALBUMS_IMAGES_FRESH_STATE 66 ALBUMS_IMAGES_FRESH_STATE
59 }; 67 };
60 68
61 friend class PicasaFileUtilTest; 69 friend class PicasaFileUtilTest;
62 friend class PicasaDataProviderInvalidateSimpleTest; 70 friend class TestPicasaDataProvider;
63 friend class PicasaDataProviderInvalidateInflightTableReaderTest;
64 friend class PicasaDataProviderInvalidateInflightAlbumsIndexerTest;
65 71
66 // Notifies data provider that any currently cached data is stale. 72 // Called when the FilePathWatcher for Picasa's temp directory has started.
67 void InvalidateData(); 73 void OnTempDirWatchStarted(
74 scoped_ptr<base::FilePathWatcher> temp_dir_watcher);
75
76 // Called when Picasa's temp directory has changed. Virtual for testing.
77 virtual void OnTempDirChanged(const base::FilePath& temp_dir_path,
78 bool error);
68 79
69 // Kicks off utility processes needed to fulfill any pending callbacks. 80 // Kicks off utility processes needed to fulfill any pending callbacks.
70 void DoRefreshIfNecessary(); 81 void DoRefreshIfNecessary();
71 82
72 void OnAlbumTableReaderDone(scoped_refptr<SafePicasaAlbumTableReader> reader, 83 void OnAlbumTableReaderDone(scoped_refptr<SafePicasaAlbumTableReader> reader,
73 bool parse_success, 84 bool parse_success,
74 const std::vector<AlbumInfo>& albums, 85 const std::vector<AlbumInfo>& albums,
75 const std::vector<AlbumInfo>& folder); 86 const std::vector<AlbumInfo>& folder);
76 87
77 void OnAlbumsIndexerDone(scoped_refptr<SafePicasaAlbumsIndexer> indexer, 88 void OnAlbumsIndexerDone(scoped_refptr<SafePicasaAlbumsIndexer> indexer,
78 bool success, 89 bool success,
79 const picasa::AlbumImagesMap& albums_images); 90 const picasa::AlbumImagesMap& albums_images);
80 91
81 static std::string DateToPathString(const base::Time& time); 92 static std::string DateToPathString(const base::Time& time);
82 static void UniquifyNames(const std::vector<AlbumInfo>& info_list, 93 static void UniquifyNames(const std::vector<AlbumInfo>& info_list,
83 AlbumMap* result_map); 94 AlbumMap* result_map);
84 95
85 // Methods are used in the browser test to tweak internal data for testing.
86 void SetDatabasePathForTesting(const base::FilePath& database_path);
87 void SetAlbumMapsForTesting(const AlbumMap& album_map,
88 const AlbumMap& folder_map);
89
90 AlbumMap album_map_; 96 AlbumMap album_map_;
91 AlbumMap folder_map_; 97 AlbumMap folder_map_;
92 AlbumImagesMap albums_images_; 98 AlbumImagesMap albums_images_;
93 99
94 base::FilePath database_path_; 100 base::FilePath database_path_;
95 101
96 State state_; 102 State state_;
97 103
98 // Callbacks that are waiting for their requested data to be ready. 104 // Callbacks that are waiting for their requested data to be ready.
99 std::queue<ReadyCallback> album_list_ready_callbacks_; 105 std::queue<ReadyCallback> album_list_ready_callbacks_;
100 std::queue<ReadyCallback> albums_index_ready_callbacks_; 106 std::queue<ReadyCallback> albums_index_ready_callbacks_;
101 107
102 // Stores the "live" in-flight utility processes. Callbacks from other 108 // Stores the "live" in-flight utility processes. Callbacks from other
103 // (older) utility processes are stale and ignored. Only one of these at a 109 // (older) utility processes are stale and ignored. Only one of these at a
104 // time should be non-NULL. 110 // time should be non-NULL.
105 scoped_refptr<SafePicasaAlbumTableReader> album_table_reader_; 111 scoped_refptr<SafePicasaAlbumTableReader> album_table_reader_;
106 scoped_refptr<SafePicasaAlbumsIndexer> albums_indexer_; 112 scoped_refptr<SafePicasaAlbumsIndexer> albums_indexer_;
107 113
114 // We watch the temp dir, as we can't detect database file modifications on
115 // Mac, but we are able to detect creation and deletion of temporary files.
116 scoped_ptr<base::FilePathWatcher> temp_dir_watcher_;
117
108 base::WeakPtrFactory<PicasaDataProvider> weak_factory_; 118 base::WeakPtrFactory<PicasaDataProvider> weak_factory_;
109 119
110 DISALLOW_COPY_AND_ASSIGN(PicasaDataProvider); 120 DISALLOW_COPY_AND_ASSIGN(PicasaDataProvider);
111 }; 121 };
112 122
113 } // namespace picasa 123 } // namespace picasa
114 124
115 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PICASA_DATA_PROVIDER_H_ 125 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PICASA_DATA_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698