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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/synchronization/cancellation_flag.h" | 13 #include "base/synchronization/cancellation_flag.h" |
| 14 #include "base/thread_task_runner_handle.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "chrome/browser/chromeos/drive/change_list_loader_observer.h" | 16 #include "chrome/browser/chromeos/drive/change_list_loader_observer.h" |
16 #include "chrome/browser/chromeos/drive/change_list_processor.h" | 17 #include "chrome/browser/chromeos/drive/change_list_processor.h" |
17 #include "chrome/browser/chromeos/drive/file_system_util.h" | 18 #include "chrome/browser/chromeos/drive/file_system_util.h" |
18 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 19 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
19 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 20 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
20 #include "chrome/browser/drive/event_logger.h" | 21 #include "chrome/browser/drive/event_logger.h" |
21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
22 #include "google_apis/drive/drive_api_parser.h" | 23 #include "google_apis/drive/drive_api_parser.h" |
23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 220 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
220 DCHECK(!callback.is_null()); | 221 DCHECK(!callback.is_null()); |
221 | 222 |
222 // If the latest UpdateAboutResource task is still running. Wait for it, | 223 // If the latest UpdateAboutResource task is still running. Wait for it, |
223 if (pending_callbacks_.count(current_update_task_id_)) { | 224 if (pending_callbacks_.count(current_update_task_id_)) { |
224 pending_callbacks_[current_update_task_id_].push_back(callback); | 225 pending_callbacks_[current_update_task_id_].push_back(callback); |
225 return; | 226 return; |
226 } | 227 } |
227 | 228 |
228 if (cached_about_resource_) { | 229 if (cached_about_resource_) { |
229 base::MessageLoopProxy::current()->PostTask( | 230 base::ThreadTaskRunnerHandle::Get()->PostTask( |
230 FROM_HERE, | 231 FROM_HERE, |
231 base::Bind( | 232 base::Bind( |
232 callback, | 233 callback, google_apis::HTTP_NO_CONTENT, |
233 google_apis::HTTP_NO_CONTENT, | |
234 base::Passed(scoped_ptr<google_apis::AboutResource>( | 234 base::Passed(scoped_ptr<google_apis::AboutResource>( |
235 new google_apis::AboutResource(*cached_about_resource_))))); | 235 new google_apis::AboutResource(*cached_about_resource_))))); |
236 } else { | 236 } else { |
237 UpdateAboutResource(callback); | 237 UpdateAboutResource(callback); |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 void AboutResourceLoader::UpdateAboutResource( | 241 void AboutResourceLoader::UpdateAboutResource( |
242 const google_apis::AboutResourceCallback& callback) { | 242 const google_apis::AboutResourceCallback& callback) { |
243 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 243 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 454 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
455 | 455 |
456 if (!loaded_ && error == FILE_ERROR_OK) { | 456 if (!loaded_ && error == FILE_ERROR_OK) { |
457 loaded_ = true; | 457 loaded_ = true; |
458 FOR_EACH_OBSERVER(ChangeListLoaderObserver, | 458 FOR_EACH_OBSERVER(ChangeListLoaderObserver, |
459 observers_, | 459 observers_, |
460 OnInitialLoadComplete()); | 460 OnInitialLoadComplete()); |
461 } | 461 } |
462 | 462 |
463 for (size_t i = 0; i < pending_load_callback_.size(); ++i) { | 463 for (size_t i = 0; i < pending_load_callback_.size(); ++i) { |
464 base::MessageLoopProxy::current()->PostTask( | 464 base::ThreadTaskRunnerHandle::Get()->PostTask( |
465 FROM_HERE, | 465 FROM_HERE, base::Bind(pending_load_callback_[i], error)); |
466 base::Bind(pending_load_callback_[i], error)); | |
467 } | 466 } |
468 pending_load_callback_.clear(); | 467 pending_load_callback_.clear(); |
469 | 468 |
470 // If there is pending update check, try to load the change from the server | 469 // If there is pending update check, try to load the change from the server |
471 // again, because there may exist an update during the completed loading. | 470 // again, because there may exist an update during the completed loading. |
472 if (!pending_update_check_callback_.is_null()) { | 471 if (!pending_update_check_callback_.is_null()) { |
473 Load(base::ResetAndReturn(&pending_update_check_callback_)); | 472 Load(base::ResetAndReturn(&pending_update_check_callback_)); |
474 } | 473 } |
475 } | 474 } |
476 | 475 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 | 576 |
578 OnChangeListLoadComplete(error); | 577 OnChangeListLoadComplete(error); |
579 | 578 |
580 FOR_EACH_OBSERVER(ChangeListLoaderObserver, | 579 FOR_EACH_OBSERVER(ChangeListLoaderObserver, |
581 observers_, | 580 observers_, |
582 OnLoadFromServerComplete()); | 581 OnLoadFromServerComplete()); |
583 } | 582 } |
584 | 583 |
585 } // namespace internal | 584 } // namespace internal |
586 } // namespace drive | 585 } // namespace drive |
OLD | NEW |