| 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_data_provider.h" | 5 #include "chrome/browser/media_galleries/fileapi/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" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 void PicasaDataProvider::OnTempDirChanged(const base::FilePath& temp_dir_path, | 135 void PicasaDataProvider::OnTempDirChanged(const base::FilePath& temp_dir_path, |
| 136 bool error) { | 136 bool error) { |
| 137 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 137 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 138 if (base::IsDirectoryEmpty(temp_dir_path)) | 138 if (base::IsDirectoryEmpty(temp_dir_path)) |
| 139 InvalidateData(); | 139 InvalidateData(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void PicasaDataProvider::DoRefreshIfNecessary() { | 142 void PicasaDataProvider::DoRefreshIfNecessary() { |
| 143 DCHECK(state_ != INVALID_DATA_STATE); | 143 DCHECK(state_ != INVALID_DATA_STATE); |
| 144 DCHECK(state_ != ALBUMS_IMAGES_FRESH_STATE); | 144 DCHECK(state_ != ALBUMS_IMAGES_FRESH_STATE); |
| 145 DCHECK(!(album_table_reader_ && albums_indexer_)); | 145 DCHECK(!(album_table_reader_.get() && albums_indexer_.get())); |
| 146 | 146 |
| 147 if (album_list_ready_callbacks_.empty() && | 147 if (album_list_ready_callbacks_.empty() && |
| 148 albums_index_ready_callbacks_.empty()) { | 148 albums_index_ready_callbacks_.empty()) { |
| 149 return; | 149 return; |
| 150 } | 150 } |
| 151 | 151 |
| 152 if (state_ == STALE_DATA_STATE) { | 152 if (state_ == STALE_DATA_STATE) { |
| 153 if (album_table_reader_) | 153 if (album_table_reader_.get()) |
| 154 return; | 154 return; |
| 155 album_table_reader_ = | 155 album_table_reader_ = |
| 156 new SafePicasaAlbumTableReader(AlbumTableFiles(database_path_)); | 156 new SafePicasaAlbumTableReader(AlbumTableFiles(database_path_)); |
| 157 album_table_reader_->Start( | 157 album_table_reader_->Start( |
| 158 base::Bind(&PicasaDataProvider::OnAlbumTableReaderDone, | 158 base::Bind(&PicasaDataProvider::OnAlbumTableReaderDone, |
| 159 weak_factory_.GetWeakPtr(), | 159 weak_factory_.GetWeakPtr(), |
| 160 album_table_reader_)); | 160 album_table_reader_)); |
| 161 } else { | 161 } else { |
| 162 DCHECK(state_ == LIST_OF_ALBUMS_AND_FOLDERS_FRESH_STATE); | 162 DCHECK(state_ == LIST_OF_ALBUMS_AND_FOLDERS_FRESH_STATE); |
| 163 if (albums_indexer_) | 163 if (albums_indexer_.get()) |
| 164 return; | 164 return; |
| 165 albums_indexer_ = new SafePicasaAlbumsIndexer(album_map_, folder_map_); | 165 albums_indexer_ = new SafePicasaAlbumsIndexer(album_map_, folder_map_); |
| 166 albums_indexer_->Start(base::Bind(&PicasaDataProvider::OnAlbumsIndexerDone, | 166 albums_indexer_->Start(base::Bind(&PicasaDataProvider::OnAlbumsIndexerDone, |
| 167 weak_factory_.GetWeakPtr(), | 167 weak_factory_.GetWeakPtr(), |
| 168 albums_indexer_)); | 168 albums_indexer_)); |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 void PicasaDataProvider::OnAlbumTableReaderDone( | 172 void PicasaDataProvider::OnAlbumTableReaderDone( |
| 173 scoped_refptr<SafePicasaAlbumTableReader> reader, | 173 scoped_refptr<SafePicasaAlbumTableReader> reader, |
| 174 bool parse_success, | 174 bool parse_success, |
| 175 const std::vector<AlbumInfo>& albums, | 175 const std::vector<AlbumInfo>& albums, |
| 176 const std::vector<AlbumInfo>& folders) { | 176 const std::vector<AlbumInfo>& folders) { |
| 177 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 177 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 178 // If the reader has already been deemed stale, ignore the result. | 178 // If the reader has already been deemed stale, ignore the result. |
| 179 if (reader != album_table_reader_) | 179 if (reader.get() != album_table_reader_.get()) |
| 180 return; | 180 return; |
| 181 album_table_reader_ = NULL; | 181 album_table_reader_ = NULL; |
| 182 | 182 |
| 183 DCHECK(state_ == STALE_DATA_STATE); | 183 DCHECK(state_ == STALE_DATA_STATE); |
| 184 | 184 |
| 185 if (!parse_success) { | 185 if (!parse_success) { |
| 186 // If we didn't get the list successfully, fail all those waiting for | 186 // If we didn't get the list successfully, fail all those waiting for |
| 187 // the albums indexer also. | 187 // the albums indexer also. |
| 188 state_ = INVALID_DATA_STATE; | 188 state_ = INVALID_DATA_STATE; |
| 189 RunAllCallbacks(&album_list_ready_callbacks_, false /* success */); | 189 RunAllCallbacks(&album_list_ready_callbacks_, false /* success */); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 202 // Chain from this process onto refreshing the albums images if necessary. | 202 // Chain from this process onto refreshing the albums images if necessary. |
| 203 DoRefreshIfNecessary(); | 203 DoRefreshIfNecessary(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void PicasaDataProvider::OnAlbumsIndexerDone( | 206 void PicasaDataProvider::OnAlbumsIndexerDone( |
| 207 scoped_refptr<SafePicasaAlbumsIndexer> indexer, | 207 scoped_refptr<SafePicasaAlbumsIndexer> indexer, |
| 208 bool success, | 208 bool success, |
| 209 const picasa::AlbumImagesMap& albums_images) { | 209 const picasa::AlbumImagesMap& albums_images) { |
| 210 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 210 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 211 // If the indexer has already been deemed stale, ignore the result. | 211 // If the indexer has already been deemed stale, ignore the result. |
| 212 if (indexer != albums_indexer_) | 212 if (indexer.get() != albums_indexer_.get()) |
| 213 return; | 213 return; |
| 214 albums_indexer_ = NULL; | 214 albums_indexer_ = NULL; |
| 215 | 215 |
| 216 DCHECK(state_ == LIST_OF_ALBUMS_AND_FOLDERS_FRESH_STATE); | 216 DCHECK(state_ == LIST_OF_ALBUMS_AND_FOLDERS_FRESH_STATE); |
| 217 | 217 |
| 218 if (success) { | 218 if (success) { |
| 219 state_ = ALBUMS_IMAGES_FRESH_STATE; | 219 state_ = ALBUMS_IMAGES_FRESH_STATE; |
| 220 | 220 |
| 221 albums_images_ = albums_images; | 221 albums_images_ = albums_images; |
| 222 } | 222 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 if (total_counts[name] != 1) { | 258 if (total_counts[name] != 1) { |
| 259 name = base::StringPrintf("%s (%d)", name.c_str(), | 259 name = base::StringPrintf("%s (%d)", name.c_str(), |
| 260 ++current_counts[name]); | 260 ++current_counts[name]); |
| 261 } | 261 } |
| 262 | 262 |
| 263 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])); |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 } // namespace picasa | 267 } // namespace picasa |
| OLD | NEW |