| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/file_system/create_directory_operation.h
" | 5 #include "chrome/browser/chromeos/drive/file_system/create_directory_operation.h
" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/drive/drive.pb.h" | 7 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 8 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" | 8 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" |
| 9 #include "chrome/browser/chromeos/drive/file_system_util.h" | 9 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 10 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 10 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 entry.mutable_file_info()->set_last_accessed(now.ToInternalValue()); | 39 entry.mutable_file_info()->set_last_accessed(now.ToInternalValue()); |
| 40 entry.set_parent_local_id(parent_local_id); | 40 entry.set_parent_local_id(parent_local_id); |
| 41 entry.set_metadata_edit_state(ResourceEntry::DIRTY); | 41 entry.set_metadata_edit_state(ResourceEntry::DIRTY); |
| 42 entry.set_modification_date(base::Time::Now().ToInternalValue()); | 42 entry.set_modification_date(base::Time::Now().ToInternalValue()); |
| 43 | 43 |
| 44 std::string local_id; | 44 std::string local_id; |
| 45 FileError error = metadata->AddEntry(entry, &local_id); | 45 FileError error = metadata->AddEntry(entry, &local_id); |
| 46 if (error != FILE_ERROR_OK) | 46 if (error != FILE_ERROR_OK) |
| 47 return error; | 47 return error; |
| 48 | 48 |
| 49 base::FilePath path; |
| 50 error = metadata->GetFilePath(local_id, &path); |
| 51 if (error != FILE_ERROR_OK) |
| 52 return error; |
| 53 |
| 49 updated_local_ids->insert(local_id); | 54 updated_local_ids->insert(local_id); |
| 50 changed_directories->insert(metadata->GetFilePath(local_id).DirName()); | 55 changed_directories->insert(path.DirName()); |
| 51 | 56 |
| 52 if (remaining_path.empty()) // All directories are created successfully. | 57 if (remaining_path.empty()) // All directories are created successfully. |
| 53 return FILE_ERROR_OK; | 58 return FILE_ERROR_OK; |
| 54 | 59 |
| 55 // Create descendant directories. | 60 // Create descendant directories. |
| 56 return CreateDirectoryRecursively(metadata, local_id, remaining_path, | 61 return CreateDirectoryRecursively(metadata, local_id, remaining_path, |
| 57 updated_local_ids, changed_directories); | 62 updated_local_ids, changed_directories); |
| 58 } | 63 } |
| 59 | 64 |
| 60 FileError UpdateLocalState(internal::ResourceMetadata* metadata, | 65 FileError UpdateLocalState(internal::ResourceMetadata* metadata, |
| 61 const base::FilePath& directory_path, | 66 const base::FilePath& directory_path, |
| 62 bool is_exclusive, | 67 bool is_exclusive, |
| 63 bool is_recursive, | 68 bool is_recursive, |
| 64 std::set<std::string>* updated_local_ids, | 69 std::set<std::string>* updated_local_ids, |
| 65 std::set<base::FilePath>* changed_directories) { | 70 std::set<base::FilePath>* changed_directories) { |
| 66 // Get the existing deepest entry. | 71 // Get the existing deepest entry. |
| 67 std::vector<base::FilePath::StringType> components; | 72 std::vector<base::FilePath::StringType> components; |
| 68 directory_path.GetComponents(&components); | 73 directory_path.GetComponents(&components); |
| 69 | 74 |
| 70 if (components.empty() || components[0] != util::kDriveGrandRootDirName) | 75 if (components.empty() || components[0] != util::kDriveGrandRootDirName) |
| 71 return FILE_ERROR_NOT_FOUND; | 76 return FILE_ERROR_NOT_FOUND; |
| 72 | 77 |
| 73 base::FilePath existing_deepest_path(components[0]); | 78 base::FilePath existing_deepest_path(components[0]); |
| 74 std::string local_id = util::kDriveGrandRootLocalId; | 79 std::string local_id = util::kDriveGrandRootLocalId; |
| 75 for (size_t i = 1; i < components.size(); ++i) { | 80 for (size_t i = 1; i < components.size(); ++i) { |
| 76 std::string child_local_id = metadata->GetChildId(local_id, components[i]); | 81 std::string child_local_id; |
| 77 if (child_local_id.empty()) | 82 FileError error = |
| 83 metadata->GetChildId(local_id, components[i], &child_local_id); |
| 84 if (error == FILE_ERROR_NOT_FOUND) |
| 78 break; | 85 break; |
| 86 if (error != FILE_ERROR_OK) |
| 87 return error; |
| 79 existing_deepest_path = existing_deepest_path.Append(components[i]); | 88 existing_deepest_path = existing_deepest_path.Append(components[i]); |
| 80 local_id = child_local_id; | 89 local_id = child_local_id; |
| 81 } | 90 } |
| 82 | 91 |
| 83 ResourceEntry entry; | 92 ResourceEntry entry; |
| 84 FileError error = metadata->GetResourceEntryById(local_id, &entry); | 93 FileError error = metadata->GetResourceEntryById(local_id, &entry); |
| 85 if (error != FILE_ERROR_OK) | 94 if (error != FILE_ERROR_OK) |
| 86 return error; | 95 return error; |
| 87 | 96 |
| 88 if (!entry.file_info().is_directory()) | 97 if (!entry.file_info().is_directory()) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 167 |
| 159 for (std::set<base::FilePath>::const_iterator it = | 168 for (std::set<base::FilePath>::const_iterator it = |
| 160 changed_directories->begin(); it != changed_directories->end(); ++it) | 169 changed_directories->begin(); it != changed_directories->end(); ++it) |
| 161 observer_->OnDirectoryChangedByOperation(*it); | 170 observer_->OnDirectoryChangedByOperation(*it); |
| 162 | 171 |
| 163 callback.Run(error); | 172 callback.Run(error); |
| 164 } | 173 } |
| 165 | 174 |
| 166 } // namespace file_system | 175 } // namespace file_system |
| 167 } // namespace drive | 176 } // namespace drive |
| OLD | NEW |