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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 return; | 180 return; |
| 181 } | 181 } |
| 182 | 182 |
| 183 if (directory_fetch_info.empty()) { | 183 if (directory_fetch_info.empty()) { |
| 184 // If the caller is not interested in a particular directory, just start | 184 // If the caller is not interested in a particular directory, just start |
| 185 // loading the change list. | 185 // loading the change list. |
| 186 LoadChangeListFromServer(about_resource.Pass(), | 186 LoadChangeListFromServer(about_resource.Pass(), |
| 187 start_changestamp, | 187 start_changestamp, |
| 188 callback); | 188 callback); |
| 189 } else if (directory_fetch_info.changestamp() < remote_changestamp && | 189 } else if (directory_fetch_info.changestamp() < remote_changestamp && |
| 190 !util::IsSpecialResourceId(directory_fetch_info.resource_id())) { | 190 directory_fetch_info.resource_id() != |
| 191 util::kDriveOtherDirSpecialResourceId) { | |
| 191 // If the caller is interested in a particular directory, and the | 192 // If the caller is interested in a particular directory, and the |
| 192 // directory changestamp is older than server's, start loading the | 193 // directory changestamp is older than server's, start loading the |
| 193 // directory first. Skip special entries as they are not meaningful in the | 194 // directory first. Skip special entries as they are not meaningful in the |
| 194 // server. | 195 // server. |
| 195 DVLOG(1) << "Fast-fetching directory: " << directory_fetch_info.ToString() | 196 DVLOG(1) << "Fast-fetching directory: " << directory_fetch_info.ToString() |
| 196 << "; remote_changestamp: " << remote_changestamp; | 197 << "; remote_changestamp: " << remote_changestamp; |
| 197 const DirectoryFetchInfo new_directory_fetch_info( | 198 const DirectoryFetchInfo new_directory_fetch_info( |
| 198 directory_fetch_info.resource_id(), remote_changestamp); | 199 directory_fetch_info.resource_id(), remote_changestamp); |
| 199 DoLoadDirectoryFromServer( | 200 DoLoadDirectoryFromServer( |
| 200 new_directory_fetch_info, | 201 new_directory_fetch_info, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 } | 335 } |
| 335 | 336 |
| 336 void ChangeListLoader::DoLoadDirectoryFromServer( | 337 void ChangeListLoader::DoLoadDirectoryFromServer( |
| 337 const DirectoryFetchInfo& directory_fetch_info, | 338 const DirectoryFetchInfo& directory_fetch_info, |
| 338 const FileOperationCallback& callback) { | 339 const FileOperationCallback& callback) { |
| 339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 340 DCHECK(!callback.is_null()); | 341 DCHECK(!callback.is_null()); |
| 341 DCHECK(!directory_fetch_info.empty()); | 342 DCHECK(!directory_fetch_info.empty()); |
| 342 DVLOG(1) << "Start loading directory: " << directory_fetch_info.ToString(); | 343 DVLOG(1) << "Start loading directory: " << directory_fetch_info.ToString(); |
| 343 | 344 |
| 344 if (util::IsSpecialResourceId(directory_fetch_info.resource_id())) { | 345 if (directory_fetch_info.resource_id() == |
| 345 // Load for a special directory is meaningless in the server. | 346 util::kDriveOtherDirSpecialResourceId) { |
| 347 // Load for a <other> directory is meaningless in the server. | |
| 346 // Let it succeed and use what we have locally. | 348 // Let it succeed and use what we have locally. |
| 347 callback.Run(DRIVE_FILE_OK); | 349 callback.Run(DRIVE_FILE_OK); |
| 348 return; | 350 return; |
| 349 } | 351 } |
| 350 | 352 |
| 353 if (directory_fetch_info.resource_id() == | |
| 354 util::kDriveGrandRootSpecialResourceId) { | |
| 355 // Load for a grand root directory means slightly different from other | |
| 356 // directories. It should have two directories; <other> and mydrive root. | |
| 357 // <other> directory should always exists, but mydrive root should be | |
|
kinaba
2013/04/10 04:34:44
nit: exists -> exist
hidehiko
2013/04/10 06:11:19
Done.
| |
| 358 // created by root resource id retreived from the server. | |
|
kinaba
2013/04/10 04:34:44
retrieved
hidehiko
2013/04/10 06:11:19
Done.
| |
| 359 // Here, we check if mydrive root exists, and if not, create it. | |
| 360 resource_metadata_->GetEntryInfoByPath( | |
| 361 base::FilePath(util::kDriveMyDriveRootPath), | |
| 362 base::Bind( | |
| 363 &ChangeListLoader::DoLoadDirectoryFromServerAfterGetEntryInfoByPath, | |
| 364 weak_ptr_factory_.GetWeakPtr(), | |
| 365 directory_fetch_info, | |
| 366 callback)); | |
| 367 return; | |
| 368 } | |
| 369 | |
| 351 scoped_ptr<LoadFeedParams> params(new LoadFeedParams); | 370 scoped_ptr<LoadFeedParams> params(new LoadFeedParams); |
| 352 params->directory_resource_id = directory_fetch_info.resource_id(); | 371 params->directory_resource_id = directory_fetch_info.resource_id(); |
| 353 LoadFromServer( | 372 LoadFromServer( |
| 354 params.Pass(), | 373 params.Pass(), |
| 355 base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterLoad, | 374 base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterLoad, |
| 356 weak_ptr_factory_.GetWeakPtr(), | 375 weak_ptr_factory_.GetWeakPtr(), |
| 357 directory_fetch_info, | 376 directory_fetch_info, |
| 358 callback)); | 377 callback)); |
| 359 } | 378 } |
| 360 | 379 |
| 380 void ChangeListLoader::DoLoadDirectoryFromServerAfterGetEntryInfoByPath( | |
| 381 const DirectoryFetchInfo& directory_fetch_info, | |
| 382 const FileOperationCallback& callback, | |
| 383 DriveFileError error, | |
| 384 scoped_ptr<DriveEntryProto> entry_proto) { | |
| 385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 386 DCHECK(!callback.is_null()); | |
| 387 DCHECK(!directory_fetch_info.empty()); | |
|
Haruki Sato
2013/04/10 03:44:35
Also this method assumes it's request for <drive>?
hidehiko
2013/04/10 06:11:19
Done.
| |
| 388 | |
| 389 if (error == DRIVE_FILE_OK) { | |
| 390 // MyDrive root already exists. Just return success. | |
| 391 callback.Run(DRIVE_FILE_OK); | |
| 392 return; | |
| 393 } | |
| 394 | |
| 395 // Fetch root resource id from the server. | |
| 396 scheduler_->GetAboutResource( | |
| 397 base::Bind( | |
| 398 &ChangeListLoader::DoLoadDirectoryFromServerAfterGetAboutResource, | |
| 399 weak_ptr_factory_.GetWeakPtr(), | |
| 400 directory_fetch_info, | |
| 401 callback)); | |
| 402 } | |
| 403 | |
| 404 void ChangeListLoader::DoLoadDirectoryFromServerAfterGetAboutResource( | |
| 405 const DirectoryFetchInfo& directory_fetch_info, | |
| 406 const FileOperationCallback& callback, | |
| 407 google_apis::GDataErrorCode status, | |
| 408 scoped_ptr<google_apis::AboutResource> about_resource) { | |
| 409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 410 DCHECK(!callback.is_null()); | |
| 411 DCHECK(!directory_fetch_info.empty()); | |
| 412 | |
| 413 DriveFileError error = util::GDataToDriveFileError(status); | |
| 414 if (error != DRIVE_FILE_OK) { | |
| 415 callback.Run(error); | |
| 416 return; | |
| 417 } | |
| 418 | |
| 419 // Build entry proto map for grand root directory, which has two entries; | |
| 420 // "/drive/root" and "/drive/other". | |
| 421 DriveEntryProtoMap grand_root_entry_proto_map; | |
| 422 const std::string& root_resource_id = about_resource->root_folder_id(); | |
| 423 grand_root_entry_proto_map[root_resource_id] = | |
| 424 util::CreateMyDriveRootEntry(root_resource_id); | |
| 425 grand_root_entry_proto_map[util::kDriveOtherDirSpecialResourceId] = | |
| 426 util::CreateOtherDirEntry(); | |
| 427 resource_metadata_->RefreshDirectory( | |
|
Haruki Sato
2013/04/10 03:44:35
Any reason to use RefreshDirectory rather than Add
hidehiko
2013/04/10 06:11:19
Two reasons:
1) AddEntry returns an error if the e
| |
| 428 directory_fetch_info, | |
| 429 grand_root_entry_proto_map, | |
| 430 base::Bind(&ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh, | |
| 431 weak_ptr_factory_.GetWeakPtr(), | |
| 432 directory_fetch_info, | |
| 433 callback)); | |
| 434 } | |
| 435 | |
| 361 void ChangeListLoader::DoLoadDirectoryFromServerAfterLoad( | 436 void ChangeListLoader::DoLoadDirectoryFromServerAfterLoad( |
| 362 const DirectoryFetchInfo& directory_fetch_info, | 437 const DirectoryFetchInfo& directory_fetch_info, |
| 363 const FileOperationCallback& callback, | 438 const FileOperationCallback& callback, |
| 364 ScopedVector<ChangeList> change_lists, | 439 ScopedVector<ChangeList> change_lists, |
| 365 DriveFileError error) { | 440 DriveFileError error) { |
| 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 367 DCHECK(!callback.is_null()); | 442 DCHECK(!callback.is_null()); |
| 368 DCHECK(!directory_fetch_info.empty()); | 443 DCHECK(!directory_fetch_info.empty()); |
| 369 | 444 |
| 370 if (error != DRIVE_FILE_OK) { | 445 if (error != DRIVE_FILE_OK) { |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 772 for (size_t i = 0; i < callbacks.size(); ++i) { | 847 for (size_t i = 0; i < callbacks.size(); ++i) { |
| 773 base::MessageLoopProxy::current()->PostTask( | 848 base::MessageLoopProxy::current()->PostTask( |
| 774 FROM_HERE, | 849 FROM_HERE, |
| 775 base::Bind(callbacks[i], error)); | 850 base::Bind(callbacks[i], error)); |
| 776 } | 851 } |
| 777 pending_load_callback_.erase(it); | 852 pending_load_callback_.erase(it); |
| 778 } | 853 } |
| 779 } | 854 } |
| 780 | 855 |
| 781 } // namespace drive | 856 } // namespace drive |
| OLD | NEW |