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/gdata/gdata_files.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/platform_file.h" | 9 #include "base/platform_file.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 // GDataFileSystem has already locked. | 460 // GDataFileSystem has already locked. |
461 DVLOG(1) << "AddEntryToResourceMap " << entry->resource_id(); | 461 DVLOG(1) << "AddEntryToResourceMap " << entry->resource_id(); |
462 resource_map_.insert(std::make_pair(entry->resource_id(), entry)); | 462 resource_map_.insert(std::make_pair(entry->resource_id(), entry)); |
463 } | 463 } |
464 | 464 |
465 void GDataDirectoryService::RemoveEntryFromResourceMap(GDataEntry* entry) { | 465 void GDataDirectoryService::RemoveEntryFromResourceMap(GDataEntry* entry) { |
466 // GDataFileSystem has already locked. | 466 // GDataFileSystem has already locked. |
467 resource_map_.erase(entry->resource_id()); | 467 resource_map_.erase(entry->resource_id()); |
468 } | 468 } |
469 | 469 |
470 void GDataDirectoryService::FindEntryByPath(const FilePath& file_path, | 470 GDataEntry* GDataDirectoryService::FindEntryByPathSync( |
471 const FindEntryCallback& callback) { | 471 const FilePath& file_path) { |
472 // GDataFileSystem has already locked. | |
473 DCHECK(!callback.is_null()); | |
474 | |
475 std::vector<FilePath::StringType> components; | 472 std::vector<FilePath::StringType> components; |
476 file_path.GetComponents(&components); | 473 file_path.GetComponents(&components); |
477 | 474 |
478 GDataDirectory* current_dir = root_.get(); | 475 GDataDirectory* current_dir = root_.get(); |
479 FilePath directory_path; | 476 FilePath directory_path; |
480 | 477 |
481 for (size_t i = 0; i < components.size() && current_dir; i++) { | 478 for (size_t i = 0; i < components.size() && current_dir; i++) { |
482 directory_path = directory_path.Append(current_dir->base_name()); | 479 directory_path = directory_path.Append(current_dir->base_name()); |
483 | 480 |
484 // Last element must match, if not last then it must be a directory. | 481 // Last element must match, if not last then it must be a directory. |
485 if (i == components.size() - 1) { | 482 if (i == components.size() - 1) { |
486 if (current_dir->base_name() == components[i]) | 483 if (current_dir->base_name() == components[i]) |
487 callback.Run(GDATA_FILE_OK, current_dir); | 484 return current_dir; |
488 else | 485 else |
489 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, NULL); | 486 return NULL; |
490 return; | |
491 } | 487 } |
492 | 488 |
493 // Not the last part of the path, search for the next segment. | 489 // Not the last part of the path, search for the next segment. |
494 GDataEntry* entry = current_dir->FindChild(components[i + 1]); | 490 GDataEntry* entry = current_dir->FindChild(components[i + 1]); |
495 if (!entry) { | 491 if (!entry) { |
496 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, NULL); | 492 return NULL; |
497 return; | |
498 } | 493 } |
499 | 494 |
500 // Found file, must be the last segment. | 495 // Found file, must be the last segment. |
501 if (entry->file_info().is_directory) { | 496 if (entry->file_info().is_directory) { |
502 // Found directory, continue traversal. | 497 // Found directory, continue traversal. |
503 current_dir = entry->AsGDataDirectory(); | 498 current_dir = entry->AsGDataDirectory(); |
504 } else { | 499 } else { |
505 if ((i + 1) == (components.size() - 1)) | 500 if ((i + 1) == (components.size() - 1)) |
506 callback.Run(GDATA_FILE_OK, entry); | 501 return entry; |
507 else | 502 else |
508 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, NULL); | 503 return NULL; |
509 | |
510 return; | |
511 } | 504 } |
512 } | 505 } |
513 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, NULL); | 506 return NULL; |
514 } | 507 } |
515 | 508 |
516 GDataEntry* GDataDirectoryService::GetEntryByResourceId( | 509 GDataEntry* GDataDirectoryService::GetEntryByResourceId( |
517 const std::string& resource) { | 510 const std::string& resource) { |
518 // GDataFileSystem has already locked. | 511 // GDataFileSystem has already locked. |
519 ResourceMap::const_iterator iter = resource_map_.find(resource); | 512 ResourceMap::const_iterator iter = resource_map_.find(resource); |
520 return iter == resource_map_.end() ? NULL : iter->second; | 513 return iter == resource_map_.end() ? NULL : iter->second; |
521 } | 514 } |
522 | 515 |
523 void GDataDirectoryService::GetEntryByResourceIdAsync( | 516 void GDataDirectoryService::GetEntryByResourceIdAsync( |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 if (!root_->FromProto(proto.gdata_directory())) | 757 if (!root_->FromProto(proto.gdata_directory())) |
765 return false; | 758 return false; |
766 | 759 |
767 origin_ = FROM_CACHE; | 760 origin_ = FROM_CACHE; |
768 largest_changestamp_ = proto.largest_changestamp(); | 761 largest_changestamp_ = proto.largest_changestamp(); |
769 | 762 |
770 return true; | 763 return true; |
771 } | 764 } |
772 | 765 |
773 } // namespace gdata | 766 } // namespace gdata |
OLD | NEW |