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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 start_time_ = base::TimeTicks::Now(); | 55 start_time_ = base::TimeTicks::Now(); |
56 | 56 |
57 // This is full resource list fetch. | 57 // This is full resource list fetch. |
58 scheduler_->GetAllFileList( | 58 scheduler_->GetAllFileList( |
59 base::Bind(&FullFeedFetcher::OnFileListFetched, | 59 base::Bind(&FullFeedFetcher::OnFileListFetched, |
60 weak_ptr_factory_.GetWeakPtr(), callback)); | 60 weak_ptr_factory_.GetWeakPtr(), callback)); |
61 } | 61 } |
62 | 62 |
63 private: | 63 private: |
64 void OnFileListFetched(const FeedFetcherCallback& callback, | 64 void OnFileListFetched(const FeedFetcherCallback& callback, |
65 google_apis::GDataErrorCode status, | 65 google_apis::DriveApiErrorCode status, |
66 scoped_ptr<google_apis::FileList> file_list) { | 66 scoped_ptr<google_apis::FileList> file_list) { |
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
68 DCHECK(!callback.is_null()); | 68 DCHECK(!callback.is_null()); |
69 | 69 |
70 FileError error = GDataToFileError(status); | 70 FileError error = GDataToFileError(status); |
71 if (error != FILE_ERROR_OK) { | 71 if (error != FILE_ERROR_OK) { |
72 callback.Run(error, ScopedVector<ChangeList>()); | 72 callback.Run(error, ScopedVector<ChangeList>()); |
73 return; | 73 return; |
74 } | 74 } |
75 | 75 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 DCHECK(!callback.is_null()); | 117 DCHECK(!callback.is_null()); |
118 | 118 |
119 scheduler_->GetChangeList( | 119 scheduler_->GetChangeList( |
120 start_change_id_, | 120 start_change_id_, |
121 base::Bind(&DeltaFeedFetcher::OnChangeListFetched, | 121 base::Bind(&DeltaFeedFetcher::OnChangeListFetched, |
122 weak_ptr_factory_.GetWeakPtr(), callback)); | 122 weak_ptr_factory_.GetWeakPtr(), callback)); |
123 } | 123 } |
124 | 124 |
125 private: | 125 private: |
126 void OnChangeListFetched(const FeedFetcherCallback& callback, | 126 void OnChangeListFetched(const FeedFetcherCallback& callback, |
127 google_apis::GDataErrorCode status, | 127 google_apis::DriveApiErrorCode status, |
128 scoped_ptr<google_apis::ChangeList> change_list) { | 128 scoped_ptr<google_apis::ChangeList> change_list) { |
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
130 DCHECK(!callback.is_null()); | 130 DCHECK(!callback.is_null()); |
131 | 131 |
132 FileError error = GDataToFileError(status); | 132 FileError error = GDataToFileError(status); |
133 if (error != FILE_ERROR_OK) { | 133 if (error != FILE_ERROR_OK) { |
134 callback.Run(error, ScopedVector<ChangeList>()); | 134 callback.Run(error, ScopedVector<ChangeList>()); |
135 return; | 135 return; |
136 } | 136 } |
137 | 137 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 pending_callbacks_[current_update_task_id_].push_back(callback); | 246 pending_callbacks_[current_update_task_id_].push_back(callback); |
247 | 247 |
248 scheduler_->GetAboutResource( | 248 scheduler_->GetAboutResource( |
249 base::Bind(&AboutResourceLoader::UpdateAboutResourceAfterGetAbout, | 249 base::Bind(&AboutResourceLoader::UpdateAboutResourceAfterGetAbout, |
250 weak_ptr_factory_.GetWeakPtr(), | 250 weak_ptr_factory_.GetWeakPtr(), |
251 current_update_task_id_)); | 251 current_update_task_id_)); |
252 } | 252 } |
253 | 253 |
254 void AboutResourceLoader::UpdateAboutResourceAfterGetAbout( | 254 void AboutResourceLoader::UpdateAboutResourceAfterGetAbout( |
255 int task_id, | 255 int task_id, |
256 google_apis::GDataErrorCode status, | 256 google_apis::DriveApiErrorCode status, |
257 scoped_ptr<google_apis::AboutResource> about_resource) { | 257 scoped_ptr<google_apis::AboutResource> about_resource) { |
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
259 FileError error = GDataToFileError(status); | 259 FileError error = GDataToFileError(status); |
260 | 260 |
261 const std::vector<google_apis::AboutResourceCallback> callbacks = | 261 const std::vector<google_apis::AboutResourceCallback> callbacks = |
262 pending_callbacks_[task_id]; | 262 pending_callbacks_[task_id]; |
263 pending_callbacks_.erase(task_id); | 263 pending_callbacks_.erase(task_id); |
264 | 264 |
265 if (error != FILE_ERROR_OK) { | 265 if (error != FILE_ERROR_OK) { |
266 for (size_t i = 0; i < callbacks.size(); ++i) | 266 for (size_t i = 0; i < callbacks.size(); ++i) |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 } | 408 } |
409 | 409 |
410 about_resource_loader_->GetAboutResource( | 410 about_resource_loader_->GetAboutResource( |
411 base::Bind(&ChangeListLoader::LoadAfterGetAboutResource, | 411 base::Bind(&ChangeListLoader::LoadAfterGetAboutResource, |
412 weak_ptr_factory_.GetWeakPtr(), | 412 weak_ptr_factory_.GetWeakPtr(), |
413 *local_changestamp)); | 413 *local_changestamp)); |
414 } | 414 } |
415 | 415 |
416 void ChangeListLoader::LoadAfterGetAboutResource( | 416 void ChangeListLoader::LoadAfterGetAboutResource( |
417 int64 local_changestamp, | 417 int64 local_changestamp, |
418 google_apis::GDataErrorCode status, | 418 google_apis::DriveApiErrorCode status, |
419 scoped_ptr<google_apis::AboutResource> about_resource) { | 419 scoped_ptr<google_apis::AboutResource> about_resource) { |
420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
421 | 421 |
422 FileError error = GDataToFileError(status); | 422 FileError error = GDataToFileError(status); |
423 if (error != FILE_ERROR_OK) { | 423 if (error != FILE_ERROR_OK) { |
424 OnChangeListLoadComplete(error); | 424 OnChangeListLoadComplete(error); |
425 return; | 425 return; |
426 } | 426 } |
427 | 427 |
428 DCHECK(about_resource); | 428 DCHECK(about_resource); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 pending_load_callback_.clear(); | 462 pending_load_callback_.clear(); |
463 | 463 |
464 // If there is pending update check, try to load the change from the server | 464 // If there is pending update check, try to load the change from the server |
465 // again, because there may exist an update during the completed loading. | 465 // again, because there may exist an update during the completed loading. |
466 if (!pending_update_check_callback_.is_null()) { | 466 if (!pending_update_check_callback_.is_null()) { |
467 Load(base::ResetAndReturn(&pending_update_check_callback_)); | 467 Load(base::ResetAndReturn(&pending_update_check_callback_)); |
468 } | 468 } |
469 } | 469 } |
470 | 470 |
471 void ChangeListLoader::OnAboutResourceUpdated( | 471 void ChangeListLoader::OnAboutResourceUpdated( |
472 google_apis::GDataErrorCode error, | 472 google_apis::DriveApiErrorCode error, |
473 scoped_ptr<google_apis::AboutResource> resource) { | 473 scoped_ptr<google_apis::AboutResource> resource) { |
474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
475 | 475 |
476 if (drive::GDataToFileError(error) != drive::FILE_ERROR_OK) { | 476 if (drive::GDataToFileError(error) != drive::FILE_ERROR_OK) { |
477 logger_->Log(logging::LOG_ERROR, | 477 logger_->Log(logging::LOG_ERROR, |
478 "Failed to update the about resource: %s", | 478 "Failed to update the about resource: %s", |
479 google_apis::GDataErrorCodeToString(error).c_str()); | 479 google_apis::DriveApiErrorCodeToString(error).c_str()); |
480 return; | 480 return; |
481 } | 481 } |
482 logger_->Log(logging::LOG_INFO, | 482 logger_->Log(logging::LOG_INFO, |
483 "About resource updated to: %s", | 483 "About resource updated to: %s", |
484 base::Int64ToString(resource->largest_change_id()).c_str()); | 484 base::Int64ToString(resource->largest_change_id()).c_str()); |
485 } | 485 } |
486 | 486 |
487 void ChangeListLoader::LoadChangeListFromServer(int64 start_changestamp) { | 487 void ChangeListLoader::LoadChangeListFromServer(int64 start_changestamp) { |
488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
489 DCHECK(!change_feed_fetcher_); | 489 DCHECK(!change_feed_fetcher_); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 571 |
572 OnChangeListLoadComplete(error); | 572 OnChangeListLoadComplete(error); |
573 | 573 |
574 FOR_EACH_OBSERVER(ChangeListLoaderObserver, | 574 FOR_EACH_OBSERVER(ChangeListLoaderObserver, |
575 observers_, | 575 observers_, |
576 OnLoadFromServerComplete()); | 576 OnLoadFromServerComplete()); |
577 } | 577 } |
578 | 578 |
579 } // namespace internal | 579 } // namespace internal |
580 } // namespace drive | 580 } // namespace drive |
OLD | NEW |