| 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/drive/drive_resource_metadata.h" | 5 #include "chrome/browser/chromeos/drive/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" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
| 14 #include "chrome/browser/chromeos/drive/drive.pb.h" | 14 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 15 #include "chrome/browser/chromeos/drive/drive_files.h" | 15 #include "chrome/browser/chromeos/drive/drive_files.h" |
| 16 #include "chrome/browser/google_apis/gdata_util.h" | 16 #include "chrome/browser/google_apis/gdata_util.h" |
| 17 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 17 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 | 19 |
| 20 using content::BrowserThread; | 20 using content::BrowserThread; |
| 21 | 21 |
| 22 namespace gdata { | 22 namespace drive { |
| 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. |callback| must not be null. | 31 // Posts |error| to |callback| asynchronously. |callback| must not be null. |
| 32 void PostFileMoveCallbackError(const FileMoveCallback& callback, | 32 void PostFileMoveCallbackError(const FileMoveCallback& callback, |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 179 |
| 180 // DriveResourceMetadata class implementation. | 180 // DriveResourceMetadata class implementation. |
| 181 | 181 |
| 182 DriveResourceMetadata::DriveResourceMetadata() | 182 DriveResourceMetadata::DriveResourceMetadata() |
| 183 : blocking_task_runner_(NULL), | 183 : blocking_task_runner_(NULL), |
| 184 serialized_size_(0), | 184 serialized_size_(0), |
| 185 largest_changestamp_(0), | 185 largest_changestamp_(0), |
| 186 origin_(UNINITIALIZED), | 186 origin_(UNINITIALIZED), |
| 187 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 187 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 188 root_ = CreateDriveDirectory().Pass(); | 188 root_ = CreateDriveDirectory().Pass(); |
| 189 if (!util::IsDriveV2ApiEnabled()) | 189 if (!gdata::util::IsDriveV2ApiEnabled()) |
| 190 InitializeRootEntry(kDriveRootDirectoryResourceId); | 190 InitializeRootEntry(kDriveRootDirectoryResourceId); |
| 191 } | 191 } |
| 192 | 192 |
| 193 DriveResourceMetadata::~DriveResourceMetadata() { | 193 DriveResourceMetadata::~DriveResourceMetadata() { |
| 194 ClearRoot(); | 194 ClearRoot(); |
| 195 | 195 |
| 196 // Ensure db is closed on the blocking pool. | 196 // Ensure db is closed on the blocking pool. |
| 197 if (blocking_task_runner_ && resource_metadata_db_.get()) | 197 if (blocking_task_runner_ && resource_metadata_db_.get()) |
| 198 blocking_task_runner_->DeleteSoon(FROM_HERE, | 198 blocking_task_runner_->DeleteSoon(FROM_HERE, |
| 199 resource_metadata_db_.release()); | 199 resource_metadata_db_.release()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 scoped_ptr<DriveEntry> DriveResourceMetadata::FromDocumentEntry( | 202 scoped_ptr<DriveEntry> DriveResourceMetadata::FromDocumentEntry( |
| 203 const DocumentEntry& doc) { | 203 const gdata::DocumentEntry& doc) { |
| 204 scoped_ptr<DriveEntry> entry; | 204 scoped_ptr<DriveEntry> entry; |
| 205 if (doc.is_folder()) | 205 if (doc.is_folder()) |
| 206 entry = CreateDriveDirectory().Pass(); | 206 entry = CreateDriveDirectory().Pass(); |
| 207 else if (doc.is_hosted_document() || doc.is_file()) | 207 else if (doc.is_hosted_document() || doc.is_file()) |
| 208 entry = CreateDriveFile().Pass(); | 208 entry = CreateDriveFile().Pass(); |
| 209 | 209 |
| 210 if (entry.get()) | 210 if (entry.get()) |
| 211 entry->InitFromDocumentEntry(doc); | 211 entry->InitFromDocumentEntry(doc); |
| 212 return entry.Pass(); | 212 return entry.Pass(); |
| 213 } | 213 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 236 // so we need to delete them here. | 236 // so we need to delete them here. |
| 237 root_->RemoveChildren(); | 237 root_->RemoveChildren(); |
| 238 RemoveEntryFromResourceMap(root_->resource_id()); | 238 RemoveEntryFromResourceMap(root_->resource_id()); |
| 239 DCHECK(resource_map_.empty()); | 239 DCHECK(resource_map_.empty()); |
| 240 resource_map_.clear(); | 240 resource_map_.clear(); |
| 241 root_.reset(); | 241 root_.reset(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void DriveResourceMetadata::AddEntryToDirectory( | 244 void DriveResourceMetadata::AddEntryToDirectory( |
| 245 const FilePath& directory_path, | 245 const FilePath& directory_path, |
| 246 scoped_ptr<DocumentEntry> doc_entry, | 246 scoped_ptr<gdata::DocumentEntry> doc_entry, |
| 247 const FileMoveCallback& callback) { | 247 const FileMoveCallback& callback) { |
| 248 DCHECK(!directory_path.empty()); | 248 DCHECK(!directory_path.empty()); |
| 249 DCHECK(!callback.is_null()); | 249 DCHECK(!callback.is_null()); |
| 250 | 250 |
| 251 if (!doc_entry.get()) { | 251 if (!doc_entry.get()) { |
| 252 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_FAILED); | 252 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_FAILED); |
| 253 return; | 253 return; |
| 254 } | 254 } |
| 255 | 255 |
| 256 scoped_ptr<DriveEntry> new_entry = FromDocumentEntry(*doc_entry); | 256 scoped_ptr<DriveEntry> new_entry = FromDocumentEntry(*doc_entry); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 GetEntryInfoByPath( | 506 GetEntryInfoByPath( |
| 507 first_path, | 507 first_path, |
| 508 base::Bind(&DriveResourceMetadata::GetEntryInfoPairByPathsAfterGetFirst, | 508 base::Bind(&DriveResourceMetadata::GetEntryInfoPairByPathsAfterGetFirst, |
| 509 weak_ptr_factory_.GetWeakPtr(), | 509 weak_ptr_factory_.GetWeakPtr(), |
| 510 first_path, | 510 first_path, |
| 511 second_path, | 511 second_path, |
| 512 callback)); | 512 callback)); |
| 513 } | 513 } |
| 514 | 514 |
| 515 void DriveResourceMetadata::RefreshFile( | 515 void DriveResourceMetadata::RefreshFile( |
| 516 scoped_ptr<DocumentEntry> doc_entry, | 516 scoped_ptr<gdata::DocumentEntry> doc_entry, |
| 517 const GetEntryInfoWithFilePathCallback& callback) { | 517 const GetEntryInfoWithFilePathCallback& callback) { |
| 518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 519 DCHECK(!callback.is_null()); | 519 DCHECK(!callback.is_null()); |
| 520 | 520 |
| 521 if (!doc_entry.get()) { | 521 if (!doc_entry.get()) { |
| 522 PostGetEntryInfoWithFilePathCallbackError( | 522 PostGetEntryInfoWithFilePathCallbackError( |
| 523 callback, DRIVE_FILE_ERROR_FAILED); | 523 callback, DRIVE_FILE_ERROR_FAILED); |
| 524 return; | 524 return; |
| 525 } | 525 } |
| 526 | 526 |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 DCHECK(!callback.is_null()); | 864 DCHECK(!callback.is_null()); |
| 865 DCHECK(result.get()); | 865 DCHECK(result.get()); |
| 866 | 866 |
| 867 result->second.path = second_path; | 867 result->second.path = second_path; |
| 868 result->second.error = error; | 868 result->second.error = error; |
| 869 result->second.proto = entry_proto.Pass(); | 869 result->second.proto = entry_proto.Pass(); |
| 870 | 870 |
| 871 callback.Run(result.Pass()); | 871 callback.Run(result.Pass()); |
| 872 } | 872 } |
| 873 | 873 |
| 874 } // namespace gdata | 874 } // namespace drive |
| OLD | NEW |