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/gdata/drive_resource_metadata.h" | 5 #include "chrome/browser/chromeos/gdata/drive_resource_metadata.h" |
6 | 6 |
7 #include <leveldb/db.h> | 7 #include <leveldb/db.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 namespace gdata { | 22 namespace gdata { |
23 namespace { | 23 namespace { |
24 | 24 |
25 // m: prefix for filesystem metadata db keys, version and largest_changestamp. | 25 // m: prefix for filesystem metadata db keys, version and largest_changestamp. |
26 // r: prefix for resource id db keys. | 26 // r: prefix for resource id db keys. |
27 const char kDBKeyLargestChangestamp[] = "m:largest_changestamp"; | 27 const char kDBKeyLargestChangestamp[] = "m:largest_changestamp"; |
28 const char kDBKeyVersion[] = "m:version"; | 28 const char kDBKeyVersion[] = "m:version"; |
29 const char kDBKeyResourceIdPrefix[] = "r:"; | 29 const char kDBKeyResourceIdPrefix[] = "r:"; |
30 | 30 |
| 31 // Posts |error| to |callback| asynchronously. |
| 32 void PostError(const FileMoveCallback& callback, DriveFileError error) { |
| 33 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 34 base::Bind(callback, error, FilePath())); |
| 35 } |
| 36 |
31 } // namespace | 37 } // namespace |
32 | 38 |
33 EntryInfoResult::EntryInfoResult() : error(DRIVE_FILE_ERROR_FAILED) { | 39 EntryInfoResult::EntryInfoResult() : error(DRIVE_FILE_ERROR_FAILED) { |
34 } | 40 } |
35 | 41 |
36 EntryInfoResult::~EntryInfoResult() { | 42 EntryInfoResult::~EntryInfoResult() { |
37 } | 43 } |
38 | 44 |
39 EntryInfoPairResult::EntryInfoPairResult() { | 45 EntryInfoPairResult::EntryInfoPairResult() { |
40 } | 46 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 // Note that children have a reference to root_, | 219 // Note that children have a reference to root_, |
214 // so we need to delete them here. | 220 // so we need to delete them here. |
215 root_->RemoveChildren(); | 221 root_->RemoveChildren(); |
216 RemoveEntryFromResourceMap(root_->resource_id()); | 222 RemoveEntryFromResourceMap(root_->resource_id()); |
217 DCHECK(resource_map_.empty()); | 223 DCHECK(resource_map_.empty()); |
218 resource_map_.clear(); | 224 resource_map_.clear(); |
219 root_.reset(); | 225 root_.reset(); |
220 } | 226 } |
221 | 227 |
222 void DriveResourceMetadata::AddEntryToDirectory( | 228 void DriveResourceMetadata::AddEntryToDirectory( |
223 DriveDirectory* directory, | 229 const FilePath& directory_path, |
224 DriveEntry* new_entry, | 230 scoped_ptr<DocumentEntry> doc_entry, |
225 const FileMoveCallback& callback) { | 231 const FileMoveCallback& callback) { |
226 DCHECK(directory); | 232 DCHECK(!directory_path.empty()); |
227 DCHECK(new_entry); | |
228 DCHECK(!callback.is_null()); | 233 DCHECK(!callback.is_null()); |
229 | 234 |
| 235 if (!doc_entry.get()) { |
| 236 PostError(callback, DRIVE_FILE_ERROR_FAILED); |
| 237 return; |
| 238 } |
| 239 |
| 240 DriveEntry* new_entry = FromDocumentEntry(*doc_entry); |
| 241 if (!new_entry) { |
| 242 PostError(callback, DRIVE_FILE_ERROR_FAILED); |
| 243 return; |
| 244 } |
| 245 |
| 246 DriveEntry* dir_entry = FindEntryByPathSync(directory_path); |
| 247 if (!dir_entry) { |
| 248 PostError(callback, DRIVE_FILE_ERROR_NOT_FOUND); |
| 249 return; |
| 250 } |
| 251 |
| 252 DriveDirectory* directory = dir_entry->AsDriveDirectory(); |
| 253 if (!directory) { |
| 254 PostError(callback, DRIVE_FILE_ERROR_NOT_A_DIRECTORY); |
| 255 return; |
| 256 } |
| 257 |
230 directory->AddEntry(new_entry); | 258 directory->AddEntry(new_entry); |
231 DVLOG(1) << "AddEntryToDirectory " << new_entry->GetFilePath().value(); | 259 DVLOG(1) << "AddEntryToDirectory " << new_entry->GetFilePath().value(); |
232 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 260 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
233 base::Bind(callback, DRIVE_FILE_OK, new_entry->GetFilePath())); | 261 base::Bind(callback, DRIVE_FILE_OK, new_entry->GetFilePath())); |
234 } | 262 } |
235 | 263 |
236 void DriveResourceMetadata::MoveEntryToDirectory( | 264 void DriveResourceMetadata::MoveEntryToDirectory( |
237 const FilePath& directory_path, | 265 const FilePath& directory_path, |
238 DriveEntry* entry, | 266 DriveEntry* entry, |
239 const FileMoveCallback& callback) { | 267 const FileMoveCallback& callback) { |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 DCHECK(result.get()); | 804 DCHECK(result.get()); |
777 | 805 |
778 result->second.path = second_path; | 806 result->second.path = second_path; |
779 result->second.error = error; | 807 result->second.error = error; |
780 result->second.proto = entry_proto.Pass(); | 808 result->second.proto = entry_proto.Pass(); |
781 | 809 |
782 callback.Run(result.Pass()); | 810 callback.Run(result.Pass()); |
783 } | 811 } |
784 | 812 |
785 } // namespace gdata | 813 } // namespace gdata |
OLD | NEW |