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

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

Issue 14091012: chromeos: Rewrite DriveResourceMetadata::MoveEntryToDirectory with RefreshEntry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 8 months 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
« no previous file with comments | « chrome/browser/chromeos/drive/drive_resource_metadata.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/drive_resource_metadata.h" 5 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 // Returns true if enough disk space is avilable for DB operation. 46 // Returns true if enough disk space is avilable for DB operation.
47 // TODO(hashimoto): Merge this with DriveCache's FreeDiskSpaceGetterInterface. 47 // TODO(hashimoto): Merge this with DriveCache's FreeDiskSpaceGetterInterface.
48 bool EnoughDiskSpaceIsAvailableForDBOperation(const base::FilePath& path) { 48 bool EnoughDiskSpaceIsAvailableForDBOperation(const base::FilePath& path) {
49 const int64 kRequiredDiskSpaceInMB = 128; // 128 MB seems to be large enough. 49 const int64 kRequiredDiskSpaceInMB = 128; // 128 MB seems to be large enough.
50 return base::SysInfo::AmountOfFreeDiskSpace(path) >= 50 return base::SysInfo::AmountOfFreeDiskSpace(path) >=
51 kRequiredDiskSpaceInMB * (1 << 20); 51 kRequiredDiskSpaceInMB * (1 << 20);
52 } 52 }
53 53
54 // Runs |callback| with arguments.
55 void RunGetEntryInfoWithFilePathCallback(
56 const GetEntryInfoWithFilePathCallback& callback,
57 base::FilePath* path,
58 scoped_ptr<DriveEntryProto> entry,
59 FileError error) {
60 DCHECK(!callback.is_null());
61
62 if (error != FILE_ERROR_OK)
63 entry.reset();
64 callback.Run(error, *path, entry.Pass());
65 }
66
54 } // namespace 67 } // namespace
55 68
56 std::string DirectoryFetchInfo::ToString() const { 69 std::string DirectoryFetchInfo::ToString() const {
57 return ("resource_id: " + resource_id_ + 70 return ("resource_id: " + resource_id_ +
58 ", changestamp: " + base::Int64ToString(changestamp_)); 71 ", changestamp: " + base::Int64ToString(changestamp_));
59 } 72 }
60 73
61 EntryInfoResult::EntryInfoResult() : error(FILE_ERROR_FAILED) { 74 EntryInfoResult::EntryInfoResult() : error(FILE_ERROR_FAILED) {
62 } 75 }
63 76
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 scoped_ptr<GetEntryInfoResult> result) { 119 scoped_ptr<GetEntryInfoResult> result) {
107 DCHECK(!callback.is_null()); 120 DCHECK(!callback.is_null());
108 DCHECK(result); 121 DCHECK(result);
109 callback.Run(result->error, result->entry.Pass()); 122 callback.Run(result->error, result->entry.Pass());
110 } 123 }
111 124
112 FileError error; 125 FileError error;
113 scoped_ptr<DriveEntryProto> entry; 126 scoped_ptr<DriveEntryProto> entry;
114 }; 127 };
115 128
116 // Struct to hold result values passed to GetEntryInfoWithFilePathCallback.
117 struct DriveResourceMetadata::GetEntryInfoWithFilePathResult {
118 GetEntryInfoWithFilePathResult(FileError error,
119 const base::FilePath& path,
120 scoped_ptr<DriveEntryProto> entry)
121 : error(error),
122 path(path),
123 entry(entry.Pass()) {}
124
125 explicit GetEntryInfoWithFilePathResult(FileError error)
126 : error(error) {}
127
128 // Runs GetEntryInfoWithFilePathCallback with the values stored in |result|.
129 static void RunCallbackWithResult(
130 const GetEntryInfoWithFilePathCallback& callback,
131 scoped_ptr<GetEntryInfoWithFilePathResult> result) {
132 DCHECK(!callback.is_null());
133 DCHECK(result);
134 callback.Run(result->error, result->path, result->entry.Pass());
135 }
136
137 FileError error;
138 base::FilePath path;
139 scoped_ptr<DriveEntryProto> entry;
140 };
141
142 // Struct to hold result values passed to ReadDirectoryCallback. 129 // Struct to hold result values passed to ReadDirectoryCallback.
143 struct DriveResourceMetadata::ReadDirectoryResult { 130 struct DriveResourceMetadata::ReadDirectoryResult {
144 ReadDirectoryResult(FileError error, 131 ReadDirectoryResult(FileError error,
145 scoped_ptr<DriveEntryProtoVector> entries) 132 scoped_ptr<DriveEntryProtoVector> entries)
146 : error(error), 133 : error(error),
147 entries(entries.Pass()) {} 134 entries(entries.Pass()) {}
148 135
149 // Runs ReadDirectoryCallback with the values stored in |result|. 136 // Runs ReadDirectoryCallback with the values stored in |result|.
150 static void RunCallbackWithResult(const ReadDirectoryCallback& callback, 137 static void RunCallbackWithResult(const ReadDirectoryCallback& callback,
151 scoped_ptr<ReadDirectoryResult> result) { 138 scoped_ptr<ReadDirectoryResult> result) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 resource_id), 329 resource_id),
343 base::Bind(&FileMoveResult::RunCallbackWithResult, 330 base::Bind(&FileMoveResult::RunCallbackWithResult,
344 callback)); 331 callback));
345 } 332 }
346 333
347 void DriveResourceMetadata::GetEntryInfoByResourceId( 334 void DriveResourceMetadata::GetEntryInfoByResourceId(
348 const std::string& resource_id, 335 const std::string& resource_id,
349 const GetEntryInfoWithFilePathCallback& callback) { 336 const GetEntryInfoWithFilePathCallback& callback) {
350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
351 DCHECK(!callback.is_null()); 338 DCHECK(!callback.is_null());
339
340 base::FilePath* file_path = new base::FilePath;
341 scoped_ptr<DriveEntryProto> entry(new DriveEntryProto);
342 DriveEntryProto* entry_ptr = entry.get();
352 base::PostTaskAndReplyWithResult( 343 base::PostTaskAndReplyWithResult(
353 blocking_task_runner_, 344 blocking_task_runner_,
354 FROM_HERE, 345 FROM_HERE,
355 base::Bind(&DriveResourceMetadata::GetEntryInfoByResourceIdOnBlockingPool, 346 base::Bind(&DriveResourceMetadata::GetEntryInfoByResourceIdOnBlockingPool,
356 base::Unretained(this), 347 base::Unretained(this),
357 resource_id), 348 resource_id,
358 base::Bind(&GetEntryInfoWithFilePathResult::RunCallbackWithResult, 349 file_path,
359 callback)); 350 entry_ptr),
351 base::Bind(&RunGetEntryInfoWithFilePathCallback,
352 callback,
353 base::Owned(file_path),
354 base::Passed(&entry)));
360 } 355 }
361 356
362 void DriveResourceMetadata::GetEntryInfoByPath( 357 void DriveResourceMetadata::GetEntryInfoByPath(
363 const base::FilePath& file_path, 358 const base::FilePath& file_path,
364 const GetEntryInfoCallback& callback) { 359 const GetEntryInfoCallback& callback) {
365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
366 DCHECK(!callback.is_null()); 361 DCHECK(!callback.is_null());
367 base::PostTaskAndReplyWithResult( 362 base::PostTaskAndReplyWithResult(
368 blocking_task_runner_, 363 blocking_task_runner_,
369 FROM_HERE, 364 FROM_HERE,
(...skipping 17 matching lines...) Expand all
387 file_path), 382 file_path),
388 base::Bind(&ReadDirectoryResult::RunCallbackWithResult, 383 base::Bind(&ReadDirectoryResult::RunCallbackWithResult,
389 callback)); 384 callback));
390 } 385 }
391 386
392 void DriveResourceMetadata::RefreshEntry( 387 void DriveResourceMetadata::RefreshEntry(
393 const DriveEntryProto& entry_proto, 388 const DriveEntryProto& entry_proto,
394 const GetEntryInfoWithFilePathCallback& callback) { 389 const GetEntryInfoWithFilePathCallback& callback) {
395 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
396 DCHECK(!callback.is_null()); 391 DCHECK(!callback.is_null());
392
393 base::FilePath* file_path = new base::FilePath;
394 scoped_ptr<DriveEntryProto> entry(new DriveEntryProto);
395 DriveEntryProto* entry_ptr = entry.get();
397 base::PostTaskAndReplyWithResult( 396 base::PostTaskAndReplyWithResult(
398 blocking_task_runner_, 397 blocking_task_runner_,
399 FROM_HERE, 398 FROM_HERE,
400 base::Bind(&DriveResourceMetadata::RefreshEntryOnBlockingPool, 399 base::Bind(&DriveResourceMetadata::RefreshEntryOnBlockingPool,
401 base::Unretained(this), 400 base::Unretained(this),
402 entry_proto), 401 entry_proto,
403 base::Bind(&GetEntryInfoWithFilePathResult::RunCallbackWithResult, 402 file_path,
404 callback)); 403 entry_ptr),
404 base::Bind(&RunGetEntryInfoWithFilePathCallback,
405 callback,
406 base::Owned(file_path),
407 base::Passed(&entry)));
405 } 408 }
406 409
407 void DriveResourceMetadata::RefreshDirectory( 410 void DriveResourceMetadata::RefreshDirectory(
408 const DirectoryFetchInfo& directory_fetch_info, 411 const DirectoryFetchInfo& directory_fetch_info,
409 const DriveEntryProtoMap& entry_proto_map, 412 const DriveEntryProtoMap& entry_proto_map,
410 const FileMoveCallback& callback) { 413 const FileMoveCallback& callback) {
411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
412 DCHECK(!callback.is_null()); 415 DCHECK(!callback.is_null());
413 base::PostTaskAndReplyWithResult( 416 base::PostTaskAndReplyWithResult(
414 blocking_task_runner_, 417 blocking_task_runner_,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 const base::FilePath& file_path, 485 const base::FilePath& file_path,
483 const base::FilePath& directory_path) { 486 const base::FilePath& directory_path) {
484 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); 487 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
485 DCHECK(!directory_path.empty()); 488 DCHECK(!directory_path.empty());
486 DCHECK(!file_path.empty()); 489 DCHECK(!file_path.empty());
487 490
488 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) 491 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_))
489 return FileMoveResult(FILE_ERROR_NO_SPACE); 492 return FileMoveResult(FILE_ERROR_NO_SPACE);
490 493
491 scoped_ptr<DriveEntryProto> entry = FindEntryByPathSync(file_path); 494 scoped_ptr<DriveEntryProto> entry = FindEntryByPathSync(file_path);
492 if (!entry) 495 scoped_ptr<DriveEntryProto> destination = FindEntryByPathSync(directory_path);
496 if (!entry || !destination)
493 return FileMoveResult(FILE_ERROR_NOT_FOUND); 497 return FileMoveResult(FILE_ERROR_NOT_FOUND);
498 if (!destination->file_info().is_directory())
499 return FileMoveResult(FILE_ERROR_NOT_A_DIRECTORY);
494 500
495 // Cannot move an entry without its parent. (i.e. the root) 501 entry->set_parent_resource_id(destination->resource_id());
496 if (entry->parent_resource_id().empty())
497 return FileMoveResult(FILE_ERROR_INVALID_OPERATION);
498 502
499 scoped_ptr<DriveEntryProto> destination = FindEntryByPathSync(directory_path); 503 base::FilePath result_file_path;
500 base::FilePath moved_file_path; 504 FileError error = RefreshEntryOnBlockingPool(*entry, &result_file_path, NULL);
501 FileError error = FILE_ERROR_FAILED; 505 return FileMoveResult(error, result_file_path);
502 if (!destination) {
503 error = FILE_ERROR_NOT_FOUND;
504 } else if (!destination->file_info().is_directory()) {
505 error = FILE_ERROR_NOT_A_DIRECTORY;
506 } else {
507 DetachEntryFromDirectory(entry->resource_id());
508 entry->set_parent_resource_id(destination->resource_id());
509 AddEntryToDirectory(*entry);
510 moved_file_path = GetFilePath(entry->resource_id());
511 error = FILE_ERROR_OK;
512 }
513 DVLOG(1) << "MoveEntryToDirectory " << moved_file_path.value();
514 return FileMoveResult(error, moved_file_path);
515 } 506 }
516 507
517 DriveResourceMetadata::FileMoveResult 508 DriveResourceMetadata::FileMoveResult
518 DriveResourceMetadata::RenameEntryOnBlockingPool( 509 DriveResourceMetadata::RenameEntryOnBlockingPool(
519 const base::FilePath& file_path, 510 const base::FilePath& file_path,
520 const std::string& new_name) { 511 const std::string& new_name) {
521 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); 512 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
522 DCHECK(!file_path.empty()); 513 DCHECK(!file_path.empty());
523 DCHECK(!new_name.empty()); 514 DCHECK(!new_name.empty());
524 515
525 DVLOG(1) << "RenameEntry " << file_path.value() << " to " << new_name; 516 DVLOG(1) << "RenameEntry " << file_path.value() << " to " << new_name;
526 517
527 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) 518 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_))
528 return FileMoveResult(FILE_ERROR_NO_SPACE); 519 return FileMoveResult(FILE_ERROR_NO_SPACE);
529 520
530 scoped_ptr<DriveEntryProto> entry = FindEntryByPathSync(file_path); 521 scoped_ptr<DriveEntryProto> entry = FindEntryByPathSync(file_path);
531 if (!entry) 522 if (!entry)
532 return FileMoveResult(FILE_ERROR_NOT_FOUND); 523 return FileMoveResult(FILE_ERROR_NOT_FOUND);
533 524
534 if (base::FilePath::FromUTF8Unsafe(new_name) == file_path.BaseName()) 525 if (base::FilePath::FromUTF8Unsafe(new_name) == file_path.BaseName())
535 return FileMoveResult(FILE_ERROR_EXISTS); 526 return FileMoveResult(FILE_ERROR_EXISTS);
536 527
537 entry->set_title(new_name); 528 entry->set_title(new_name);
538 scoped_ptr<GetEntryInfoWithFilePathResult> result = 529 base::FilePath result_file_path;
539 RefreshEntryOnBlockingPool(*entry); 530 FileError error = RefreshEntryOnBlockingPool(*entry, &result_file_path, NULL);
540 return FileMoveResult(result->error, result->path); 531 return FileMoveResult(error, result_file_path);
541 } 532 }
542 533
543 DriveResourceMetadata::FileMoveResult 534 DriveResourceMetadata::FileMoveResult
544 DriveResourceMetadata::RemoveEntryOnBlockingPool( 535 DriveResourceMetadata::RemoveEntryOnBlockingPool(
545 const std::string& resource_id) { 536 const std::string& resource_id) {
546 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); 537 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
547 538
548 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) 539 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_))
549 return FileMoveResult(FILE_ERROR_NO_SPACE); 540 return FileMoveResult(FILE_ERROR_NO_SPACE);
550 541
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 if (resource_id.empty()) 577 if (resource_id.empty())
587 return scoped_ptr<DriveEntryProto>(); 578 return scoped_ptr<DriveEntryProto>();
588 579
589 entry = storage_->GetEntry(resource_id); 580 entry = storage_->GetEntry(resource_id);
590 DCHECK(entry); 581 DCHECK(entry);
591 DCHECK_EQ(entry->base_name(), component); 582 DCHECK_EQ(entry->base_name(), component);
592 } 583 }
593 return entry.Pass(); 584 return entry.Pass();
594 } 585 }
595 586
596 scoped_ptr<DriveResourceMetadata::GetEntryInfoWithFilePathResult> 587 FileError DriveResourceMetadata::GetEntryInfoByResourceIdOnBlockingPool(
597 DriveResourceMetadata::GetEntryInfoByResourceIdOnBlockingPool( 588 const std::string& resource_id,
598 const std::string& resource_id) { 589 base::FilePath* out_file_path,
590 DriveEntryProto* out_entry) {
599 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); 591 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
600 DCHECK(!resource_id.empty()); 592 DCHECK(!resource_id.empty());
601 593
602 scoped_ptr<DriveEntryProto> entry = storage_->GetEntry(resource_id); 594 scoped_ptr<DriveEntryProto> entry = storage_->GetEntry(resource_id);
603 FileError error = FILE_ERROR_FAILED; 595 if (!entry)
604 base::FilePath drive_file_path; 596 return FILE_ERROR_NOT_FOUND;
605 if (entry) {
606 error = FILE_ERROR_OK;
607 drive_file_path = GetFilePath(resource_id);
608 } else {
609 error = FILE_ERROR_NOT_FOUND;
610 }
611 597
612 return make_scoped_ptr( 598 if (out_file_path)
613 new GetEntryInfoWithFilePathResult(error, drive_file_path, entry.Pass())); 599 *out_file_path = GetFilePath(resource_id);
600 if (out_entry)
601 *out_entry = *entry;
602
603 return FILE_ERROR_OK;
614 } 604 }
615 605
616 scoped_ptr<DriveResourceMetadata::GetEntryInfoResult> 606 scoped_ptr<DriveResourceMetadata::GetEntryInfoResult>
617 DriveResourceMetadata::GetEntryInfoByPathOnBlockingPool( 607 DriveResourceMetadata::GetEntryInfoByPathOnBlockingPool(
618 const base::FilePath& path) { 608 const base::FilePath& path) {
619 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); 609 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
620 610
621 scoped_ptr<DriveEntryProto> entry = FindEntryByPathSync(path); 611 scoped_ptr<DriveEntryProto> entry = FindEntryByPathSync(path);
622 FileError error = entry ? FILE_ERROR_OK : FILE_ERROR_NOT_FOUND; 612 FileError error = entry ? FILE_ERROR_OK : FILE_ERROR_NOT_FOUND;
623 613
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 // Get the first entry. 645 // Get the first entry.
656 GetEntryInfoByPath( 646 GetEntryInfoByPath(
657 first_path, 647 first_path,
658 base::Bind(&DriveResourceMetadata::GetEntryInfoPairByPathsAfterGetFirst, 648 base::Bind(&DriveResourceMetadata::GetEntryInfoPairByPathsAfterGetFirst,
659 weak_ptr_factory_.GetWeakPtr(), 649 weak_ptr_factory_.GetWeakPtr(),
660 first_path, 650 first_path,
661 second_path, 651 second_path,
662 callback)); 652 callback));
663 } 653 }
664 654
665 scoped_ptr<DriveResourceMetadata::GetEntryInfoWithFilePathResult> 655 FileError DriveResourceMetadata::RefreshEntryOnBlockingPool(
666 DriveResourceMetadata::RefreshEntryOnBlockingPool( 656 const DriveEntryProto& entry,
667 const DriveEntryProto& entry_proto) { 657 base::FilePath* out_file_path,
658 DriveEntryProto* out_entry) {
668 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); 659 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
669 660
670 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) { 661 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_))
671 return make_scoped_ptr( 662 return FILE_ERROR_NO_SPACE;
672 new GetEntryInfoWithFilePathResult(FILE_ERROR_NO_SPACE));
673 }
674 663
675 scoped_ptr<DriveEntryProto> entry = 664 scoped_ptr<DriveEntryProto> old_entry =
676 storage_->GetEntry(entry_proto.resource_id()); 665 storage_->GetEntry(entry.resource_id());
677 if (!entry) { 666 if (!old_entry)
678 return make_scoped_ptr( 667 return FILE_ERROR_NOT_FOUND;
679 new GetEntryInfoWithFilePathResult(FILE_ERROR_NOT_FOUND));
680 }
681 668
682 if (entry->parent_resource_id().empty() || // Rejct root. 669 if (old_entry->parent_resource_id().empty() || // Rejct root.
683 entry->file_info().is_directory() != // Reject incompatible input. 670 old_entry->file_info().is_directory() != // Reject incompatible input.
684 entry_proto.file_info().is_directory()) { 671 entry.file_info().is_directory())
685 return make_scoped_ptr( 672 return FILE_ERROR_INVALID_OPERATION;
686 new GetEntryInfoWithFilePathResult(FILE_ERROR_INVALID_OPERATION));
687 }
688 673
689 // Update data. 674 // Update data.
690 scoped_ptr<DriveEntryProto> new_parent = 675 scoped_ptr<DriveEntryProto> new_parent =
691 GetDirectory(entry_proto.parent_resource_id()); 676 GetDirectory(entry.parent_resource_id());
692 677
693 if (!new_parent) { 678 if (!new_parent)
694 return make_scoped_ptr( 679 return FILE_ERROR_NOT_FOUND;
695 new GetEntryInfoWithFilePathResult(FILE_ERROR_NOT_FOUND));
696 }
697 680
698 // Remove from the old parent and add it to the new parent with the new data. 681 // Remove from the old parent and add it to the new parent with the new data.
699 DetachEntryFromDirectory(entry->resource_id()); 682 DetachEntryFromDirectory(old_entry->resource_id());
700 AddEntryToDirectory(CreateEntryWithProperBaseName(entry_proto)); 683 AddEntryToDirectory(CreateEntryWithProperBaseName(entry));
701 684
702 // Note that base_name is not the same for the new entry and entry_proto. 685 if (out_file_path)
703 scoped_ptr<DriveEntryProto> result_entry_proto = 686 *out_file_path = GetFilePath(entry.resource_id());
704 storage_->GetEntry(entry->resource_id()); 687
705 return make_scoped_ptr( 688 if (out_entry) {
706 new GetEntryInfoWithFilePathResult(FILE_ERROR_OK, 689 // Note that base_name is not the same for the new entry and entry_proto.
707 GetFilePath(entry->resource_id()), 690 scoped_ptr<DriveEntryProto> result_entry_proto =
708 result_entry_proto.Pass())); 691 storage_->GetEntry(entry.resource_id());
692 DCHECK(result_entry_proto);
693 *out_entry = *result_entry_proto;
694 }
695 return FILE_ERROR_OK;
709 } 696 }
710 697
711 DriveResourceMetadata::FileMoveResult 698 DriveResourceMetadata::FileMoveResult
712 DriveResourceMetadata::RefreshDirectoryOnBlockingPool( 699 DriveResourceMetadata::RefreshDirectoryOnBlockingPool(
713 const DirectoryFetchInfo& directory_fetch_info, 700 const DirectoryFetchInfo& directory_fetch_info,
714 const DriveEntryProtoMap& entry_proto_map) { 701 const DriveEntryProtoMap& entry_proto_map) {
715 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); 702 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
716 DCHECK(!directory_fetch_info.empty()); 703 DCHECK(!directory_fetch_info.empty());
717 704
718 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) 705 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_))
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 storage_->GetChildren(directory_resource_id, &children); 986 storage_->GetChildren(directory_resource_id, &children);
1000 for (size_t i = 0; i < children.size(); ++i) { 987 for (size_t i = 0; i < children.size(); ++i) {
1001 scoped_ptr<DriveEntryProto> child = storage_->GetEntry(children[i]); 988 scoped_ptr<DriveEntryProto> child = storage_->GetEntry(children[i]);
1002 DCHECK(child); 989 DCHECK(child);
1003 entries->push_back(*child); 990 entries->push_back(*child);
1004 } 991 }
1005 return entries.Pass(); 992 return entries.Pass();
1006 } 993 }
1007 994
1008 } // namespace drive 995 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_resource_metadata.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698