| 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/drive_feed_loader.h" | 5 #include "chrome/browser/chromeos/drive/drive_feed_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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 249 |
| 250 void DriveFeedLoader::RemoveObserver(DriveFeedLoaderObserver* observer) { | 250 void DriveFeedLoader::RemoveObserver(DriveFeedLoaderObserver* observer) { |
| 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 252 observers_.RemoveObserver(observer); | 252 observers_.RemoveObserver(observer); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void DriveFeedLoader::ReloadFromServerIfNeeded( | 255 void DriveFeedLoader::ReloadFromServerIfNeeded( |
| 256 const FileOperationCallback& callback) { | 256 const FileOperationCallback& callback) { |
| 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 258 DCHECK(!callback.is_null()); | 258 DCHECK(!callback.is_null()); |
| 259 DVLOG(1) << "ReloadFromServerIfNeeded local_changestamp=" | |
| 260 << resource_metadata_->largest_changestamp() | |
| 261 << ", loaded=" << resource_metadata_->loaded(); | |
| 262 | 259 |
| 263 // Sets the refreshing flag, so that the caller does not send refresh requests | 260 // Sets the refreshing flag, so that the caller does not send refresh requests |
| 264 // in parallel (see DriveFileSystem::CheckForUpdates). Corresponding | 261 // in parallel (see DriveFileSystem::CheckForUpdates). Corresponding |
| 265 // "refresh_ = false" is in OnGetAccountMetadata when the cached feed is up to | 262 // "refresh_ = false" is in OnGetAccountMetadata when the cached feed is up to |
| 266 // date, or in OnFeedFromServerLoaded called back from LoadFromServer(). | 263 // date, or in OnFeedFromServerLoaded called back from LoadFromServer(). |
| 267 refreshing_ = true; | 264 refreshing_ = true; |
| 268 | 265 |
| 269 if (google_apis::util::IsDriveV2ApiEnabled()) { | 266 if (google_apis::util::IsDriveV2ApiEnabled()) { |
| 270 // Drive v2 needs a separate application list fetch operation. | 267 // Drive v2 needs a separate application list fetch operation. |
| 271 // TODO(haruki): Application list rarely changes and is not necessarily | 268 // TODO(haruki): Application list rarely changes and is not necessarily |
| (...skipping 12 matching lines...) Expand all Loading... |
| 284 } | 281 } |
| 285 | 282 |
| 286 void DriveFeedLoader::OnGetAccountMetadata( | 283 void DriveFeedLoader::OnGetAccountMetadata( |
| 287 const FileOperationCallback& callback, | 284 const FileOperationCallback& callback, |
| 288 google_apis::GDataErrorCode status, | 285 google_apis::GDataErrorCode status, |
| 289 scoped_ptr<google_apis::AccountMetadataFeed> account_metadata) { | 286 scoped_ptr<google_apis::AccountMetadataFeed> account_metadata) { |
| 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 291 DCHECK(!callback.is_null()); | 288 DCHECK(!callback.is_null()); |
| 292 DCHECK(refreshing_); | 289 DCHECK(refreshing_); |
| 293 | 290 |
| 294 int64 local_changestamp = resource_metadata_->largest_changestamp(); | |
| 295 int64 remote_changestamp = 0; | 291 int64 remote_changestamp = 0; |
| 296 | |
| 297 // When account metadata successfully fetched, parse the latest changestamp. | 292 // When account metadata successfully fetched, parse the latest changestamp. |
| 298 if (util::GDataToDriveFileError(status) == DRIVE_FILE_OK) { | 293 if (util::GDataToDriveFileError(status) == DRIVE_FILE_OK) { |
| 299 DCHECK(account_metadata); | 294 DCHECK(account_metadata); |
| 300 webapps_registry_->UpdateFromFeed(*account_metadata); | 295 webapps_registry_->UpdateFromFeed(*account_metadata); |
| 301 remote_changestamp = account_metadata->largest_changestamp(); | 296 remote_changestamp = account_metadata->largest_changestamp(); |
| 302 } | 297 } |
| 303 | 298 |
| 299 resource_metadata_->GetLargestChangestamp( |
| 300 base::Bind(&DriveFeedLoader::CompareChangestamps, |
| 301 weak_ptr_factory_.GetWeakPtr(), |
| 302 callback, |
| 303 remote_changestamp)); |
| 304 } |
| 305 |
| 306 void DriveFeedLoader::CompareChangestamps( |
| 307 const FileOperationCallback& callback, |
| 308 int64 remote_changestamp, |
| 309 int64 local_changestamp) { |
| 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 311 DCHECK(!callback.is_null()); |
| 312 DCHECK(refreshing_); |
| 313 |
| 304 if (remote_changestamp > 0 && local_changestamp >= remote_changestamp) { | 314 if (remote_changestamp > 0 && local_changestamp >= remote_changestamp) { |
| 305 if (local_changestamp > remote_changestamp) { | 315 if (local_changestamp > remote_changestamp) { |
| 306 LOG(WARNING) << "Cached client feed is fresher than server, client = " | 316 LOG(WARNING) << "Cached client feed is fresher than server, client = " |
| 307 << local_changestamp | 317 << local_changestamp |
| 308 << ", server = " | 318 << ", server = " |
| 309 << remote_changestamp; | 319 << remote_changestamp; |
| 310 } | 320 } |
| 311 | 321 |
| 312 // No changes detected, tell the client that the loading was successful. | 322 // No changes detected, tell the client that the loading was successful. |
| 313 refreshing_ = false; | 323 refreshing_ = false; |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 | 696 |
| 687 // Run the callback now that the filesystem is ready. | 697 // Run the callback now that the filesystem is ready. |
| 688 load_finished_callback.Run(DRIVE_FILE_OK); | 698 load_finished_callback.Run(DRIVE_FILE_OK); |
| 689 | 699 |
| 690 FOR_EACH_OBSERVER(DriveFeedLoaderObserver, | 700 FOR_EACH_OBSERVER(DriveFeedLoaderObserver, |
| 691 observers_, | 701 observers_, |
| 692 OnFeedFromServerLoaded()); | 702 OnFeedFromServerLoaded()); |
| 693 } | 703 } |
| 694 | 704 |
| 695 } // namespace drive | 705 } // namespace drive |
| OLD | NEW |