diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-20 08:06:36 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-20 08:06:36 +0000 |
commit | b360d67852164cca4d5d30758c5d6eb87786ee95 (patch) | |
tree | a5fd979614c784fe2f4f887754274d98253a8a31 | |
parent | 558c1905c0a070531c4cbd592c9052a16ab61d20 (diff) | |
download | chromium_src-b360d67852164cca4d5d30758c5d6eb87786ee95.zip chromium_src-b360d67852164cca4d5d30758c5d6eb87786ee95.tar.gz chromium_src-b360d67852164cca4d5d30758c5d6eb87786ee95.tar.bz2 |
drive: Stop returning scoped_ptr from ResourceMetadataStorage::GetHeader
BUG=None
TEST=unit_tests
R=kinaba@chromium.org
Review URL: https://codereview.chromium.org/17210003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207349 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 16 insertions, 24 deletions
diff --git a/chrome/browser/chromeos/drive/resource_metadata_storage.cc b/chrome/browser/chromeos/drive/resource_metadata_storage.cc index d596dc6..b9c8bbf 100644 --- a/chrome/browser/chromeos/drive/resource_metadata_storage.cc +++ b/chrome/browser/chromeos/drive/resource_metadata_storage.cc @@ -230,8 +230,8 @@ bool ResourceMetadataStorage::Initialize() { resource_map_.reset(db); // Check the validity of existing DB. - scoped_ptr<ResourceMetadataHeader> header = GetHeader(); - if (!header || header->version() != kDBVersion) { + ResourceMetadataHeader header; + if (!GetHeader(&header) || header.version() != kDBVersion) { open_existing_result = DB_INIT_INCOMPATIBLE; LOG(INFO) << "Reject incompatible DB."; } else if (!CheckValidity()) { @@ -288,23 +288,23 @@ bool ResourceMetadataStorage::SetLargestChangestamp( int64 largest_changestamp) { base::ThreadRestrictions::AssertIOAllowed(); - scoped_ptr<ResourceMetadataHeader> header = GetHeader(); - if (!header) { + ResourceMetadataHeader header; + if (!GetHeader(&header)) { DLOG(ERROR) << "Failed to get the header."; return false; } - header->set_largest_changestamp(largest_changestamp); - return PutHeader(*header); + header.set_largest_changestamp(largest_changestamp); + return PutHeader(header); } int64 ResourceMetadataStorage::GetLargestChangestamp() { base::ThreadRestrictions::AssertIOAllowed(); - scoped_ptr<ResourceMetadataHeader> header = GetHeader(); - if (!header) { + ResourceMetadataHeader header; + if (!GetHeader(&header)) { DLOG(ERROR) << "Failed to get the header."; return 0; } - return header->largest_changestamp(); + return header.largest_changestamp(); } bool ResourceMetadataStorage::PutEntry(const ResourceEntry& entry) { @@ -492,8 +492,7 @@ bool ResourceMetadataStorage::PutHeader( return status.ok(); } -scoped_ptr<ResourceMetadataHeader> -ResourceMetadataStorage::GetHeader() { +bool ResourceMetadataStorage::GetHeader(ResourceMetadataHeader* header) { base::ThreadRestrictions::AssertIOAllowed(); std::string serialized_header; @@ -501,14 +500,7 @@ ResourceMetadataStorage::GetHeader() { leveldb::ReadOptions(), leveldb::Slice(GetHeaderDBKey()), &serialized_header); - if (!status.ok()) - return scoped_ptr<ResourceMetadataHeader>(); - - scoped_ptr<ResourceMetadataHeader> header( - new ResourceMetadataHeader); - if (!header->ParseFromString(serialized_header)) - return scoped_ptr<ResourceMetadataHeader>(); - return header.Pass(); + return status.ok() && header->ParseFromString(serialized_header); } bool ResourceMetadataStorage::CheckValidity() { diff --git a/chrome/browser/chromeos/drive/resource_metadata_storage.h b/chrome/browser/chromeos/drive/resource_metadata_storage.h index edd4a3f..c4d12f1 100644 --- a/chrome/browser/chromeos/drive/resource_metadata_storage.h +++ b/chrome/browser/chromeos/drive/resource_metadata_storage.h @@ -147,7 +147,7 @@ class ResourceMetadataStorage { bool PutHeader(const ResourceMetadataHeader& header); // Gets header. - scoped_ptr<ResourceMetadataHeader> GetHeader(); + bool GetHeader(ResourceMetadataHeader* out_header); // Checks validity of the data. bool CheckValidity(); diff --git a/chrome/browser/chromeos/drive/resource_metadata_storage_unittest.cc b/chrome/browser/chromeos/drive/resource_metadata_storage_unittest.cc index 14e711b..ae57e65 100644 --- a/chrome/browser/chromeos/drive/resource_metadata_storage_unittest.cc +++ b/chrome/browser/chromeos/drive/resource_metadata_storage_unittest.cc @@ -28,10 +28,10 @@ class ResourceMetadataStorageTest : public testing::Test { // Overwrites |storage_|'s version. void SetDBVersion(int version) { - scoped_ptr<ResourceMetadataHeader> header = storage_->GetHeader(); - ASSERT_TRUE(header); - header->set_version(version); - storage_->PutHeader(*header); + ResourceMetadataHeader header; + ASSERT_TRUE(storage_->GetHeader(&header)); + header.set_version(version); + EXPECT_TRUE(storage_->PutHeader(header)); } bool CheckValidity() { |