Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/chromeos/drive/change_list_processor.cc

Issue 107293013: drive: Stop comparing resource ID against kDriveGrandRootLocalId (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_processor.h" 5 #include "chrome/browser/chromeos/drive/change_list_processor.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "chrome/browser/chromeos/drive/drive.pb.h" 9 #include "chrome/browser/chromeos/drive/drive.pb.h"
10 #include "chrome/browser/chromeos/drive/file_system_util.h" 10 #include "chrome/browser/chromeos/drive/file_system_util.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 private: 50 private:
51 int num_regular_files_; 51 int num_regular_files_;
52 int num_hosted_documents_; 52 int num_hosted_documents_;
53 int num_shared_with_me_entries_; 53 int num_shared_with_me_entries_;
54 }; 54 };
55 55
56 } // namespace 56 } // namespace
57 57
58 std::string DirectoryFetchInfo::ToString() const { 58 std::string DirectoryFetchInfo::ToString() const {
59 return ("resource_id: " + resource_id_ + 59 return ("local_id: " + local_id_ +
60 ", resource_id: " + resource_id_ +
60 ", changestamp: " + base::Int64ToString(changestamp_)); 61 ", changestamp: " + base::Int64ToString(changestamp_));
61 } 62 }
62 63
63 ChangeList::ChangeList() {} 64 ChangeList::ChangeList() {}
64 65
65 ChangeList::ChangeList(const google_apis::ResourceList& resource_list) 66 ChangeList::ChangeList(const google_apis::ResourceList& resource_list)
66 : largest_changestamp_(resource_list.largest_changestamp()) { 67 : largest_changestamp_(resource_list.largest_changestamp()) {
67 resource_list.GetNextFeedURL(&next_url_); 68 resource_list.GetNextFeedURL(&next_url_);
68 69
69 entries_.resize(resource_list.entries().size()); 70 entries_.resize(resource_list.entries().size());
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 351 }
351 352
352 // static 353 // static
353 FileError ChangeListProcessor::RefreshDirectory( 354 FileError ChangeListProcessor::RefreshDirectory(
354 ResourceMetadata* resource_metadata, 355 ResourceMetadata* resource_metadata,
355 const DirectoryFetchInfo& directory_fetch_info, 356 const DirectoryFetchInfo& directory_fetch_info,
356 ScopedVector<ChangeList> change_lists, 357 ScopedVector<ChangeList> change_lists,
357 base::FilePath* out_file_path) { 358 base::FilePath* out_file_path) {
358 DCHECK(!directory_fetch_info.empty()); 359 DCHECK(!directory_fetch_info.empty());
359 360
360 std::string directory_local_id; 361 ResourceEntry directory;
361 FileError error = resource_metadata->GetIdByResourceId( 362 FileError error = resource_metadata->GetResourceEntryById(
362 directory_fetch_info.resource_id(), &directory_local_id); 363 directory_fetch_info.local_id(), &directory);
363 if (error != FILE_ERROR_OK) 364 if (error != FILE_ERROR_OK)
364 return error; 365 return error;
365 366
366 ResourceEntry directory;
367 error = resource_metadata->GetResourceEntryById(directory_local_id,
368 &directory);
369 if (error != FILE_ERROR_OK)
370 return error;
371
372 if (!directory.file_info().is_directory()) 367 if (!directory.file_info().is_directory())
373 return FILE_ERROR_NOT_A_DIRECTORY; 368 return FILE_ERROR_NOT_A_DIRECTORY;
374 369
375 for (size_t i = 0; i < change_lists.size(); ++i) { 370 for (size_t i = 0; i < change_lists.size(); ++i) {
376 ChangeList* change_list = change_lists[i]; 371 ChangeList* change_list = change_lists[i];
377 std::vector<ResourceEntry>* entries = change_list->mutable_entries(); 372 std::vector<ResourceEntry>* entries = change_list->mutable_entries();
378 for (size_t i = 0; i < entries->size(); ++i) { 373 for (size_t i = 0; i < entries->size(); ++i) {
379 ResourceEntry* entry = &(*entries)[i]; 374 ResourceEntry* entry = &(*entries)[i];
380 const std::string& parent_resource_id = 375 const std::string& parent_resource_id =
381 change_list->parent_resource_ids()[i]; 376 change_list->parent_resource_ids()[i];
382 377
383 // Skip if the parent resource ID does not match. This is needed to 378 // Skip if the parent resource ID does not match. This is needed to
384 // handle entries with multiple parents. For such entries, the first 379 // handle entries with multiple parents. For such entries, the first
385 // parent is picked and other parents are ignored, hence some entries may 380 // parent is picked and other parents are ignored, hence some entries may
386 // have a parent resource ID which does not match the target directory's. 381 // have a parent resource ID which does not match the target directory's.
387 if (parent_resource_id != directory_fetch_info.resource_id()) { 382 if (parent_resource_id != directory_fetch_info.resource_id()) {
388 DVLOG(1) << "Wrong-parent entry rejected: " << entry->resource_id(); 383 DVLOG(1) << "Wrong-parent entry rejected: " << entry->resource_id();
389 continue; 384 continue;
390 } 385 }
391 386
392 entry->set_parent_local_id(directory_local_id); 387 entry->set_parent_local_id(directory_fetch_info.local_id());
393 388
394 std::string local_id; 389 std::string local_id;
395 error = resource_metadata->GetIdByResourceId(entry->resource_id(), 390 error = resource_metadata->GetIdByResourceId(entry->resource_id(),
396 &local_id); 391 &local_id);
397 if (error == FILE_ERROR_OK) { 392 if (error == FILE_ERROR_OK) {
398 entry->set_local_id(local_id); 393 entry->set_local_id(local_id);
399 error = resource_metadata->RefreshEntry(*entry); 394 error = resource_metadata->RefreshEntry(*entry);
400 } 395 }
401 396
402 if (error == FILE_ERROR_NOT_FOUND) { // If refreshing fails, try adding. 397 if (error == FILE_ERROR_NOT_FOUND) { // If refreshing fails, try adding.
403 std::string local_id; 398 std::string local_id;
404 entry->clear_local_id(); 399 entry->clear_local_id();
405 error = resource_metadata->AddEntry(*entry, &local_id); 400 error = resource_metadata->AddEntry(*entry, &local_id);
406 } 401 }
407 402
408 if (error != FILE_ERROR_OK) 403 if (error != FILE_ERROR_OK)
409 return error; 404 return error;
410 } 405 }
411 } 406 }
412 407
413 directory.mutable_directory_specific_info()->set_changestamp( 408 directory.mutable_directory_specific_info()->set_changestamp(
414 directory_fetch_info.changestamp()); 409 directory_fetch_info.changestamp());
415 error = resource_metadata->RefreshEntry(directory); 410 error = resource_metadata->RefreshEntry(directory);
416 if (error != FILE_ERROR_OK) 411 if (error != FILE_ERROR_OK)
417 return error; 412 return error;
418 413
419 *out_file_path = resource_metadata->GetFilePath(directory_local_id); 414 *out_file_path = resource_metadata->GetFilePath(
415 directory_fetch_info.local_id());
420 return FILE_ERROR_OK; 416 return FILE_ERROR_OK;
421 } 417 }
422 418
423 // static 419 // static
424 FileError ChangeListProcessor::SetParentLocalIdOfEntry( 420 FileError ChangeListProcessor::SetParentLocalIdOfEntry(
425 ResourceMetadata* resource_metadata, 421 ResourceMetadata* resource_metadata,
426 ResourceEntry* entry, 422 ResourceEntry* entry,
427 const std::string& parent_resource_id) { 423 const std::string& parent_resource_id) {
428 std::string parent_local_id; 424 std::string parent_local_id;
429 if (parent_resource_id.empty()) { 425 if (parent_resource_id.empty()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 resource_metadata_->GetSubDirectoriesRecursively(local_id, 458 resource_metadata_->GetSubDirectoriesRecursively(local_id,
463 &sub_directories); 459 &sub_directories);
464 changed_dirs_.insert(sub_directories.begin(), sub_directories.end()); 460 changed_dirs_.insert(sub_directories.begin(), sub_directories.end());
465 } 461 }
466 } 462 }
467 } 463 }
468 } 464 }
469 465
470 } // namespace internal 466 } // namespace internal
471 } // namespace drive 467 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/change_list_processor.h ('k') | chrome/browser/chromeos/drive/change_list_processor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698