Chromium Code Reviews| 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 void PostError(const FileMoveCallback& callback, DriveFileError error) { | |
|
satorux1
2012/08/27 22:45:57
function comment missing. this seems to be used to
achuithb
2012/08/27 23:10:03
Done.
| |
| 32 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | |
| 33 base::Bind(callback, error, FilePath())); | |
| 34 } | |
| 35 | |
| 31 } // namespace | 36 } // namespace |
| 32 | 37 |
| 33 EntryInfoResult::EntryInfoResult() : error(DRIVE_FILE_ERROR_FAILED) { | 38 EntryInfoResult::EntryInfoResult() : error(DRIVE_FILE_ERROR_FAILED) { |
| 34 } | 39 } |
| 35 | 40 |
| 36 EntryInfoResult::~EntryInfoResult() { | 41 EntryInfoResult::~EntryInfoResult() { |
| 37 } | 42 } |
| 38 | 43 |
| 39 EntryInfoPairResult::EntryInfoPairResult() { | 44 EntryInfoPairResult::EntryInfoPairResult() { |
| 40 } | 45 } |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 // Note that children have a reference to root_, | 218 // Note that children have a reference to root_, |
| 214 // so we need to delete them here. | 219 // so we need to delete them here. |
| 215 root_->RemoveChildren(); | 220 root_->RemoveChildren(); |
| 216 RemoveEntryFromResourceMap(root_->resource_id()); | 221 RemoveEntryFromResourceMap(root_->resource_id()); |
| 217 DCHECK(resource_map_.empty()); | 222 DCHECK(resource_map_.empty()); |
| 218 resource_map_.clear(); | 223 resource_map_.clear(); |
| 219 root_.reset(); | 224 root_.reset(); |
| 220 } | 225 } |
| 221 | 226 |
| 222 void DriveResourceMetadata::AddEntryToDirectory( | 227 void DriveResourceMetadata::AddEntryToDirectory( |
| 223 DriveDirectory* directory, | 228 const FilePath& directory_path, |
| 224 DriveEntry* new_entry, | 229 scoped_ptr<DocumentEntry> doc_entry, |
| 225 const FileMoveCallback& callback) { | 230 const FileMoveCallback& callback) { |
| 226 DCHECK(directory); | 231 DCHECK(!directory_path.empty()); |
| 227 DCHECK(new_entry); | |
| 228 DCHECK(!callback.is_null()); | 232 DCHECK(!callback.is_null()); |
| 229 | 233 |
| 234 if (!doc_entry.get()) { | |
| 235 PostError(callback, DRIVE_FILE_ERROR_FAILED); | |
| 236 return; | |
| 237 } | |
| 238 | |
| 239 DriveEntry* new_entry = FromDocumentEntry(*doc_entry); | |
| 240 if (!new_entry) { | |
| 241 PostError(callback, DRIVE_FILE_ERROR_FAILED); | |
| 242 return; | |
| 243 } | |
| 244 | |
| 245 DriveEntry* dir_entry = FindEntryByPathSync(directory_path); | |
| 246 if (!dir_entry) { | |
| 247 PostError(callback, DRIVE_FILE_ERROR_NOT_FOUND); | |
| 248 return; | |
| 249 } | |
| 250 | |
| 251 DriveDirectory* directory = dir_entry->AsDriveDirectory(); | |
| 252 if (!directory) { | |
| 253 PostError(callback, DRIVE_FILE_ERROR_NOT_A_DIRECTORY); | |
| 254 return; | |
| 255 } | |
| 256 | |
| 230 directory->AddEntry(new_entry); | 257 directory->AddEntry(new_entry); |
| 231 DVLOG(1) << "AddEntryToDirectory " << new_entry->GetFilePath().value(); | 258 DVLOG(1) << "AddEntryToDirectory " << new_entry->GetFilePath().value(); |
| 232 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 259 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 233 base::Bind(callback, DRIVE_FILE_OK, new_entry->GetFilePath())); | 260 base::Bind(callback, DRIVE_FILE_OK, new_entry->GetFilePath())); |
| 234 } | 261 } |
| 235 | 262 |
| 236 void DriveResourceMetadata::MoveEntryToDirectory( | 263 void DriveResourceMetadata::MoveEntryToDirectory( |
| 237 const FilePath& directory_path, | 264 const FilePath& directory_path, |
| 238 DriveEntry* entry, | 265 DriveEntry* entry, |
| 239 const FileMoveCallback& callback) { | 266 const FileMoveCallback& callback) { |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 DCHECK(result.get()); | 803 DCHECK(result.get()); |
| 777 | 804 |
| 778 result->second.path = second_path; | 805 result->second.path = second_path; |
| 779 result->second.error = error; | 806 result->second.error = error; |
| 780 result->second.proto = entry_proto.Pass(); | 807 result->second.proto = entry_proto.Pass(); |
| 781 | 808 |
| 782 callback.Run(result.Pass()); | 809 callback.Run(result.Pass()); |
| 783 } | 810 } |
| 784 | 811 |
| 785 } // namespace gdata | 812 } // namespace gdata |
| OLD | NEW |