Chromium Code Reviews| 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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 | 258 |
| 259 void ChangeListLoader::LoadFromServerIfNeededAfterGetAbout( | 259 void ChangeListLoader::LoadFromServerIfNeededAfterGetAbout( |
| 260 const DirectoryFetchInfo& directory_fetch_info, | 260 const DirectoryFetchInfo& directory_fetch_info, |
| 261 const FileOperationCallback& callback, | 261 const FileOperationCallback& callback, |
| 262 google_apis::GDataErrorCode status, | 262 google_apis::GDataErrorCode status, |
| 263 scoped_ptr<google_apis::AboutResource> about_resource) { | 263 scoped_ptr<google_apis::AboutResource> about_resource) { |
| 264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 265 DCHECK(!callback.is_null()); | 265 DCHECK(!callback.is_null()); |
| 266 DCHECK(refreshing_); | 266 DCHECK(refreshing_); |
| 267 | 267 |
| 268 int64 remote_changestamp = 0; | |
| 269 if (util::GDataToDriveFileError(status) == DRIVE_FILE_OK) { | 268 if (util::GDataToDriveFileError(status) == DRIVE_FILE_OK) { |
| 270 DCHECK(about_resource); | 269 DCHECK(about_resource.get()); |
|
hidehiko
2013/03/18 06:22:27
Do you want to:
DCHECK_EQ(util::GDataToDriveFileEr
Haruki Sato
2013/03/18 07:06:41
Done. Thanks!
This actually is rather a debugging
| |
| 271 remote_changestamp = about_resource->largest_change_id(); | 270 } else { |
| 271 DCHECK(!about_resource.get()); | |
| 272 // ERROR here???? | |
| 272 } | 273 } |
| 273 | 274 |
| 274 resource_metadata_->GetLargestChangestamp( | 275 resource_metadata_->GetLargestChangestamp( |
| 275 base::Bind(&ChangeListLoader::CompareChangestampsAndLoadIfNeeded, | 276 base::Bind(&ChangeListLoader::CompareChangestampsAndLoadIfNeeded, |
| 276 weak_ptr_factory_.GetWeakPtr(), | 277 weak_ptr_factory_.GetWeakPtr(), |
| 277 directory_fetch_info, | 278 directory_fetch_info, |
| 278 callback, | 279 callback, |
| 279 remote_changestamp)); | 280 base::Passed(about_resource.Pass()))); |
|
hidehiko
2013/03/18 06:22:27
base::Passed(&about_resource) ? Ditto for below.
Haruki Sato
2013/03/18 07:06:41
Done. Thanks.
| |
| 280 } | 281 } |
| 281 | 282 |
| 282 void ChangeListLoader::CompareChangestampsAndLoadIfNeeded( | 283 void ChangeListLoader::CompareChangestampsAndLoadIfNeeded( |
| 283 const DirectoryFetchInfo& directory_fetch_info, | 284 const DirectoryFetchInfo& directory_fetch_info, |
| 284 const FileOperationCallback& callback, | 285 const FileOperationCallback& callback, |
| 285 int64 remote_changestamp, | 286 scoped_ptr<google_apis::AboutResource> about_resource, |
| 286 int64 local_changestamp) { | 287 int64 local_changestamp) { |
| 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 288 DCHECK(!callback.is_null()); | 289 DCHECK(!callback.is_null()); |
| 289 DCHECK(refreshing_); | 290 DCHECK(refreshing_); |
| 290 | 291 |
| 292 int64 remote_changestamp = | |
| 293 about_resource ? about_resource->largest_change_id() : 0; | |
| 291 if (remote_changestamp > 0 && local_changestamp >= remote_changestamp) { | 294 if (remote_changestamp > 0 && local_changestamp >= remote_changestamp) { |
| 292 if (local_changestamp > remote_changestamp) { | 295 if (local_changestamp > remote_changestamp) { |
| 293 LOG(WARNING) << "Cached client feed is fresher than server, client = " | 296 LOG(WARNING) << "Cached client feed is fresher than server, client = " |
| 294 << local_changestamp | 297 << local_changestamp |
| 295 << ", server = " | 298 << ", server = " |
| 296 << remote_changestamp; | 299 << remote_changestamp; |
| 297 } | 300 } |
| 298 | 301 |
| 299 // No changes detected, tell the client that the loading was successful. | 302 // No changes detected, tell the client that the loading was successful. |
| 300 OnChangeListLoadComplete(callback, DRIVE_FILE_OK); | 303 OnChangeListLoadComplete(callback, DRIVE_FILE_OK); |
| 301 return; | 304 return; |
| 302 } | 305 } |
| 303 | 306 |
| 304 int64 start_changestamp = local_changestamp > 0 ? local_changestamp + 1 : 0; | 307 int64 start_changestamp = local_changestamp > 0 ? local_changestamp + 1 : 0; |
| 308 if (start_changestamp == 0 && !about_resource.get()) { | |
| 309 // Full update needs AboutResource. If this is a full update, we should just | |
| 310 // give up. | |
| 311 callback.Run(DRIVE_FILE_ERROR_FAILED); | |
| 312 return; | |
| 313 } | |
| 305 | 314 |
| 306 // TODO(satorux): Use directory_fetch_info to start "fast-fetch" here. | 315 // TODO(satorux): Use directory_fetch_info to start "fast-fetch" here. |
| 307 LoadChangeListFromServer(start_changestamp, | 316 LoadChangeListFromServer(about_resource.Pass(), |
| 308 remote_changestamp, | 317 start_changestamp, |
| 309 callback); | 318 callback); |
| 310 } | 319 } |
| 311 | 320 |
| 312 void ChangeListLoader::LoadChangeListFromServer( | 321 void ChangeListLoader::LoadChangeListFromServer( |
| 322 scoped_ptr<google_apis::AboutResource> about_resource, | |
| 313 int64 start_changestamp, | 323 int64 start_changestamp, |
| 314 int64 remote_changestamp, | |
| 315 const FileOperationCallback& callback) { | 324 const FileOperationCallback& callback) { |
| 316 scoped_ptr<LoadFeedParams> load_params(new LoadFeedParams); | 325 scoped_ptr<LoadFeedParams> load_params(new LoadFeedParams); |
| 317 load_params->start_changestamp = start_changestamp; | 326 load_params->start_changestamp = start_changestamp; |
| 318 LoadFromServer( | 327 LoadFromServer( |
| 319 load_params.Pass(), | 328 load_params.Pass(), |
| 320 base::Bind(&ChangeListLoader::UpdateMetadataFromFeedAfterLoadFromServer, | 329 base::Bind(&ChangeListLoader::UpdateMetadataFromFeedAfterLoadFromServer, |
| 321 weak_ptr_factory_.GetWeakPtr(), | 330 weak_ptr_factory_.GetWeakPtr(), |
| 331 base::Passed(about_resource.Pass()), | |
| 322 start_changestamp != 0, // is_delta_feed | 332 start_changestamp != 0, // is_delta_feed |
| 323 remote_changestamp, | |
| 324 callback)); | 333 callback)); |
| 325 } | 334 } |
| 326 | 335 |
| 327 void ChangeListLoader::OnGetAppList(google_apis::GDataErrorCode status, | 336 void ChangeListLoader::OnGetAppList(google_apis::GDataErrorCode status, |
| 328 scoped_ptr<google_apis::AppList> app_list) { | 337 scoped_ptr<google_apis::AppList> app_list) { |
| 329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 330 | 339 |
| 331 DriveFileError error = util::GDataToDriveFileError(status); | 340 DriveFileError error = util::GDataToDriveFileError(status); |
| 332 if (error != DRIVE_FILE_OK) | 341 if (error != DRIVE_FILE_OK) |
| 333 return; | 342 return; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 | 473 |
| 465 scoped_ptr<LoadFeedParams> params(new LoadFeedParams); | 474 scoped_ptr<LoadFeedParams> params(new LoadFeedParams); |
| 466 params->search_query = search_query; | 475 params->search_query = search_query; |
| 467 params->shared_with_me = shared_with_me; | 476 params->shared_with_me = shared_with_me; |
| 468 params->feed_to_load = next_feed; | 477 params->feed_to_load = next_feed; |
| 469 params->load_subsequent_feeds = false; | 478 params->load_subsequent_feeds = false; |
| 470 LoadFromServer(params.Pass(), feed_load_callback); | 479 LoadFromServer(params.Pass(), feed_load_callback); |
| 471 } | 480 } |
| 472 | 481 |
| 473 void ChangeListLoader::UpdateMetadataFromFeedAfterLoadFromServer( | 482 void ChangeListLoader::UpdateMetadataFromFeedAfterLoadFromServer( |
| 483 scoped_ptr<google_apis::AboutResource> about_resource, | |
| 474 bool is_delta_feed, | 484 bool is_delta_feed, |
| 475 int64 feed_changestamp, | |
| 476 const FileOperationCallback& callback, | 485 const FileOperationCallback& callback, |
| 477 const ScopedVector<google_apis::ResourceList>& feed_list, | 486 const ScopedVector<google_apis::ResourceList>& feed_list, |
| 478 DriveFileError error) { | 487 DriveFileError error) { |
| 479 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 480 DCHECK(!callback.is_null()); | 489 DCHECK(!callback.is_null()); |
| 481 DCHECK(refreshing_); | 490 DCHECK(refreshing_); |
| 482 | 491 |
| 483 if (error != DRIVE_FILE_OK) { | 492 if (error != DRIVE_FILE_OK) { |
| 484 OnChangeListLoadComplete(callback, error); | 493 OnChangeListLoadComplete(callback, error); |
| 485 return; | 494 return; |
| 486 } | 495 } |
| 487 | 496 |
| 488 UpdateFromFeed(feed_list, | 497 UpdateFromFeed(about_resource.Pass(), |
| 498 feed_list, | |
| 489 is_delta_feed, | 499 is_delta_feed, |
| 490 feed_changestamp, | |
| 491 base::Bind(&ChangeListLoader::OnUpdateFromFeed, | 500 base::Bind(&ChangeListLoader::OnUpdateFromFeed, |
| 492 weak_ptr_factory_.GetWeakPtr(), | 501 weak_ptr_factory_.GetWeakPtr(), |
| 493 callback)); | 502 callback)); |
| 494 } | 503 } |
| 495 | 504 |
| 496 void ChangeListLoader::LoadFromServerAfterGetResourceList( | 505 void ChangeListLoader::LoadFromServerAfterGetResourceList( |
| 497 scoped_ptr<LoadFeedParams> params, | 506 scoped_ptr<LoadFeedParams> params, |
| 498 const LoadFeedListCallback& callback, | 507 const LoadFeedListCallback& callback, |
| 499 base::TimeTicks start_time, | 508 base::TimeTicks start_time, |
| 500 google_apis::GDataErrorCode status, | 509 google_apis::GDataErrorCode status, |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 resource_metadata_->SerializeToString(serialized_proto.get()); | 735 resource_metadata_->SerializeToString(serialized_proto.get()); |
| 727 resource_metadata_->set_last_serialized(base::Time::Now()); | 736 resource_metadata_->set_last_serialized(base::Time::Now()); |
| 728 resource_metadata_->set_serialized_size(serialized_proto->size()); | 737 resource_metadata_->set_serialized_size(serialized_proto->size()); |
| 729 blocking_task_runner_->PostTask( | 738 blocking_task_runner_->PostTask( |
| 730 FROM_HERE, | 739 FROM_HERE, |
| 731 base::Bind(&SaveProtoOnBlockingPool, path, | 740 base::Bind(&SaveProtoOnBlockingPool, path, |
| 732 base::Passed(&serialized_proto))); | 741 base::Passed(&serialized_proto))); |
| 733 } | 742 } |
| 734 | 743 |
| 735 void ChangeListLoader::UpdateFromFeed( | 744 void ChangeListLoader::UpdateFromFeed( |
| 745 scoped_ptr<google_apis::AboutResource> about_resource, | |
| 736 const ScopedVector<google_apis::ResourceList>& feed_list, | 746 const ScopedVector<google_apis::ResourceList>& feed_list, |
| 737 bool is_delta_feed, | 747 bool is_delta_feed, |
| 738 int64 root_feed_changestamp, | |
| 739 const base::Closure& update_finished_callback) { | 748 const base::Closure& update_finished_callback) { |
| 740 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 749 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 741 DCHECK(!update_finished_callback.is_null()); | 750 DCHECK(!update_finished_callback.is_null()); |
| 742 DVLOG(1) << "Updating directory with a feed"; | 751 DVLOG(1) << "Updating directory with a feed"; |
| 743 | 752 |
| 744 change_list_processor_.reset(new ChangeListProcessor(resource_metadata_)); | 753 change_list_processor_.reset(new ChangeListProcessor(resource_metadata_)); |
| 745 // Don't send directory content change notification while performing | 754 // Don't send directory content change notification while performing |
| 746 // the initial content retrieval. | 755 // the initial content retrieval. |
| 747 const bool should_notify_changed_directories = is_delta_feed; | 756 const bool should_notify_changed_directories = is_delta_feed; |
| 748 | 757 |
| 749 change_list_processor_->ApplyFeeds( | 758 change_list_processor_->ApplyFeeds( |
| 759 about_resource.Pass(), | |
| 750 feed_list, | 760 feed_list, |
| 751 is_delta_feed, | 761 is_delta_feed, |
| 752 root_feed_changestamp, | |
| 753 base::Bind(&ChangeListLoader::NotifyDirectoryChanged, | 762 base::Bind(&ChangeListLoader::NotifyDirectoryChanged, |
| 754 weak_ptr_factory_.GetWeakPtr(), | 763 weak_ptr_factory_.GetWeakPtr(), |
| 755 should_notify_changed_directories, | 764 should_notify_changed_directories, |
| 756 update_finished_callback)); | 765 update_finished_callback)); |
| 757 } | 766 } |
| 758 | 767 |
| 759 void ChangeListLoader::ScheduleRun( | 768 void ChangeListLoader::ScheduleRun( |
| 760 const DirectoryFetchInfo& directory_fetch_info, | 769 const DirectoryFetchInfo& directory_fetch_info, |
| 761 const FileOperationCallback& callback) { | 770 const FileOperationCallback& callback) { |
| 762 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 823 QueuedCallbackInfo info = queue_.front(); | 832 QueuedCallbackInfo info = queue_.front(); |
| 824 const FileOperationCallback& callback = info.second; | 833 const FileOperationCallback& callback = info.second; |
| 825 queue_.pop(); | 834 queue_.pop(); |
| 826 base::MessageLoopProxy::current()->PostTask( | 835 base::MessageLoopProxy::current()->PostTask( |
| 827 FROM_HERE, | 836 FROM_HERE, |
| 828 base::Bind(callback, error)); | 837 base::Bind(callback, error)); |
| 829 } | 838 } |
| 830 } | 839 } |
| 831 | 840 |
| 832 } // namespace drive | 841 } // namespace drive |
| OLD | NEW |