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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/create_directory_operation.cc

Issue 23571006: drive: Stop using resource ID to access local metadata in CreateDirectoryOperation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | chrome/browser/chromeos/drive/resource_metadata.h » ('j') | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/file_system/create_directory_operation.h " 5 #include "chrome/browser/chromeos/drive/file_system/create_directory_operation.h "
6 6
7 #include "chrome/browser/chromeos/drive/drive.pb.h" 7 #include "chrome/browser/chromeos/drive/drive.pb.h"
8 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" 8 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h"
9 #include "chrome/browser/chromeos/drive/file_system_util.h" 9 #include "chrome/browser/chromeos/drive/file_system_util.h"
10 #include "chrome/browser/chromeos/drive/job_scheduler.h" 10 #include "chrome/browser/chromeos/drive/job_scheduler.h"
11 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" 11 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h"
12 #include "chrome/browser/google_apis/gdata_errorcode.h" 12 #include "chrome/browser/google_apis/gdata_errorcode.h"
13 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 13 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 15
16 using content::BrowserThread; 16 using content::BrowserThread;
17 17
18 namespace drive { 18 namespace drive {
19 namespace file_system { 19 namespace file_system {
20 20
21 namespace { 21 namespace {
22 22
23 // Part of CreateDirectoryRecursively(). Adds an |entry| for new directory 23 // Part of CreateDirectoryRecursively(). Adds an |entry| for new directory
24 // to |metadata|, and return the status. If succeeded, |file_path| will store 24 // to |metadata|, and return the status. If succeeded, |file_path| will store
25 // the path to the result file. 25 // the path to the result file.
26 FileError UpdateLocalStateForCreateDirectoryRecursively( 26 FileError UpdateLocalStateForCreateDirectoryRecursively(
27 internal::ResourceMetadata* metadata, 27 internal::ResourceMetadata* metadata,
28 const ResourceEntry& entry, 28 scoped_ptr<google_apis::ResourceEntry> resource_entry,
29 base::FilePath* file_path) { 29 base::FilePath* file_path) {
30 DCHECK(metadata); 30 DCHECK(metadata);
31 DCHECK(file_path); 31 DCHECK(file_path);
32 32
33 ResourceEntry entry;
34 std::string parent_resource_id;
35 if (!ConvertToResourceEntry(*resource_entry, &entry, &parent_resource_id))
36 return FILE_ERROR_NOT_A_FILE;
37
38 std::string parent_local_id;
39 FileError result = metadata->GetIdByResourceId(parent_resource_id,
40 &parent_local_id);
41 if (result != FILE_ERROR_OK)
42 return result;
43 entry.set_parent_local_id(parent_local_id);
44
33 std::string local_id; 45 std::string local_id;
34 FileError result = metadata->AddEntry(entry, &local_id); 46 result = metadata->AddEntry(entry, &local_id);
35 // Depending on timing, a metadata may be updated by change list already. 47 // Depending on timing, a metadata may be updated by change list already.
36 // So, FILE_ERROR_EXISTS is not an error. 48 // So, FILE_ERROR_EXISTS is not an error.
37 if (result == FILE_ERROR_EXISTS) 49 if (result == FILE_ERROR_EXISTS)
38 result = metadata->GetIdByResourceId(entry.resource_id(), &local_id); 50 result = metadata->GetIdByResourceId(entry.resource_id(), &local_id);
39 51
40 if (result == FILE_ERROR_OK) 52 if (result == FILE_ERROR_OK)
41 *file_path = metadata->GetFilePath(local_id); 53 *file_path = metadata->GetFilePath(local_id);
42 54
43 return result; 55 return result;
44 } 56 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 ResourceEntry* entry) { 107 ResourceEntry* entry) {
96 DCHECK(metadata); 108 DCHECK(metadata);
97 DCHECK(entry); 109 DCHECK(entry);
98 110
99 std::vector<base::FilePath::StringType> components; 111 std::vector<base::FilePath::StringType> components;
100 directory_path.GetComponents(&components); 112 directory_path.GetComponents(&components);
101 113
102 if (components.empty() || components[0] != util::kDriveGrandRootDirName) 114 if (components.empty() || components[0] != util::kDriveGrandRootDirName)
103 return base::FilePath(); 115 return base::FilePath();
104 116
105 std::string resource_id = util::kDriveGrandRootSpecialResourceId; 117 std::string local_id = util::kDriveGrandRootSpecialResourceId;
106 for (size_t i = 1; i < components.size(); ++i) { 118 for (size_t i = 1; i < components.size(); ++i) {
107 std::string child_resource_id = 119 std::string child_local_id = metadata->GetChildId(local_id, components[i]);
108 metadata->GetChildResourceId(resource_id, components[i]); 120 if (child_local_id.empty())
109 if (child_resource_id.empty())
110 break; 121 break;
111 resource_id = child_resource_id; 122 local_id = child_local_id;
112 } 123 }
113 124
114 FileError error = metadata->GetResourceEntryById(resource_id, entry); 125 FileError error = metadata->GetResourceEntryById(local_id, entry);
115 DCHECK_EQ(FILE_ERROR_OK, error); 126 DCHECK_EQ(FILE_ERROR_OK, error);
116 127
117 if (!entry->file_info().is_directory()) 128 if (!entry->file_info().is_directory())
118 return base::FilePath(); 129 return base::FilePath();
119 130
120 return metadata->GetFilePath(resource_id); 131 return metadata->GetFilePath(local_id);
121 } 132 }
122 133
123 void CreateDirectoryOperation::CreateDirectoryAfterGetExistingDeepestDirectory( 134 void CreateDirectoryOperation::CreateDirectoryAfterGetExistingDeepestDirectory(
124 const base::FilePath& directory_path, 135 const base::FilePath& directory_path,
125 bool is_exclusive, 136 bool is_exclusive,
126 bool is_recursive, 137 bool is_recursive,
127 const FileOperationCallback& callback, 138 const FileOperationCallback& callback,
128 ResourceEntry* existing_deepest_directory_entry, 139 ResourceEntry* existing_deepest_directory_entry,
129 const base::FilePath& existing_deepest_directory_path) { 140 const base::FilePath& existing_deepest_directory_path) {
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 scoped_ptr<google_apis::ResourceEntry> resource_entry) { 198 scoped_ptr<google_apis::ResourceEntry> resource_entry) {
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
189 DCHECK(!callback.is_null()); 200 DCHECK(!callback.is_null());
190 201
191 FileError error = GDataToFileError(gdata_error); 202 FileError error = GDataToFileError(gdata_error);
192 if (error != FILE_ERROR_OK) { 203 if (error != FILE_ERROR_OK) {
193 callback.Run(error); 204 callback.Run(error);
194 return; 205 return;
195 } 206 }
196 DCHECK(resource_entry); 207 DCHECK(resource_entry);
197 208 const std::string& resource_id = resource_entry->resource_id();
198 ResourceEntry entry;
199 std::string parent_resource_id;
200 if (!ConvertToResourceEntry(*resource_entry, &entry, &parent_resource_id)) {
201 callback.Run(FILE_ERROR_NOT_A_FILE);
202 return;
203 }
204
205 // TODO(hashimoto): Resolve local ID before use. crbug.com/260514
206 entry.set_parent_local_id(parent_resource_id);
207 209
208 // Note that the created directory may be renamed inside 210 // Note that the created directory may be renamed inside
209 // ResourceMetadata::AddEntry due to name confliction. 211 // ResourceMetadata::AddEntry due to name confliction.
210 // What we actually need here is the new created path (not the path we try 212 // What we actually need here is the new created path (not the path we try
211 // to create). 213 // to create).
212 base::FilePath* file_path = new base::FilePath; 214 base::FilePath* file_path = new base::FilePath;
213 base::PostTaskAndReplyWithResult( 215 base::PostTaskAndReplyWithResult(
214 blocking_task_runner_.get(), 216 blocking_task_runner_.get(),
215 FROM_HERE, 217 FROM_HERE,
216 base::Bind(&UpdateLocalStateForCreateDirectoryRecursively, 218 base::Bind(&UpdateLocalStateForCreateDirectoryRecursively,
217 metadata_, 219 metadata_,
218 entry, 220 base::Passed(&resource_entry),
219 file_path), 221 file_path),
220 base::Bind(&CreateDirectoryOperation:: 222 base::Bind(&CreateDirectoryOperation::
221 CreateDirectoryRecursivelyAfterUpdateLocalState, 223 CreateDirectoryRecursivelyAfterUpdateLocalState,
222 weak_ptr_factory_.GetWeakPtr(), 224 weak_ptr_factory_.GetWeakPtr(),
223 resource_entry->resource_id(), 225 resource_id,
224 remaining_path, 226 remaining_path,
225 callback, 227 callback,
226 base::Owned(file_path))); 228 base::Owned(file_path)));
227 } 229 }
228 230
229 void CreateDirectoryOperation::CreateDirectoryRecursivelyAfterUpdateLocalState( 231 void CreateDirectoryOperation::CreateDirectoryRecursivelyAfterUpdateLocalState(
230 const std::string& resource_id, 232 const std::string& resource_id,
231 const base::FilePath& remaining_path, 233 const base::FilePath& remaining_path,
232 const FileOperationCallback& callback, 234 const FileOperationCallback& callback,
233 base::FilePath* file_path, 235 base::FilePath* file_path,
(...skipping 13 matching lines...) Expand all
247 callback.Run(FILE_ERROR_OK); 249 callback.Run(FILE_ERROR_OK);
248 return; 250 return;
249 } 251 }
250 252
251 // Create descendant directories. 253 // Create descendant directories.
252 CreateDirectoryRecursively(resource_id, remaining_path, callback); 254 CreateDirectoryRecursively(resource_id, remaining_path, callback);
253 } 255 }
254 256
255 } // namespace file_system 257 } // namespace file_system
256 } // namespace drive 258 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/resource_metadata.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698