| 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 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" | 5 #include "chrome/browser/media_galleries/fileapi/picasa/picasa_data_provider.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" |
| 12 #include "base/file_util.h" |
| 11 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/browser/media_galleries/fileapi/file_path_watcher_util.h" |
| 12 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 15 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
| 13 #include "chrome/browser/media_galleries/fileapi/safe_picasa_album_table_reader.
h" | 16 #include "chrome/browser/media_galleries/fileapi/safe_picasa_album_table_reader.
h" |
| 14 #include "chrome/browser/media_galleries/fileapi/safe_picasa_albums_indexer.h" | 17 #include "chrome/browser/media_galleries/fileapi/safe_picasa_albums_indexer.h" |
| 15 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" | 18 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" |
| 16 #include "webkit/browser/fileapi/file_system_operation_context.h" | 19 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 17 #include "webkit/browser/fileapi/file_system_url.h" | 20 #include "webkit/browser/fileapi/file_system_url.h" |
| 18 | 21 |
| 19 using chrome::MediaFileSystemBackend; | 22 using chrome::MediaFileSystemBackend; |
| 20 | 23 |
| 21 namespace picasa { | 24 namespace picasa { |
| 22 | 25 |
| 23 namespace { | 26 namespace { |
| 24 | 27 |
| 25 void RunAllCallbacks( | 28 void RunAllCallbacks( |
| 26 std::queue<PicasaDataProvider::ReadyCallback>* ready_callbacks_queue, | 29 std::queue<PicasaDataProvider::ReadyCallback>* ready_callbacks_queue, |
| 27 bool success) { | 30 bool success) { |
| 28 while (!ready_callbacks_queue->empty()) { | 31 while (!ready_callbacks_queue->empty()) { |
| 29 ready_callbacks_queue->front().Run(success); | 32 ready_callbacks_queue->front().Run(success); |
| 30 ready_callbacks_queue->pop(); | 33 ready_callbacks_queue->pop(); |
| 31 } | 34 } |
| 32 } | 35 } |
| 33 | 36 |
| 34 } // namespace | 37 } // namespace |
| 35 | 38 |
| 36 PicasaDataProvider::PicasaDataProvider(const base::FilePath& database_path) | 39 PicasaDataProvider::PicasaDataProvider(const base::FilePath& database_path) |
| 37 : database_path_(database_path), | 40 : database_path_(database_path), |
| 38 state_(STALE_DATA_STATE), | 41 state_(STALE_DATA_STATE), |
| 39 weak_factory_(this) { | 42 weak_factory_(this) { |
| 40 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 43 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 44 |
| 45 chrome::StartFilePathWatchOnMediaTaskRunner( |
| 46 database_path_.DirName().AppendASCII(kPicasaTempDirName), |
| 47 true /* recursive */, |
| 48 base::Bind(&PicasaDataProvider::OnTempDirWatchStarted, |
| 49 weak_factory_.GetWeakPtr()), |
| 50 base::Bind(&PicasaDataProvider::OnTempDirChanged, |
| 51 weak_factory_.GetWeakPtr())); |
| 41 } | 52 } |
| 42 | 53 |
| 43 PicasaDataProvider::~PicasaDataProvider() {} | 54 PicasaDataProvider::~PicasaDataProvider() {} |
| 44 | 55 |
| 45 void PicasaDataProvider::RefreshData(DataType needed_data, | 56 void PicasaDataProvider::RefreshData(DataType needed_data, |
| 46 const ReadyCallback& ready_callback) { | 57 const ReadyCallback& ready_callback) { |
| 47 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 58 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 48 // TODO(tommycli): Need to watch the database_path_ folder and handle | 59 // TODO(tommycli): Need to watch the database_path_ folder and handle |
| 49 // rereading the data when it changes. | 60 // rereading the data when it changes. |
| 50 | 61 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // Set data state to stale and ignore responses from any in-flight processes. | 119 // Set data state to stale and ignore responses from any in-flight processes. |
| 109 // TODO(tommycli): Implement and call Cancel function for these | 120 // TODO(tommycli): Implement and call Cancel function for these |
| 110 // UtilityProcessHostClients to actually kill the in-flight processes. | 121 // UtilityProcessHostClients to actually kill the in-flight processes. |
| 111 state_ = STALE_DATA_STATE; | 122 state_ = STALE_DATA_STATE; |
| 112 album_table_reader_ = NULL; | 123 album_table_reader_ = NULL; |
| 113 albums_indexer_ = NULL; | 124 albums_indexer_ = NULL; |
| 114 | 125 |
| 115 DoRefreshIfNecessary(); | 126 DoRefreshIfNecessary(); |
| 116 } | 127 } |
| 117 | 128 |
| 129 void PicasaDataProvider::OnTempDirWatchStarted( |
| 130 scoped_ptr<base::FilePathWatcher> temp_dir_watcher) { |
| 131 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 132 temp_dir_watcher_.reset(temp_dir_watcher.release()); |
| 133 } |
| 134 |
| 135 void PicasaDataProvider::OnTempDirChanged(const base::FilePath& temp_dir_path, |
| 136 bool error) { |
| 137 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 138 if (file_util::IsDirectoryEmpty(temp_dir_path)) |
| 139 InvalidateData(); |
| 140 } |
| 141 |
| 118 void PicasaDataProvider::DoRefreshIfNecessary() { | 142 void PicasaDataProvider::DoRefreshIfNecessary() { |
| 119 DCHECK(state_ != INVALID_DATA_STATE); | 143 DCHECK(state_ != INVALID_DATA_STATE); |
| 120 DCHECK(state_ != ALBUMS_IMAGES_FRESH_STATE); | 144 DCHECK(state_ != ALBUMS_IMAGES_FRESH_STATE); |
| 121 DCHECK(!(album_table_reader_ && albums_indexer_)); | 145 DCHECK(!(album_table_reader_ && albums_indexer_)); |
| 122 | 146 |
| 123 if (album_list_ready_callbacks_.empty() && | 147 if (album_list_ready_callbacks_.empty() && |
| 124 albums_index_ready_callbacks_.empty()) { | 148 albums_index_ready_callbacks_.empty()) { |
| 125 return; | 149 return; |
| 126 } | 150 } |
| 127 | 151 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 257 |
| 234 if (total_counts[name] != 1) { | 258 if (total_counts[name] != 1) { |
| 235 name = base::StringPrintf("%s (%d)", name.c_str(), | 259 name = base::StringPrintf("%s (%d)", name.c_str(), |
| 236 ++current_counts[name]); | 260 ++current_counts[name]); |
| 237 } | 261 } |
| 238 | 262 |
| 239 result_map->insert(std::pair<std::string, AlbumInfo>(name, info_list[i])); | 263 result_map->insert(std::pair<std::string, AlbumInfo>(name, info_list[i])); |
| 240 } | 264 } |
| 241 } | 265 } |
| 242 | 266 |
| 243 void PicasaDataProvider::SetDatabasePathForTesting( | |
| 244 const base::FilePath& database_path) { | |
| 245 database_path_ = database_path; | |
| 246 } | |
| 247 | |
| 248 void PicasaDataProvider::SetAlbumMapsForTesting(const AlbumMap& album_map, | |
| 249 const AlbumMap& folder_map) { | |
| 250 album_map_ = album_map; | |
| 251 folder_map_ = folder_map; | |
| 252 } | |
| 253 | |
| 254 } // namespace picasa | 267 } // namespace picasa |
| OLD | NEW |