OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/drive/change_list_loader.h" | 5 #include "chrome/browser/chromeos/drive/change_list_loader.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 weak_ptr_factory_(this) { | 182 weak_ptr_factory_(this) { |
183 } | 183 } |
184 | 184 |
185 virtual ~FastFetchFeedFetcher() { | 185 virtual ~FastFetchFeedFetcher() { |
186 } | 186 } |
187 | 187 |
188 virtual void Run(const FeedFetcherCallback& callback) OVERRIDE { | 188 virtual void Run(const FeedFetcherCallback& callback) OVERRIDE { |
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
190 DCHECK(!callback.is_null()); | 190 DCHECK(!callback.is_null()); |
191 DCHECK(!directory_resource_id_.empty()); | 191 DCHECK(!directory_resource_id_.empty()); |
192 DCHECK(util::IsDriveV2ApiEnabled() || !root_folder_id_.empty()); | |
193 | 192 |
194 // Remember the time stamp for usage stats. | 193 // Remember the time stamp for usage stats. |
195 start_time_ = base::TimeTicks::Now(); | 194 start_time_ = base::TimeTicks::Now(); |
196 | 195 |
197 // We use WAPI's GetResourceListInDirectory even if Drive API v2 is | 196 // We use WAPI's GetResourceListInDirectory even if Drive API v2 is |
198 // enabled. This is the short term work around of the performance | 197 // enabled. This is the short term work around of the performance |
199 // regression. | 198 // regression. |
| 199 // TODO(hashimoto): Remove this. crbug.com/340931. |
200 | 200 |
201 std::string resource_id = directory_resource_id_; | 201 std::string resource_id = directory_resource_id_; |
202 if (util::IsDriveV2ApiEnabled() && | 202 if (directory_resource_id_ == root_folder_id_) { |
203 directory_resource_id_ == root_folder_id_) { | |
204 // GData WAPI doesn't accept the root directory id which is used in Drive | 203 // GData WAPI doesn't accept the root directory id which is used in Drive |
205 // API v2. So it is necessary to translate it here. | 204 // API v2. So it is necessary to translate it here. |
206 resource_id = util::kWapiRootDirectoryResourceId; | 205 resource_id = util::kWapiRootDirectoryResourceId; |
207 } | 206 } |
208 | 207 |
209 scheduler_->GetResourceListInDirectoryByWapi( | 208 scheduler_->GetResourceListInDirectoryByWapi( |
210 resource_id, | 209 resource_id, |
211 base::Bind(&FastFetchFeedFetcher::OnResourceListFetched, | 210 base::Bind(&FastFetchFeedFetcher::OnResourceListFetched, |
212 weak_ptr_factory_.GetWeakPtr(), callback)); | 211 weak_ptr_factory_.GetWeakPtr(), callback)); |
213 } | 212 } |
214 | 213 |
215 private: | 214 private: |
216 void OnResourceListFetched( | 215 void OnResourceListFetched( |
217 const FeedFetcherCallback& callback, | 216 const FeedFetcherCallback& callback, |
218 google_apis::GDataErrorCode status, | 217 google_apis::GDataErrorCode status, |
219 scoped_ptr<google_apis::ResourceList> resource_list) { | 218 scoped_ptr<google_apis::ResourceList> resource_list) { |
220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
221 DCHECK(!callback.is_null()); | 220 DCHECK(!callback.is_null()); |
222 | 221 |
223 FileError error = GDataToFileError(status); | 222 FileError error = GDataToFileError(status); |
224 if (error != FILE_ERROR_OK) { | 223 if (error != FILE_ERROR_OK) { |
225 callback.Run(error, ScopedVector<ChangeList>()); | 224 callback.Run(error, ScopedVector<ChangeList>()); |
226 return; | 225 return; |
227 } | 226 } |
228 | 227 |
229 // Add the current change list to the list of collected lists. | 228 // Add the current change list to the list of collected lists. |
230 DCHECK(resource_list); | 229 DCHECK(resource_list); |
231 ChangeList* change_list = new ChangeList(*resource_list); | 230 ChangeList* change_list = new ChangeList(*resource_list); |
232 if (util::IsDriveV2ApiEnabled()) | 231 FixResourceIdInChangeList(change_list); |
233 FixResourceIdInChangeList(change_list); | |
234 change_lists_.push_back(change_list); | 232 change_lists_.push_back(change_list); |
235 | 233 |
236 GURL next_url; | 234 GURL next_url; |
237 if (resource_list->GetNextFeedURL(&next_url) && !next_url.is_empty()) { | 235 if (resource_list->GetNextFeedURL(&next_url) && !next_url.is_empty()) { |
238 // There is the remaining result so fetch it. | 236 // There is the remaining result so fetch it. |
239 scheduler_->GetRemainingResourceList( | 237 scheduler_->GetRemainingResourceList( |
240 next_url, | 238 next_url, |
241 base::Bind(&FastFetchFeedFetcher::OnResourceListFetched, | 239 base::Bind(&FastFetchFeedFetcher::OnResourceListFetched, |
242 weak_ptr_factory_.GetWeakPtr(), callback)); | 240 weak_ptr_factory_.GetWeakPtr(), callback)); |
243 return; | 241 return; |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 callback.Run(error); | 985 callback.Run(error); |
988 // Also notify the observers. | 986 // Also notify the observers. |
989 if (error == FILE_ERROR_OK && !directory_path->empty()) { | 987 if (error == FILE_ERROR_OK && !directory_path->empty()) { |
990 FOR_EACH_OBSERVER(ChangeListLoaderObserver, observers_, | 988 FOR_EACH_OBSERVER(ChangeListLoaderObserver, observers_, |
991 OnDirectoryChanged(*directory_path)); | 989 OnDirectoryChanged(*directory_path)); |
992 } | 990 } |
993 } | 991 } |
994 | 992 |
995 } // namespace internal | 993 } // namespace internal |
996 } // namespace drive | 994 } // namespace drive |
OLD | NEW |