| 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/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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 "/drive", "/drive/other" and "drive/trash". | 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. | |
| 123 root.set_resource_id(util::kDriveGrandRootLocalId); | |
| 124 root.set_local_id(util::kDriveGrandRootLocalId); | 122 root.set_local_id(util::kDriveGrandRootLocalId); |
| 125 root.set_title(util::kDriveGrandRootDirName); | 123 root.set_title(util::kDriveGrandRootDirName); |
| 126 SetBaseNameFromTitle(&root); | 124 SetBaseNameFromTitle(&root); |
| 127 if (!storage_->PutEntry(root)) | 125 if (!storage_->PutEntry(root)) |
| 128 return false; | 126 return false; |
| 127 } else if (!entry.resource_id().empty()) { |
| 128 // Old implementations used kDriveGrandRootLocalId as a resource ID. |
| 129 entry.clear_resource_id(); |
| 130 if (!storage_->PutEntry(entry)) |
| 131 return false; |
| 129 } | 132 } |
| 130 if (!storage_->GetEntry(util::kDriveOtherDirLocalId, &entry)) { | 133 if (!storage_->GetEntry(util::kDriveOtherDirLocalId, &entry)) { |
| 131 ResourceEntry other_dir; | 134 ResourceEntry other_dir; |
| 132 other_dir.mutable_file_info()->set_is_directory(true); | 135 other_dir.mutable_file_info()->set_is_directory(true); |
| 133 // TODO(hashimoto): Stop setting dummy resource ID here. | |
| 134 other_dir.set_resource_id(util::kDriveOtherDirLocalId); | |
| 135 other_dir.set_local_id(util::kDriveOtherDirLocalId); | 136 other_dir.set_local_id(util::kDriveOtherDirLocalId); |
| 136 other_dir.set_parent_local_id(util::kDriveGrandRootLocalId); | 137 other_dir.set_parent_local_id(util::kDriveGrandRootLocalId); |
| 137 other_dir.set_title(util::kDriveOtherDirName); | 138 other_dir.set_title(util::kDriveOtherDirName); |
| 138 if (!PutEntryUnderDirectory(other_dir)) | 139 if (!PutEntryUnderDirectory(other_dir)) |
| 139 return false; | 140 return false; |
| 141 } else if (!entry.resource_id().empty()) { |
| 142 // Old implementations used kDriveOtherDirLocalId as a resource ID. |
| 143 entry.clear_resource_id(); |
| 144 if (!storage_->PutEntry(entry)) |
| 145 return false; |
| 140 } | 146 } |
| 141 if (!storage_->GetEntry(util::kDriveTrashDirLocalId, &entry)) { | 147 if (!storage_->GetEntry(util::kDriveTrashDirLocalId, &entry)) { |
| 142 ResourceEntry trash_dir; | 148 ResourceEntry trash_dir; |
| 143 trash_dir.mutable_file_info()->set_is_directory(true); | 149 trash_dir.mutable_file_info()->set_is_directory(true); |
| 144 trash_dir.set_local_id(util::kDriveTrashDirLocalId); | 150 trash_dir.set_local_id(util::kDriveTrashDirLocalId); |
| 145 trash_dir.set_parent_local_id(util::kDriveGrandRootLocalId); | 151 trash_dir.set_parent_local_id(util::kDriveGrandRootLocalId); |
| 146 trash_dir.set_title(util::kDriveTrashDirName); | 152 trash_dir.set_title(util::kDriveTrashDirName); |
| 147 if (!PutEntryUnderDirectory(trash_dir)) | 153 if (!PutEntryUnderDirectory(trash_dir)) |
| 148 return false; | 154 return false; |
| 149 } | 155 } |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 for (size_t i = 0; i < children.size(); ++i) { | 474 for (size_t i = 0; i < children.size(); ++i) { |
| 469 if (!RemoveEntryRecursively(children[i])) | 475 if (!RemoveEntryRecursively(children[i])) |
| 470 return false; | 476 return false; |
| 471 } | 477 } |
| 472 } | 478 } |
| 473 return storage_->RemoveEntry(id); | 479 return storage_->RemoveEntry(id); |
| 474 } | 480 } |
| 475 | 481 |
| 476 } // namespace internal | 482 } // namespace internal |
| 477 } // namespace drive | 483 } // namespace drive |
| OLD | NEW |