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, |
233 google_apis::HTTP_NO_CONTENT, | 234 google_apis::HTTP_NO_CONTENT, |
234 base::Passed(scoped_ptr<google_apis::AboutResource>( | 235 base::Passed(scoped_ptr<google_apis::AboutResource>( |
235 new google_apis::AboutResource(*cached_about_resource_))))); | 236 new google_apis::AboutResource(*cached_about_resource_))))); |
236 } else { | 237 } else { |
237 UpdateAboutResource(callback); | 238 UpdateAboutResource(callback); |
238 } | 239 } |
239 } | 240 } |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 455 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
455 | 456 |
456 if (!loaded_ && error == FILE_ERROR_OK) { | 457 if (!loaded_ && error == FILE_ERROR_OK) { |
457 loaded_ = true; | 458 loaded_ = true; |
458 FOR_EACH_OBSERVER(ChangeListLoaderObserver, | 459 FOR_EACH_OBSERVER(ChangeListLoaderObserver, |
459 observers_, | 460 observers_, |
460 OnInitialLoadComplete()); | 461 OnInitialLoadComplete()); |
461 } | 462 } |
462 | 463 |
463 for (size_t i = 0; i < pending_load_callback_.size(); ++i) { | 464 for (size_t i = 0; i < pending_load_callback_.size(); ++i) { |
464 base::MessageLoopProxy::current()->PostTask( | 465 base::ThreadTaskRunnerHandle::Get()->PostTask( |
465 FROM_HERE, | 466 FROM_HERE, |
466 base::Bind(pending_load_callback_[i], error)); | 467 base::Bind(pending_load_callback_[i], error)); |
467 } | 468 } |
468 pending_load_callback_.clear(); | 469 pending_load_callback_.clear(); |
469 | 470 |
470 // If there is pending update check, try to load the change from the server | 471 // 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. | 472 // again, because there may exist an update during the completed loading. |
472 if (!pending_update_check_callback_.is_null()) { | 473 if (!pending_update_check_callback_.is_null()) { |
473 Load(base::ResetAndReturn(&pending_update_check_callback_)); | 474 Load(base::ResetAndReturn(&pending_update_check_callback_)); |
474 } | 475 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 | 578 |
578 OnChangeListLoadComplete(error); | 579 OnChangeListLoadComplete(error); |
579 | 580 |
580 FOR_EACH_OBSERVER(ChangeListLoaderObserver, | 581 FOR_EACH_OBSERVER(ChangeListLoaderObserver, |
581 observers_, | 582 observers_, |
582 OnLoadFromServerComplete()); | 583 OnLoadFromServerComplete()); |
583 } | 584 } |
584 | 585 |
585 } // namespace internal | 586 } // namespace internal |
586 } // namespace drive | 587 } // namespace drive |
OLD | NEW |