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