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 "components/drive/change_list_loader.h" | 5 #include "components/drive/change_list_loader.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 |
7 #include <set> | 9 #include <set> |
8 | 10 |
9 #include "base/callback.h" | 11 #include "base/callback.h" |
10 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/macros.h" |
11 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
12 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
13 #include "base/synchronization/cancellation_flag.h" | 16 #include "base/synchronization/cancellation_flag.h" |
14 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
15 #include "base/time/time.h" | 18 #include "base/time/time.h" |
16 #include "components/drive/change_list_loader_observer.h" | 19 #include "components/drive/change_list_loader_observer.h" |
17 #include "components/drive/change_list_processor.h" | 20 #include "components/drive/change_list_processor.h" |
18 #include "components/drive/event_logger.h" | 21 #include "components/drive/event_logger.h" |
19 #include "components/drive/file_system_core_util.h" | 22 #include "components/drive/file_system_core_util.h" |
20 #include "components/drive/job_scheduler.h" | 23 #include "components/drive/job_scheduler.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 ScopedVector<ChangeList> change_lists_; | 100 ScopedVector<ChangeList> change_lists_; |
98 base::TimeTicks start_time_; | 101 base::TimeTicks start_time_; |
99 base::ThreadChecker thread_checker_; | 102 base::ThreadChecker thread_checker_; |
100 base::WeakPtrFactory<FullFeedFetcher> weak_ptr_factory_; | 103 base::WeakPtrFactory<FullFeedFetcher> weak_ptr_factory_; |
101 DISALLOW_COPY_AND_ASSIGN(FullFeedFetcher); | 104 DISALLOW_COPY_AND_ASSIGN(FullFeedFetcher); |
102 }; | 105 }; |
103 | 106 |
104 // Fetches the delta changes since |start_change_id|. | 107 // Fetches the delta changes since |start_change_id|. |
105 class DeltaFeedFetcher : public ChangeListLoader::FeedFetcher { | 108 class DeltaFeedFetcher : public ChangeListLoader::FeedFetcher { |
106 public: | 109 public: |
107 DeltaFeedFetcher(JobScheduler* scheduler, int64 start_change_id) | 110 DeltaFeedFetcher(JobScheduler* scheduler, int64_t start_change_id) |
108 : scheduler_(scheduler), | 111 : scheduler_(scheduler), |
109 start_change_id_(start_change_id), | 112 start_change_id_(start_change_id), |
110 weak_ptr_factory_(this) { | 113 weak_ptr_factory_(this) {} |
111 } | |
112 | 114 |
113 ~DeltaFeedFetcher() override {} | 115 ~DeltaFeedFetcher() override {} |
114 | 116 |
115 void Run(const FeedFetcherCallback& callback) override { | 117 void Run(const FeedFetcherCallback& callback) override { |
116 DCHECK(thread_checker_.CalledOnValidThread()); | 118 DCHECK(thread_checker_.CalledOnValidThread()); |
117 DCHECK(!callback.is_null()); | 119 DCHECK(!callback.is_null()); |
118 | 120 |
119 scheduler_->GetChangeList( | 121 scheduler_->GetChangeList( |
120 start_change_id_, | 122 start_change_id_, |
121 base::Bind(&DeltaFeedFetcher::OnChangeListFetched, | 123 base::Bind(&DeltaFeedFetcher::OnChangeListFetched, |
(...skipping 25 matching lines...) Expand all Loading... |
147 return; | 149 return; |
148 } | 150 } |
149 | 151 |
150 // Note: The fetcher is managed by ChangeListLoader, and the instance | 152 // Note: The fetcher is managed by ChangeListLoader, and the instance |
151 // will be deleted in the callback. Do not touch the fields after this | 153 // will be deleted in the callback. Do not touch the fields after this |
152 // invocation. | 154 // invocation. |
153 callback.Run(FILE_ERROR_OK, change_lists_.Pass()); | 155 callback.Run(FILE_ERROR_OK, change_lists_.Pass()); |
154 } | 156 } |
155 | 157 |
156 JobScheduler* scheduler_; | 158 JobScheduler* scheduler_; |
157 int64 start_change_id_; | 159 int64_t start_change_id_; |
158 ScopedVector<ChangeList> change_lists_; | 160 ScopedVector<ChangeList> change_lists_; |
159 base::ThreadChecker thread_checker_; | 161 base::ThreadChecker thread_checker_; |
160 base::WeakPtrFactory<DeltaFeedFetcher> weak_ptr_factory_; | 162 base::WeakPtrFactory<DeltaFeedFetcher> weak_ptr_factory_; |
161 DISALLOW_COPY_AND_ASSIGN(DeltaFeedFetcher); | 163 DISALLOW_COPY_AND_ASSIGN(DeltaFeedFetcher); |
162 }; | 164 }; |
163 | 165 |
164 } // namespace | 166 } // namespace |
165 | 167 |
166 LoaderController::LoaderController() | 168 LoaderController::LoaderController() |
167 : lock_count_(0), | 169 : lock_count_(0), |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 const bool is_initial_load = (!loaded_ && !IsRefreshing()); | 373 const bool is_initial_load = (!loaded_ && !IsRefreshing()); |
372 | 374 |
373 // Register the callback function to be called when it is loaded. | 375 // Register the callback function to be called when it is loaded. |
374 pending_load_callback_.push_back(callback); | 376 pending_load_callback_.push_back(callback); |
375 | 377 |
376 // If loading task is already running, do nothing. | 378 // If loading task is already running, do nothing. |
377 if (pending_load_callback_.size() > 1) | 379 if (pending_load_callback_.size() > 1) |
378 return; | 380 return; |
379 | 381 |
380 // Check the current status of local metadata, and start loading if needed. | 382 // Check the current status of local metadata, and start loading if needed. |
381 int64* local_changestamp = new int64(0); | 383 int64_t* local_changestamp = new int64_t(0); |
382 base::PostTaskAndReplyWithResult( | 384 base::PostTaskAndReplyWithResult( |
383 blocking_task_runner_.get(), | 385 blocking_task_runner_.get(), |
384 FROM_HERE, | 386 FROM_HERE, |
385 base::Bind(&ResourceMetadata::GetLargestChangestamp, | 387 base::Bind(&ResourceMetadata::GetLargestChangestamp, |
386 base::Unretained(resource_metadata_), | 388 base::Unretained(resource_metadata_), |
387 local_changestamp), | 389 local_changestamp), |
388 base::Bind(&ChangeListLoader::LoadAfterGetLargestChangestamp, | 390 base::Bind(&ChangeListLoader::LoadAfterGetLargestChangestamp, |
389 weak_ptr_factory_.GetWeakPtr(), | 391 weak_ptr_factory_.GetWeakPtr(), |
390 is_initial_load, | 392 is_initial_load, |
391 base::Owned(local_changestamp))); | 393 base::Owned(local_changestamp))); |
392 } | 394 } |
393 | 395 |
394 void ChangeListLoader::LoadAfterGetLargestChangestamp( | 396 void ChangeListLoader::LoadAfterGetLargestChangestamp( |
395 bool is_initial_load, | 397 bool is_initial_load, |
396 const int64* local_changestamp, | 398 const int64_t* local_changestamp, |
397 FileError error) { | 399 FileError error) { |
398 DCHECK(thread_checker_.CalledOnValidThread()); | 400 DCHECK(thread_checker_.CalledOnValidThread()); |
399 | 401 |
400 if (error != FILE_ERROR_OK) { | 402 if (error != FILE_ERROR_OK) { |
401 OnChangeListLoadComplete(error); | 403 OnChangeListLoadComplete(error); |
402 return; | 404 return; |
403 } | 405 } |
404 | 406 |
405 if (is_initial_load && *local_changestamp > 0) { | 407 if (is_initial_load && *local_changestamp > 0) { |
406 // The local data is usable. Flush callbacks to tell loading was successful. | 408 // The local data is usable. Flush callbacks to tell loading was successful. |
407 OnChangeListLoadComplete(FILE_ERROR_OK); | 409 OnChangeListLoadComplete(FILE_ERROR_OK); |
408 | 410 |
409 // Continues to load from server in background. | 411 // Continues to load from server in background. |
410 // Put dummy callbacks to indicate that fetching is still continuing. | 412 // Put dummy callbacks to indicate that fetching is still continuing. |
411 pending_load_callback_.push_back( | 413 pending_load_callback_.push_back( |
412 base::Bind(&util::EmptyFileOperationCallback)); | 414 base::Bind(&util::EmptyFileOperationCallback)); |
413 } | 415 } |
414 | 416 |
415 about_resource_loader_->GetAboutResource( | 417 about_resource_loader_->GetAboutResource( |
416 base::Bind(&ChangeListLoader::LoadAfterGetAboutResource, | 418 base::Bind(&ChangeListLoader::LoadAfterGetAboutResource, |
417 weak_ptr_factory_.GetWeakPtr(), | 419 weak_ptr_factory_.GetWeakPtr(), |
418 *local_changestamp)); | 420 *local_changestamp)); |
419 } | 421 } |
420 | 422 |
421 void ChangeListLoader::LoadAfterGetAboutResource( | 423 void ChangeListLoader::LoadAfterGetAboutResource( |
422 int64 local_changestamp, | 424 int64_t local_changestamp, |
423 google_apis::DriveApiErrorCode status, | 425 google_apis::DriveApiErrorCode status, |
424 scoped_ptr<google_apis::AboutResource> about_resource) { | 426 scoped_ptr<google_apis::AboutResource> about_resource) { |
425 DCHECK(thread_checker_.CalledOnValidThread()); | 427 DCHECK(thread_checker_.CalledOnValidThread()); |
426 | 428 |
427 FileError error = GDataToFileError(status); | 429 FileError error = GDataToFileError(status); |
428 if (error != FILE_ERROR_OK) { | 430 if (error != FILE_ERROR_OK) { |
429 OnChangeListLoadComplete(error); | 431 OnChangeListLoadComplete(error); |
430 return; | 432 return; |
431 } | 433 } |
432 | 434 |
433 DCHECK(about_resource); | 435 DCHECK(about_resource); |
434 | 436 |
435 int64 remote_changestamp = about_resource->largest_change_id(); | 437 int64_t remote_changestamp = about_resource->largest_change_id(); |
436 int64 start_changestamp = local_changestamp > 0 ? local_changestamp + 1 : 0; | 438 int64_t start_changestamp = local_changestamp > 0 ? local_changestamp + 1 : 0; |
437 if (local_changestamp >= remote_changestamp) { | 439 if (local_changestamp >= remote_changestamp) { |
438 if (local_changestamp > remote_changestamp) { | 440 if (local_changestamp > remote_changestamp) { |
439 LOG(WARNING) << "Local resource metadata is fresher than server, " | 441 LOG(WARNING) << "Local resource metadata is fresher than server, " |
440 << "local = " << local_changestamp | 442 << "local = " << local_changestamp |
441 << ", server = " << remote_changestamp; | 443 << ", server = " << remote_changestamp; |
442 } | 444 } |
443 | 445 |
444 // No changes detected, tell the client that the loading was successful. | 446 // No changes detected, tell the client that the loading was successful. |
445 OnChangeListLoadComplete(FILE_ERROR_OK); | 447 OnChangeListLoadComplete(FILE_ERROR_OK); |
446 } else { | 448 } else { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 logger_->Log(logging::LOG_ERROR, | 484 logger_->Log(logging::LOG_ERROR, |
483 "Failed to update the about resource: %s", | 485 "Failed to update the about resource: %s", |
484 google_apis::DriveApiErrorCodeToString(error).c_str()); | 486 google_apis::DriveApiErrorCodeToString(error).c_str()); |
485 return; | 487 return; |
486 } | 488 } |
487 logger_->Log(logging::LOG_INFO, | 489 logger_->Log(logging::LOG_INFO, |
488 "About resource updated to: %s", | 490 "About resource updated to: %s", |
489 base::Int64ToString(resource->largest_change_id()).c_str()); | 491 base::Int64ToString(resource->largest_change_id()).c_str()); |
490 } | 492 } |
491 | 493 |
492 void ChangeListLoader::LoadChangeListFromServer(int64 start_changestamp) { | 494 void ChangeListLoader::LoadChangeListFromServer(int64_t start_changestamp) { |
493 DCHECK(thread_checker_.CalledOnValidThread()); | 495 DCHECK(thread_checker_.CalledOnValidThread()); |
494 DCHECK(!change_feed_fetcher_); | 496 DCHECK(!change_feed_fetcher_); |
495 DCHECK(about_resource_loader_->cached_about_resource()); | 497 DCHECK(about_resource_loader_->cached_about_resource()); |
496 | 498 |
497 bool is_delta_update = start_changestamp != 0; | 499 bool is_delta_update = start_changestamp != 0; |
498 | 500 |
499 // Set up feed fetcher. | 501 // Set up feed fetcher. |
500 if (is_delta_update) { | 502 if (is_delta_update) { |
501 change_feed_fetcher_.reset( | 503 change_feed_fetcher_.reset( |
502 new DeltaFeedFetcher(scheduler_, start_changestamp)); | 504 new DeltaFeedFetcher(scheduler_, start_changestamp)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 | 578 |
577 OnChangeListLoadComplete(error); | 579 OnChangeListLoadComplete(error); |
578 | 580 |
579 FOR_EACH_OBSERVER(ChangeListLoaderObserver, | 581 FOR_EACH_OBSERVER(ChangeListLoaderObserver, |
580 observers_, | 582 observers_, |
581 OnLoadFromServerComplete()); | 583 OnLoadFromServerComplete()); |
582 } | 584 } |
583 | 585 |
584 } // namespace internal | 586 } // namespace internal |
585 } // namespace drive | 587 } // namespace drive |
OLD | NEW |