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

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

Issue 12907012: chromeos: Use RefreshEntry to implement DriveResourceMetadata::RenameEntry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 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 | « no previous file | 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 "chrome/browser/chromeos/drive/drive.pb.h" 10 #include "chrome/browser/chromeos/drive/drive.pb.h"
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 582
583 DVLOG(1) << "RenameEntry " << file_path.value() << " to " << new_name; 583 DVLOG(1) << "RenameEntry " << file_path.value() << " to " << new_name;
584 scoped_ptr<DriveEntryProto> entry = FindEntryByPathSync(file_path); 584 scoped_ptr<DriveEntryProto> entry = FindEntryByPathSync(file_path);
585 if (!entry) 585 if (!entry)
586 return FileMoveResult(DRIVE_FILE_ERROR_NOT_FOUND); 586 return FileMoveResult(DRIVE_FILE_ERROR_NOT_FOUND);
587 587
588 if (base::FilePath::FromUTF8Unsafe(new_name) == file_path.BaseName()) 588 if (base::FilePath::FromUTF8Unsafe(new_name) == file_path.BaseName())
589 return FileMoveResult(DRIVE_FILE_ERROR_EXISTS); 589 return FileMoveResult(DRIVE_FILE_ERROR_EXISTS);
590 590
591 entry->set_title(new_name); 591 entry->set_title(new_name);
592 storage_->PutEntry(*entry); 592 scoped_ptr<GetEntryInfoWithFilePathResult> result =
593 593 RefreshEntryOnBlockingPool(*entry);
594 // After changing the title of the entry, call MoveEntryToDirectory to 594 return FileMoveResult(result->error, result->path);
595 // remove the entry from its parent directory and then add it back in order to
596 // go through the file name de-duplication.
597 // TODO(achuith/satorux/zel): This code is fragile. The title has been
598 // changed, but not the file_name. MoveEntryToDirectory calls RemoveChild to
599 // remove the child based on the old file_name, and then re-adds the child by
600 // first assigning the new title to file_name. http://crbug.com/30157
601 return MoveEntryToDirectoryOnBlockingPool(
602 file_path, GetFilePath(entry->parent_resource_id()));
603 } 595 }
604 596
605 DriveResourceMetadata::FileMoveResult 597 DriveResourceMetadata::FileMoveResult
606 DriveResourceMetadata::RemoveEntryOnBlockingPool( 598 DriveResourceMetadata::RemoveEntryOnBlockingPool(
607 const std::string& resource_id) { 599 const std::string& resource_id) {
608 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); 600 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread());
609 601
610 // Disallow deletion of root. 602 // Disallow deletion of root.
611 if (resource_id == root_resource_id_) 603 if (resource_id == root_resource_id_)
612 return FileMoveResult(DRIVE_FILE_ERROR_ACCESS_DENIED); 604 return FileMoveResult(DRIVE_FILE_ERROR_ACCESS_DENIED);
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 storage_->PutEntry( 1170 storage_->PutEntry(
1179 CreateEntryWithProperBaseName(proto.drive_directory().drive_entry())); 1171 CreateEntryWithProperBaseName(proto.drive_directory().drive_entry()));
1180 AddDescendantsFromProto(proto.drive_directory()); 1172 AddDescendantsFromProto(proto.drive_directory());
1181 1173
1182 storage_->SetLargestChangestamp(proto.largest_changestamp()); 1174 storage_->SetLargestChangestamp(proto.largest_changestamp());
1183 1175
1184 return true; 1176 return true;
1185 } 1177 }
1186 1178
1187 } // namespace drive 1179 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698