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/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 return error; | 191 return error; |
192 } | 192 } |
193 return FILE_ERROR_OK; | 193 return FILE_ERROR_OK; |
194 } | 194 } |
195 | 195 |
196 void ResourceMetadata::DestroyOnBlockingPool() { | 196 void ResourceMetadata::DestroyOnBlockingPool() { |
197 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 197 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
198 delete this; | 198 delete this; |
199 } | 199 } |
200 | 200 |
201 int64 ResourceMetadata::GetLargestChangestamp() { | 201 FileError ResourceMetadata::GetLargestChangestamp(int64* out_value) { |
202 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 202 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
203 int64 value = 0; | 203 return storage_->GetLargestChangestamp(out_value); |
204 storage_->GetLargestChangestamp(&value); | |
205 return value; | |
206 } | 204 } |
207 | 205 |
208 FileError ResourceMetadata::SetLargestChangestamp(int64 value) { | 206 FileError ResourceMetadata::SetLargestChangestamp(int64 value) { |
209 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 207 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
210 | 208 |
211 if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path())) | 209 if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path())) |
212 return FILE_ERROR_NO_LOCAL_SPACE; | 210 return FILE_ERROR_NO_LOCAL_SPACE; |
213 | 211 |
214 return storage_->SetLargestChangestamp(value); | 212 return storage_->SetLargestChangestamp(value); |
215 } | 213 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 if (error != FILE_ERROR_OK) | 381 if (error != FILE_ERROR_OK) |
384 return error; | 382 return error; |
385 | 383 |
386 if (!new_parent.file_info().is_directory()) | 384 if (!new_parent.file_info().is_directory()) |
387 return FILE_ERROR_NOT_A_DIRECTORY; | 385 return FILE_ERROR_NOT_A_DIRECTORY; |
388 | 386 |
389 // Remove from the old parent and add it to the new parent with the new data. | 387 // Remove from the old parent and add it to the new parent with the new data. |
390 return PutEntryUnderDirectory(entry); | 388 return PutEntryUnderDirectory(entry); |
391 } | 389 } |
392 | 390 |
393 void ResourceMetadata::GetSubDirectoriesRecursively( | 391 FileError ResourceMetadata::GetSubDirectoriesRecursively( |
394 const std::string& id, | 392 const std::string& id, |
395 std::set<base::FilePath>* sub_directories) { | 393 std::set<base::FilePath>* sub_directories) { |
396 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 394 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
397 | 395 |
398 std::vector<std::string> children; | 396 std::vector<std::string> children; |
399 if (storage_->GetChildren(id, &children) != FILE_ERROR_OK) | 397 FileError error = storage_->GetChildren(id, &children); |
400 return; | 398 if (error != FILE_ERROR_OK) |
| 399 return error; |
401 for (size_t i = 0; i < children.size(); ++i) { | 400 for (size_t i = 0; i < children.size(); ++i) { |
402 ResourceEntry entry; | 401 ResourceEntry entry; |
403 if (storage_->GetEntry(children[i], &entry) != FILE_ERROR_OK) | 402 error = storage_->GetEntry(children[i], &entry); |
404 return; | 403 if (error != FILE_ERROR_OK) |
| 404 return error; |
405 if (entry.file_info().is_directory()) { | 405 if (entry.file_info().is_directory()) { |
406 sub_directories->insert(GetFilePath(children[i])); | 406 base::FilePath path; |
| 407 error = GetFilePath(children[i], &path); |
| 408 if (error != FILE_ERROR_OK) |
| 409 return error; |
| 410 sub_directories->insert(path); |
407 GetSubDirectoriesRecursively(children[i], sub_directories); | 411 GetSubDirectoriesRecursively(children[i], sub_directories); |
408 } | 412 } |
409 } | 413 } |
| 414 return FILE_ERROR_OK; |
410 } | 415 } |
411 | 416 |
412 std::string ResourceMetadata::GetChildId(const std::string& parent_local_id, | 417 FileError ResourceMetadata::GetChildId(const std::string& parent_local_id, |
413 const std::string& base_name) { | 418 const std::string& base_name, |
| 419 std::string* out_child_id) { |
414 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 420 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
415 std::string child_local_id; | 421 return storage_->GetChild(parent_local_id, base_name, out_child_id); |
416 storage_->GetChild(parent_local_id, base_name, &child_local_id); | |
417 return child_local_id; | |
418 } | 422 } |
419 | 423 |
420 scoped_ptr<ResourceMetadata::Iterator> ResourceMetadata::GetIterator() { | 424 scoped_ptr<ResourceMetadata::Iterator> ResourceMetadata::GetIterator() { |
421 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 425 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
422 | 426 |
423 return storage_->GetIterator(); | 427 return storage_->GetIterator(); |
424 } | 428 } |
425 | 429 |
426 base::FilePath ResourceMetadata::GetFilePath(const std::string& id) { | 430 FileError ResourceMetadata::GetFilePath(const std::string& id, |
| 431 base::FilePath* out_file_path) { |
427 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 432 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
428 | 433 |
| 434 ResourceEntry entry; |
| 435 FileError error = storage_->GetEntry(id, &entry); |
| 436 if (error != FILE_ERROR_OK) |
| 437 return error; |
| 438 |
429 base::FilePath path; | 439 base::FilePath path; |
430 ResourceEntry entry; | 440 if (!entry.parent_local_id().empty()) { |
431 if (storage_->GetEntry(id, &entry) == FILE_ERROR_OK) { | 441 error = GetFilePath(entry.parent_local_id(), &path); |
432 if (!entry.parent_local_id().empty()) { | 442 if (error != FILE_ERROR_OK) |
433 path = GetFilePath(entry.parent_local_id()); | 443 return error; |
434 } else if (entry.local_id() != util::kDriveGrandRootLocalId) { | 444 } else if (entry.local_id() != util::kDriveGrandRootLocalId) { |
435 DVLOG(1) << "Entries not under the grand root don't have paths."; | 445 DVLOG(1) << "Entries not under the grand root don't have paths."; |
436 return base::FilePath(); | 446 return FILE_ERROR_NOT_FOUND; |
437 } | |
438 path = path.Append(base::FilePath::FromUTF8Unsafe(entry.base_name())); | |
439 } | 447 } |
440 return path; | 448 path = path.Append(base::FilePath::FromUTF8Unsafe(entry.base_name())); |
| 449 *out_file_path = path; |
| 450 return FILE_ERROR_OK; |
441 } | 451 } |
442 | 452 |
443 FileError ResourceMetadata::GetIdByPath(const base::FilePath& file_path, | 453 FileError ResourceMetadata::GetIdByPath(const base::FilePath& file_path, |
444 std::string* out_id) { | 454 std::string* out_id) { |
445 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 455 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
446 | 456 |
447 // Start from the root. | 457 // Start from the root. |
448 std::vector<base::FilePath::StringType> components; | 458 std::vector<base::FilePath::StringType> components; |
449 file_path.GetComponents(&components); | 459 file_path.GetComponents(&components); |
450 if (components.empty() || components[0] != util::kDriveGrandRootDirName) | 460 if (components.empty() || components[0] != util::kDriveGrandRootDirName) |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 FileError ResourceMetadata::RemoveEntryRecursively(const std::string& id) { | 562 FileError ResourceMetadata::RemoveEntryRecursively(const std::string& id) { |
553 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 563 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
554 | 564 |
555 ResourceEntry entry; | 565 ResourceEntry entry; |
556 FileError error = storage_->GetEntry(id, &entry); | 566 FileError error = storage_->GetEntry(id, &entry); |
557 if (error != FILE_ERROR_OK) | 567 if (error != FILE_ERROR_OK) |
558 return error; | 568 return error; |
559 | 569 |
560 if (entry.file_info().is_directory()) { | 570 if (entry.file_info().is_directory()) { |
561 std::vector<std::string> children; | 571 std::vector<std::string> children; |
562 storage_->GetChildren(id, &children); | 572 error = storage_->GetChildren(id, &children); |
| 573 if (error != FILE_ERROR_OK) |
| 574 return error; |
563 for (size_t i = 0; i < children.size(); ++i) { | 575 for (size_t i = 0; i < children.size(); ++i) { |
564 error = RemoveEntryRecursively(children[i]); | 576 error = RemoveEntryRecursively(children[i]); |
565 if (error != FILE_ERROR_OK) | 577 if (error != FILE_ERROR_OK) |
566 return error; | 578 return error; |
567 } | 579 } |
568 } | 580 } |
569 return storage_->RemoveEntry(id); | 581 return storage_->RemoveEntry(id); |
570 } | 582 } |
571 | 583 |
572 } // namespace internal | 584 } // namespace internal |
573 } // namespace drive | 585 } // namespace drive |
OLD | NEW |