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

Side by Side Diff: chrome/browser/media_galleries/fileapi/picasa_data_provider.cc

Issue 2318133002: Remove call to IsRunningSequenceOnCurrentThread() in media_file_system_backend.cc (Closed)
Patch Set: Leaky LazyInstance Created 4 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
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 #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/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 23 matching lines...) Expand all
34 } 34 }
35 ready_callbacks->clear(); 35 ready_callbacks->clear();
36 } 36 }
37 37
38 } // namespace 38 } // namespace
39 39
40 PicasaDataProvider::PicasaDataProvider(const base::FilePath& database_path) 40 PicasaDataProvider::PicasaDataProvider(const base::FilePath& database_path)
41 : database_path_(database_path), 41 : database_path_(database_path),
42 state_(STALE_DATA_STATE), 42 state_(STALE_DATA_STATE),
43 weak_factory_(this) { 43 weak_factory_(this) {
44 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); 44 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
45 45
46 StartFilePathWatchOnMediaTaskRunner( 46 StartFilePathWatchOnMediaTaskRunner(
47 database_path_.DirName().AppendASCII(kPicasaTempDirName), 47 database_path_.DirName().AppendASCII(kPicasaTempDirName),
48 base::Bind(&PicasaDataProvider::OnTempDirWatchStarted, 48 base::Bind(&PicasaDataProvider::OnTempDirWatchStarted,
49 weak_factory_.GetWeakPtr()), 49 weak_factory_.GetWeakPtr()),
50 base::Bind(&PicasaDataProvider::OnTempDirChanged, 50 base::Bind(&PicasaDataProvider::OnTempDirChanged,
51 weak_factory_.GetWeakPtr())); 51 weak_factory_.GetWeakPtr()));
52 } 52 }
53 53
54 PicasaDataProvider::~PicasaDataProvider() {} 54 PicasaDataProvider::~PicasaDataProvider() {}
55 55
56 void PicasaDataProvider::RefreshData(DataType needed_data, 56 void PicasaDataProvider::RefreshData(DataType needed_data,
57 const ReadyCallback& ready_callback) { 57 const ReadyCallback& ready_callback) {
58 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); 58 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
59 // TODO(tommycli): Need to watch the database_path_ folder and handle 59 // TODO(tommycli): Need to watch the database_path_ folder and handle
60 // rereading the data when it changes. 60 // rereading the data when it changes.
61 61
62 if (state_ == INVALID_DATA_STATE) { 62 if (state_ == INVALID_DATA_STATE) {
63 ready_callback.Run(false /* success */); 63 ready_callback.Run(false /* success */);
64 return; 64 return;
65 } 65 }
66 66
67 if (needed_data == LIST_OF_ALBUMS_AND_FOLDERS_DATA) { 67 if (needed_data == LIST_OF_ALBUMS_AND_FOLDERS_DATA) {
68 if (state_ == LIST_OF_ALBUMS_AND_FOLDERS_FRESH_STATE || 68 if (state_ == LIST_OF_ALBUMS_AND_FOLDERS_FRESH_STATE ||
69 state_ == ALBUMS_IMAGES_FRESH_STATE) { 69 state_ == ALBUMS_IMAGES_FRESH_STATE) {
70 ready_callback.Run(true /* success */); 70 ready_callback.Run(true /* success */);
71 return; 71 return;
72 } 72 }
73 album_list_ready_callbacks_.push_back(ready_callback); 73 album_list_ready_callbacks_.push_back(ready_callback);
74 } else { 74 } else {
75 if (state_ == ALBUMS_IMAGES_FRESH_STATE) { 75 if (state_ == ALBUMS_IMAGES_FRESH_STATE) {
76 ready_callback.Run(true /* success */); 76 ready_callback.Run(true /* success */);
77 return; 77 return;
78 } 78 }
79 albums_index_ready_callbacks_.push_back(ready_callback); 79 albums_index_ready_callbacks_.push_back(ready_callback);
80 } 80 }
81 DoRefreshIfNecessary(); 81 DoRefreshIfNecessary();
82 } 82 }
83 83
84 std::unique_ptr<AlbumMap> PicasaDataProvider::GetFolders() { 84 std::unique_ptr<AlbumMap> PicasaDataProvider::GetFolders() {
85 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); 85 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
86 DCHECK(state_ == LIST_OF_ALBUMS_AND_FOLDERS_FRESH_STATE || 86 DCHECK(state_ == LIST_OF_ALBUMS_AND_FOLDERS_FRESH_STATE ||
87 state_ == ALBUMS_IMAGES_FRESH_STATE); 87 state_ == ALBUMS_IMAGES_FRESH_STATE);
88 return base::WrapUnique(new AlbumMap(folder_map_)); 88 return base::WrapUnique(new AlbumMap(folder_map_));
89 } 89 }
90 90
91 std::unique_ptr<AlbumMap> PicasaDataProvider::GetAlbums() { 91 std::unique_ptr<AlbumMap> PicasaDataProvider::GetAlbums() {
92 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); 92 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
93 DCHECK(state_ == LIST_OF_ALBUMS_AND_FOLDERS_FRESH_STATE || 93 DCHECK(state_ == LIST_OF_ALBUMS_AND_FOLDERS_FRESH_STATE ||
94 state_ == ALBUMS_IMAGES_FRESH_STATE); 94 state_ == ALBUMS_IMAGES_FRESH_STATE);
95 return base::WrapUnique(new AlbumMap(album_map_)); 95 return base::WrapUnique(new AlbumMap(album_map_));
96 } 96 }
97 97
98 std::unique_ptr<AlbumImages> PicasaDataProvider::FindAlbumImages( 98 std::unique_ptr<AlbumImages> PicasaDataProvider::FindAlbumImages(
99 const std::string& key, 99 const std::string& key,
100 base::File::Error* error) { 100 base::File::Error* error) {
101 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); 101 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
102 DCHECK(state_ == ALBUMS_IMAGES_FRESH_STATE); 102 DCHECK(state_ == ALBUMS_IMAGES_FRESH_STATE);
103 DCHECK(error); 103 DCHECK(error);
104 104
105 AlbumImagesMap::const_iterator it = albums_images_.find(key); 105 AlbumImagesMap::const_iterator it = albums_images_.find(key);
106 106
107 if (it == albums_images_.end()) { 107 if (it == albums_images_.end()) {
108 *error = base::File::FILE_ERROR_NOT_FOUND; 108 *error = base::File::FILE_ERROR_NOT_FOUND;
109 return std::unique_ptr<AlbumImages>(); 109 return std::unique_ptr<AlbumImages>();
110 } 110 }
111 111
112 *error = base::File::FILE_OK; 112 *error = base::File::FILE_OK;
113 return base::WrapUnique(new AlbumImages(it->second)); 113 return base::WrapUnique(new AlbumImages(it->second));
114 } 114 }
115 115
116 void PicasaDataProvider::InvalidateData() { 116 void PicasaDataProvider::InvalidateData() {
117 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); 117 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
118 118
119 // 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.
120 // TODO(tommycli): Implement and call Cancel function for these 120 // TODO(tommycli): Implement and call Cancel function for these
121 // UtilityProcessHostClients to actually kill the in-flight processes. 121 // UtilityProcessHostClients to actually kill the in-flight processes.
122 state_ = STALE_DATA_STATE; 122 state_ = STALE_DATA_STATE;
123 album_table_reader_ = NULL; 123 album_table_reader_ = NULL;
124 albums_indexer_ = NULL; 124 albums_indexer_ = NULL;
125 125
126 DoRefreshIfNecessary(); 126 DoRefreshIfNecessary();
127 } 127 }
128 128
129 void PicasaDataProvider::OnTempDirWatchStarted( 129 void PicasaDataProvider::OnTempDirWatchStarted(
130 std::unique_ptr<base::FilePathWatcher> temp_dir_watcher) { 130 std::unique_ptr<base::FilePathWatcher> temp_dir_watcher) {
131 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); 131 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
132 temp_dir_watcher_.reset(temp_dir_watcher.release()); 132 temp_dir_watcher_.reset(temp_dir_watcher.release());
133 } 133 }
134 134
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 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
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_.get() && albums_indexer_.get())); 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() &&
(...skipping 19 matching lines...) Expand all
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 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
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.get() != album_table_reader_.get()) 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.
(...skipping 12 matching lines...) Expand all
200 RunAllCallbacks(&album_list_ready_callbacks_, parse_success); 200 RunAllCallbacks(&album_list_ready_callbacks_, parse_success);
201 201
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 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence();
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.get() != albums_indexer_.get()) 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
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698