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 "components/drive/chromeos/resource_metadata.h" | 5 #include "components/drive/chromeos/resource_metadata.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 if (it->HasError()) | 115 if (it->HasError()) |
116 return FILE_ERROR_FAILED; | 116 return FILE_ERROR_FAILED; |
117 | 117 |
118 return SetUpDefaultEntries(); | 118 return SetUpDefaultEntries(); |
119 } | 119 } |
120 | 120 |
121 ResourceMetadata::~ResourceMetadata() { | 121 ResourceMetadata::~ResourceMetadata() { |
122 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 122 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
123 } | 123 } |
124 | 124 |
125 FileError ResourceMetadata::AddTeamDrive(const std::string& id, | |
hashimoto
2017/04/06 10:23:36
Do we need these new methods?
I think the same thi
yamaguchi
2017/04/07 03:57:43
Changed to have them processed as normal Entries.
| |
126 const std::string& name) { | |
127 ResourceEntry entry; | |
128 FileError error = storage_->GetEntry(id, &entry); | |
129 if (error != FILE_ERROR_NOT_FOUND) { | |
130 return FILE_ERROR_EXISTS; | |
131 } | |
132 ResourceEntry team_drive; | |
133 team_drive.mutable_file_info()->set_is_directory(true); | |
134 team_drive.set_local_id(id); | |
135 team_drive.set_parent_local_id(util::kDriveTeamDrivesDirLocalId); | |
136 team_drive.set_title(name.empty() ? id : name); | |
137 team_drive.set_resource_id(id); | |
138 return PutEntryUnderDirectory(team_drive); | |
139 } | |
140 | |
141 FileError ResourceMetadata::RefreshTeamDrive(const std::string& id, | |
142 const std::string& name) { | |
143 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | |
144 | |
145 if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path())) | |
146 return FILE_ERROR_NO_LOCAL_SPACE; | |
147 | |
148 ResourceEntry old_entry; | |
149 FileError error = storage_->GetEntry(id, &old_entry); | |
150 if (error != FILE_ERROR_OK) | |
151 return error; | |
152 | |
153 if (IsImmutableEntry(id) || | |
154 old_entry.file_info().is_directory() != // Reject incompatible input. | |
155 true) | |
156 return FILE_ERROR_INVALID_OPERATION; | |
157 | |
158 if (!id.empty()) { | |
159 // Multiple entries cannot share the same resource ID. | |
160 std::string local_id; | |
161 FileError error = GetIdByResourceId(id, &local_id); | |
162 switch (error) { | |
163 case FILE_ERROR_OK: | |
164 if (local_id != id) | |
165 return FILE_ERROR_INVALID_OPERATION; | |
166 break; | |
167 | |
168 case FILE_ERROR_NOT_FOUND: | |
169 break; | |
170 | |
171 default: | |
172 return error; | |
173 } | |
174 } | |
175 | |
176 ResourceEntry updated_entry(old_entry); | |
177 updated_entry.set_title(name); | |
178 // Remove from the old parent and add it to the new parent with the new data. | |
179 return PutEntryUnderDirectory(updated_entry); | |
180 } | |
181 | |
125 FileError ResourceMetadata::SetUpDefaultEntries() { | 182 FileError ResourceMetadata::SetUpDefaultEntries() { |
126 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 183 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
127 | 184 |
128 // Initialize "/drive". | 185 // Initialize "/drive". |
129 ResourceEntry entry; | 186 ResourceEntry entry; |
130 FileError error = storage_->GetEntry(util::kDriveGrandRootLocalId, &entry); | 187 FileError error = storage_->GetEntry(util::kDriveGrandRootLocalId, &entry); |
131 if (error == FILE_ERROR_NOT_FOUND) { | 188 if (error == FILE_ERROR_NOT_FOUND) { |
132 ResourceEntry root; | 189 ResourceEntry root; |
133 root.mutable_file_info()->set_is_directory(true); | 190 root.mutable_file_info()->set_is_directory(true); |
134 root.set_local_id(util::kDriveGrandRootLocalId); | 191 root.set_local_id(util::kDriveGrandRootLocalId); |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 | 679 |
623 error = cache_->Remove(id); | 680 error = cache_->Remove(id); |
624 if (error != FILE_ERROR_OK) | 681 if (error != FILE_ERROR_OK) |
625 return error; | 682 return error; |
626 | 683 |
627 return storage_->RemoveEntry(id); | 684 return storage_->RemoveEntry(id); |
628 } | 685 } |
629 | 686 |
630 } // namespace internal | 687 } // namespace internal |
631 } // namespace drive | 688 } // namespace drive |
OLD | NEW |