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 "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 file_path.GetComponents(&components); | 512 file_path.GetComponents(&components); |
513 | 513 |
514 GDataDirectory* current_dir = this; | 514 GDataDirectory* current_dir = this; |
515 FilePath directory_path; | 515 FilePath directory_path; |
516 | 516 |
517 util::GDataSearchPathType path_type = | 517 util::GDataSearchPathType path_type = |
518 util::GetSearchPathStatusForPathComponents(components); | 518 util::GetSearchPathStatusForPathComponents(components); |
519 | 519 |
520 if (path_type == util::GDATA_SEARCH_PATH_ROOT || | 520 if (path_type == util::GDATA_SEARCH_PATH_ROOT || |
521 path_type == util::GDATA_SEARCH_PATH_QUERY) { | 521 path_type == util::GDATA_SEARCH_PATH_QUERY) { |
522 callback.Run(base::PLATFORM_FILE_OK, fake_search_directory_.get()); | 522 callback.Run(base::PLATFORM_FILE_OK, file_path.DirName(), |
| 523 fake_search_directory_.get()); |
523 return; | 524 return; |
524 } | 525 } |
525 | 526 |
526 // If the path is under search path, we have to modify paremeters for finding | 527 // If the path is under search path, we have to modify paremeters for finding |
527 // the entry. | 528 // the entry. |
528 if (path_type != util::GDATA_SEARCH_PATH_INVALID) { | 529 if (path_type != util::GDATA_SEARCH_PATH_INVALID) { |
529 if (!ModifyFindEntryParamsForSearchPath(file_path, | 530 if (!ModifyFindEntryParamsForSearchPath(file_path, |
530 &components, ¤t_dir, &directory_path)) { | 531 &components, ¤t_dir, &directory_path)) { |
531 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, NULL); | 532 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); |
532 return; | 533 return; |
533 } | 534 } |
534 } | 535 } |
535 | 536 |
536 for (size_t i = 0; i < components.size() && current_dir; i++) { | 537 for (size_t i = 0; i < components.size() && current_dir; i++) { |
537 directory_path = directory_path.Append(current_dir->file_name()); | 538 directory_path = directory_path.Append(current_dir->file_name()); |
538 | 539 |
539 // Last element must match, if not last then it must be a directory. | 540 // Last element must match, if not last then it must be a directory. |
540 if (i == components.size() - 1) { | 541 if (i == components.size() - 1) { |
541 if (current_dir->file_name() == components[i]) | 542 if (current_dir->file_name() == components[i]) |
542 callback.Run(base::PLATFORM_FILE_OK, current_dir); | 543 callback.Run(base::PLATFORM_FILE_OK, directory_path, current_dir); |
543 else | 544 else |
544 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, NULL); | 545 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); |
545 return; | 546 return; |
546 } | 547 } |
547 | 548 |
548 // Not the last part of the path, search for the next segment. | 549 // Not the last part of the path, search for the next segment. |
549 GDataEntry* entry = current_dir->FindChild(components[i + 1]); | 550 GDataEntry* entry = current_dir->FindChild(components[i + 1]); |
550 if (!entry) { | 551 if (!entry) { |
551 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, NULL); | 552 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); |
552 return; | 553 return; |
553 } | 554 } |
554 | 555 |
555 // Found file, must be the last segment. | 556 // Found file, must be the last segment. |
556 if (entry->file_info().is_directory) { | 557 if (entry->file_info().is_directory) { |
557 // Found directory, continue traversal. | 558 // Found directory, continue traversal. |
558 current_dir = entry->AsGDataDirectory(); | 559 current_dir = entry->AsGDataDirectory(); |
559 } else { | 560 } else { |
560 if ((i + 1) == (components.size() - 1)) | 561 if ((i + 1) == (components.size() - 1)) |
561 callback.Run(base::PLATFORM_FILE_OK, entry); | 562 callback.Run(base::PLATFORM_FILE_OK, directory_path, entry); |
562 else | 563 else |
563 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, NULL); | 564 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); |
564 | 565 |
565 return; | 566 return; |
566 } | 567 } |
567 } | 568 } |
568 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, NULL); | 569 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); |
569 } | 570 } |
570 | 571 |
571 GDataEntry* GDataRootDirectory::GetEntryByResourceId( | 572 GDataEntry* GDataRootDirectory::GetEntryByResourceId( |
572 const std::string& resource) { | 573 const std::string& resource) { |
573 // GDataFileSystem has already locked. | 574 // GDataFileSystem has already locked. |
574 ResourceMap::const_iterator iter = resource_map_.find(resource); | 575 ResourceMap::const_iterator iter = resource_map_.find(resource); |
575 if (iter == resource_map_.end()) | 576 if (iter == resource_map_.end()) |
576 return NULL; | 577 return NULL; |
577 return iter->second; | 578 return iter->second; |
578 } | 579 } |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 } | 876 } |
876 | 877 |
877 FromProto(*proto.get()); | 878 FromProto(*proto.get()); |
878 set_origin(FROM_CACHE); | 879 set_origin(FROM_CACHE); |
879 set_refresh_time(base::Time::Now()); | 880 set_refresh_time(base::Time::Now()); |
880 } | 881 } |
881 return ok; | 882 return ok; |
882 } | 883 } |
883 | 884 |
884 } // namespace gdata | 885 } // namespace gdata |
OLD | NEW |