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

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

Issue 66293005: drive: Add drive/trash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix RemoveEntry Created 7 years, 1 month 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/resource_metadata.h" 5 #include "chrome/browser/chromeos/drive/resource_metadata.h"
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return FILE_ERROR_OK; 107 return FILE_ERROR_OK;
108 } 108 }
109 109
110 ResourceMetadata::~ResourceMetadata() { 110 ResourceMetadata::~ResourceMetadata() {
111 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); 111 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
112 } 112 }
113 113
114 bool ResourceMetadata::SetUpDefaultEntries() { 114 bool ResourceMetadata::SetUpDefaultEntries() {
115 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); 115 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
116 116
117 // Initialize the grand root and "other" entries. "/drive" and "/drive/other". 117 // Initialize "/drive", "/drive/other" and "drive/trash".
118 ResourceEntry entry; 118 ResourceEntry entry;
119 if (!storage_->GetEntry(util::kDriveGrandRootLocalId, &entry)) { 119 if (!storage_->GetEntry(util::kDriveGrandRootLocalId, &entry)) {
120 ResourceEntry root; 120 ResourceEntry root;
121 root.mutable_file_info()->set_is_directory(true); 121 root.mutable_file_info()->set_is_directory(true);
122 // TODO(hashimoto): Stop setting dummy resource ID here. 122 // TODO(hashimoto): Stop setting dummy resource ID here.
123 root.set_resource_id(util::kDriveGrandRootLocalId); 123 root.set_resource_id(util::kDriveGrandRootLocalId);
124 root.set_local_id(util::kDriveGrandRootLocalId); 124 root.set_local_id(util::kDriveGrandRootLocalId);
125 root.set_title(util::kDriveGrandRootDirName); 125 root.set_title(util::kDriveGrandRootDirName);
126 SetBaseNameFromTitle(&root); 126 SetBaseNameFromTitle(&root);
127 if (!storage_->PutEntry(root)) 127 if (!storage_->PutEntry(root))
128 return false; 128 return false;
129 } 129 }
130 if (!storage_->GetEntry(util::kDriveOtherDirLocalId, &entry)) { 130 if (!storage_->GetEntry(util::kDriveOtherDirLocalId, &entry)) {
131 ResourceEntry other_dir; 131 ResourceEntry other_dir;
132 other_dir.mutable_file_info()->set_is_directory(true); 132 other_dir.mutable_file_info()->set_is_directory(true);
133 // TODO(hashimoto): Stop setting dummy resource ID here. 133 // TODO(hashimoto): Stop setting dummy resource ID here.
134 other_dir.set_resource_id(util::kDriveOtherDirLocalId); 134 other_dir.set_resource_id(util::kDriveOtherDirLocalId);
135 other_dir.set_local_id(util::kDriveOtherDirLocalId); 135 other_dir.set_local_id(util::kDriveOtherDirLocalId);
136 other_dir.set_parent_local_id(util::kDriveGrandRootLocalId); 136 other_dir.set_parent_local_id(util::kDriveGrandRootLocalId);
137 other_dir.set_title(util::kDriveOtherDirName); 137 other_dir.set_title(util::kDriveOtherDirName);
138 if (!PutEntryUnderDirectory(other_dir)) 138 if (!PutEntryUnderDirectory(other_dir))
139 return false; 139 return false;
140 } 140 }
141 if (!storage_->GetEntry(util::kDriveTrashDirLocalId, &entry)) {
142 ResourceEntry trash_dir;
143 trash_dir.mutable_file_info()->set_is_directory(true);
144 trash_dir.set_local_id(util::kDriveTrashDirLocalId);
145 trash_dir.set_parent_local_id(util::kDriveGrandRootLocalId);
146 trash_dir.set_title(util::kDriveTrashDirName);
147 if (!PutEntryUnderDirectory(trash_dir))
148 return false;
149 }
141 return true; 150 return true;
142 } 151 }
143 152
144 void ResourceMetadata::DestroyOnBlockingPool() { 153 void ResourceMetadata::DestroyOnBlockingPool() {
145 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); 154 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
146 delete this; 155 delete this;
147 } 156 }
148 157
149 int64 ResourceMetadata::GetLargestChangestamp() { 158 int64 ResourceMetadata::GetLargestChangestamp() {
150 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); 159 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 *out_id = local_id; 204 *out_id = local_id;
196 return FILE_ERROR_OK; 205 return FILE_ERROR_OK;
197 } 206 }
198 207
199 FileError ResourceMetadata::RemoveEntry(const std::string& id) { 208 FileError ResourceMetadata::RemoveEntry(const std::string& id) {
200 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); 209 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
201 210
202 if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path())) 211 if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path()))
203 return FILE_ERROR_NO_LOCAL_SPACE; 212 return FILE_ERROR_NO_LOCAL_SPACE;
204 213
205 // Disallow deletion of special entries "/drive" and "/drive/other". 214 // Disallow deletion of default entries.
206 if (util::IsSpecialResourceId(id)) 215 if (id == util::kDriveGrandRootLocalId ||
216 id == util::kDriveOtherDirLocalId ||
217 id == util::kDriveTrashDirLocalId)
207 return FILE_ERROR_ACCESS_DENIED; 218 return FILE_ERROR_ACCESS_DENIED;
208 219
209 ResourceEntry entry; 220 ResourceEntry entry;
210 if (!storage_->GetEntry(id, &entry)) 221 if (!storage_->GetEntry(id, &entry))
211 return FILE_ERROR_NOT_FOUND; 222 return FILE_ERROR_NOT_FOUND;
212 223
213 if (!RemoveEntryRecursively(id)) 224 if (!RemoveEntryRecursively(id))
214 return FILE_ERROR_FAILED; 225 return FILE_ERROR_FAILED;
215 return FILE_ERROR_OK; 226 return FILE_ERROR_OK;
216 } 227 }
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 for (size_t i = 0; i < children.size(); ++i) { 468 for (size_t i = 0; i < children.size(); ++i) {
458 if (!RemoveEntryRecursively(children[i])) 469 if (!RemoveEntryRecursively(children[i]))
459 return false; 470 return false;
460 } 471 }
461 } 472 }
462 return storage_->RemoveEntry(id); 473 return storage_->RemoveEntry(id);
463 } 474 }
464 475
465 } // namespace internal 476 } // namespace internal
466 } // namespace drive 477 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system_util.h ('k') | chrome/browser/chromeos/drive/resource_metadata_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698