OLD | NEW |
---|---|
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 <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/callback_forward.h" | 13 #include "base/callback.h" |
13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "chrome/common/media_galleries/picasa_types.h" | 19 #include "chrome/common/media_galleries/picasa_types.h" |
19 | 20 |
20 namespace picasa { | 21 namespace picasa { |
21 | 22 |
22 class SafePicasaAlbumTableReader; | 23 class SafePicasaAlbumTableReader; |
24 class SafePicasaAlbumsIndexer; | |
23 | 25 |
24 // Created and owned by ImportedMediaGalleryRegistryTaskRunnerValues | 26 // Created and owned by ImportedMediaGalleryRegistryTaskRunnerValues |
25 class PicasaDataProvider { | 27 class PicasaDataProvider { |
26 public: | 28 public: |
27 explicit PicasaDataProvider(const base::FilePath& database_path); | 29 explicit PicasaDataProvider(const base::FilePath& database_path); |
28 virtual ~PicasaDataProvider(); | 30 virtual ~PicasaDataProvider(); |
29 | 31 |
30 // Ask the data provider to refresh the data if necessary. |ready_callback| | 32 // Ask the data provider to refresh the data if necessary. |ready_callback| |
31 // will be called when the data is up to date | 33 // will be called when the data is up to date. |refresh_album_contents| |
34 // is true if the caller wants the album contents also. | |
32 // TODO(tommycli): Investigate having the callback return a bool indicating | 35 // TODO(tommycli): Investigate having the callback return a bool indicating |
33 // success or failure - and handling it intelligently in PicasaFileUtil. | 36 // success or failure - and handling it intelligently in PicasaFileUtil. |
34 void RefreshData(const base::Closure& ready_callback); | 37 void RefreshData( |
38 bool need_albums_images, | |
39 const base::Closure& ready_callback); | |
35 | 40 |
41 // Notifies data provider that any currently cached data is stale. | |
42 void InvalidateData(); | |
vandebo (ex-Chrome)
2013/07/11 16:56:27
This should be handled internally.
tommycli
2013/07/11 21:19:17
Done.
| |
43 | |
44 // These methods return scoped_ptrs because we want to return a copy that | |
45 // will not change to the caller. | |
36 scoped_ptr<AlbumMap> GetAlbums(); | 46 scoped_ptr<AlbumMap> GetAlbums(); |
37 scoped_ptr<AlbumMap> GetFolders(); | 47 scoped_ptr<AlbumMap> GetFolders(); |
38 // TODO(tommycli): Implement album contents. GetAlbumContents(...) | 48 scoped_ptr<AlbumImagesMap> GetAlbumsImages(); |
39 | |
40 protected: | |
41 // Protected for test class usage. | |
42 void OnDataRefreshed(const base::Closure& ready_callback, | |
43 bool parse_success, const std::vector<AlbumInfo>& albums, | |
44 const std::vector<AlbumInfo>& folder); | |
45 | 49 |
46 private: | 50 private: |
51 enum DataState { | |
vandebo (ex-Chrome)
2013/07/11 16:56:27
nit: this can probably just be state instead of da
tommycli
2013/07/11 21:19:17
Done.
| |
52 NO_FRESH_DATA_STATE = 0, | |
vandebo (ex-Chrome)
2013/07/11 16:56:27
nit: omit = 0
vandebo (ex-Chrome)
2013/07/11 16:56:27
nit: STALE_DATA_STATE ?
tommycli
2013/07/11 21:19:17
Done.
tommycli
2013/07/11 21:19:17
Done.
| |
53 ALBUM_LIST_FRESH_STATE, | |
54 ALBUMS_IMAGES_FRESH_STATE | |
55 }; | |
56 | |
47 friend class PicasaFileUtilTest; | 57 friend class PicasaFileUtilTest; |
48 | 58 |
59 void EnsureAlbumListRefreshed(const base::Closure& ready_callback); | |
60 void EnsureAlbumsImagesRefreshed(const base::Closure& ready_callback); | |
61 | |
62 void OnAlbumListRefreshed(scoped_refptr<SafePicasaAlbumTableReader> reader, | |
63 bool parse_success, | |
64 const std::vector<AlbumInfo>& albums, | |
65 const std::vector<AlbumInfo>& folder); | |
66 | |
67 void OnAlbumsIndexerDone(scoped_refptr<SafePicasaAlbumsIndexer> indexer, | |
68 const picasa::AlbumImagesMap& albums_images); | |
69 | |
49 static std::string DateToPathString(const base::Time& time); | 70 static std::string DateToPathString(const base::Time& time); |
50 static void UniquifyNames(const std::vector<AlbumInfo>& info_list, | 71 static void UniquifyNames(const std::vector<AlbumInfo>& info_list, |
51 AlbumMap* result_map); | 72 AlbumMap* result_map); |
52 | 73 |
53 AlbumMap album_map_; | 74 AlbumMap album_map_; |
54 AlbumMap folder_map_; | 75 AlbumMap folder_map_; |
76 AlbumImagesMap albums_images_; | |
55 | 77 |
56 base::FilePath database_path_; | 78 base::FilePath database_path_; |
57 bool needs_refresh_; | |
58 | 79 |
80 DataState data_state_; | |
81 | |
82 // Callbacks that are waiting for their requested data to be ready. | |
83 std::queue<base::Closure> album_list_ready_callbacks_; | |
84 std::queue<base::Closure> albums_indexer_ready_callbacks_; | |
85 | |
86 // Stores the "live" in-flight utility processes. Callbacks from other | |
87 // (older) utility processes are stale and ignored. Only one of these should | |
88 // ever be non-NULL. | |
59 scoped_refptr<SafePicasaAlbumTableReader> album_table_reader_; | 89 scoped_refptr<SafePicasaAlbumTableReader> album_table_reader_; |
90 scoped_refptr<SafePicasaAlbumsIndexer> albums_indexer_; | |
60 | 91 |
61 base::WeakPtrFactory<PicasaDataProvider> weak_factory_; | 92 base::WeakPtrFactory<PicasaDataProvider> weak_factory_; |
62 | 93 |
63 DISALLOW_COPY_AND_ASSIGN(PicasaDataProvider); | 94 DISALLOW_COPY_AND_ASSIGN(PicasaDataProvider); |
64 }; | 95 }; |
65 | 96 |
66 } // namespace picasa | 97 } // namespace picasa |
67 | 98 |
68 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PICASA_DATA_PROVIDER_H_ | 99 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PICASA_DATA_PROVIDER_H_ |
OLD | NEW |