summaryrefslogtreecommitdiffstats
path: root/third_party
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-05 20:42:06 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-05 20:42:06 +0000
commitc03733152d359110e5d41895c2ecc20d75572054 (patch)
treee92aca64e5e8fe1a7c42775ac6e2fe8c7ed8ef5d /third_party
parentf8b470c658bf287f1a1c27e52e954a27fab54301 (diff)
downloadchromium_src-c03733152d359110e5d41895c2ecc20d75572054.zip
chromium_src-c03733152d359110e5d41895c2ecc20d75572054.tar.gz
chromium_src-c03733152d359110e5d41895c2ecc20d75572054.tar.bz2
libaddressinput - reduce number of copies in storage class by 2
1. on the way in (Put) 2. on the way out (Get) BUG=337679 Review URL: https://codereview.chromium.org/148463003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249102 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r--third_party/libaddressinput/chromium/chrome_storage_impl.cc14
-rw-r--r--third_party/libaddressinput/chromium/chrome_storage_impl.h3
-rw-r--r--third_party/libaddressinput/chromium/cpp/include/libaddressinput/storage.h2
-rw-r--r--third_party/libaddressinput/chromium/cpp/src/retriever.cc3
-rw-r--r--third_party/libaddressinput/chromium/cpp/test/fake_storage.cc4
-rw-r--r--third_party/libaddressinput/chromium/cpp/test/fake_storage.h4
-rw-r--r--third_party/libaddressinput/chromium/cpp/test/retriever_test.cc11
-rw-r--r--third_party/libaddressinput/chromium/cpp/test/storage_test_runner.cc6
8 files changed, 26 insertions, 21 deletions
diff --git a/third_party/libaddressinput/chromium/chrome_storage_impl.cc b/third_party/libaddressinput/chromium/chrome_storage_impl.cc
index ea1fca4..8b69319 100644
--- a/third_party/libaddressinput/chromium/chrome_storage_impl.cc
+++ b/third_party/libaddressinput/chromium/chrome_storage_impl.cc
@@ -17,8 +17,12 @@ ChromeStorageImpl::ChromeStorageImpl(WriteablePrefStore* store)
ChromeStorageImpl::~ChromeStorageImpl() {}
-void ChromeStorageImpl::Put(const std::string& key, const std::string& data) {
- backing_store_->SetValue(key, new base::StringValue(data));
+void ChromeStorageImpl::Put(const std::string& key,
+ scoped_ptr<std::string> data) {
+ scoped_ptr<base::StringValue> string_value(
+ new base::StringValue(std::string()));
+ string_value->GetString()->swap(*data);
+ backing_store_->SetValue(key, string_value.release());
}
void ChromeStorageImpl::Get(
@@ -50,10 +54,10 @@ void ChromeStorageImpl::DoGet(
}
const base::Value* value;
- std::string result;
+ const base::StringValue* string_value;
if (backing_store_->GetValue(key, &value) &&
- value->GetAsString(&result)) {
- (*data_ready)(true, key, result);
+ value->GetAsString(&string_value)) {
+ (*data_ready)(true, key, string_value->GetString());
} else {
(*data_ready)(false, key, std::string());
}
diff --git a/third_party/libaddressinput/chromium/chrome_storage_impl.h b/third_party/libaddressinput/chromium/chrome_storage_impl.h
index 98c21e1..5ee657b 100644
--- a/third_party/libaddressinput/chromium/chrome_storage_impl.h
+++ b/third_party/libaddressinput/chromium/chrome_storage_impl.h
@@ -28,7 +28,8 @@ class ChromeStorageImpl : public ::i18n::addressinput::Storage,
virtual ~ChromeStorageImpl();
// ::i18n::addressinput::Storage implementation.
- virtual void Put(const std::string& key, const std::string& data) OVERRIDE;
+ virtual void Put(const std::string& key, scoped_ptr<std::string> data)
+ OVERRIDE;
virtual void Get(const std::string& key, scoped_ptr<Callback> data_ready)
const OVERRIDE;
diff --git a/third_party/libaddressinput/chromium/cpp/include/libaddressinput/storage.h b/third_party/libaddressinput/chromium/cpp/include/libaddressinput/storage.h
index 95ff3ca..213c66b 100644
--- a/third_party/libaddressinput/chromium/cpp/include/libaddressinput/storage.h
+++ b/third_party/libaddressinput/chromium/cpp/include/libaddressinput/storage.h
@@ -47,7 +47,7 @@ class Storage {
virtual ~Storage() {}
// Stores |data| for |key|.
- virtual void Put(const std::string& key, const std::string& data) = 0;
+ virtual void Put(const std::string& key, scoped_ptr<std::string> data) = 0;
// Retrieves the data for |key| and invokes the |data_ready| callback.
virtual void Get(const std::string& key,
diff --git a/third_party/libaddressinput/chromium/cpp/src/retriever.cc b/third_party/libaddressinput/chromium/cpp/src/retriever.cc
index 7e0da10..9287677 100644
--- a/third_party/libaddressinput/chromium/cpp/src/retriever.cc
+++ b/third_party/libaddressinput/chromium/cpp/src/retriever.cc
@@ -211,8 +211,7 @@ void Retriever::OnDownloaded(bool success,
if (success) {
InvokeCallbackForKey(key, success, *downloaded_data);
AppendTimestamp(downloaded_data.get());
- // TODO(estade): storage should take a scoped_ptr.
- storage_->Put(key, *downloaded_data);
+ storage_->Put(key, downloaded_data.Pass());
} else if (stale_data_it != stale_data_.end()) {
InvokeCallbackForKey(key, true, stale_data_it->second);
} else {
diff --git a/third_party/libaddressinput/chromium/cpp/test/fake_storage.cc b/third_party/libaddressinput/chromium/cpp/test/fake_storage.cc
index 531b23d..2511b39 100644
--- a/third_party/libaddressinput/chromium/cpp/test/fake_storage.cc
+++ b/third_party/libaddressinput/chromium/cpp/test/fake_storage.cc
@@ -24,8 +24,8 @@ FakeStorage::FakeStorage() {}
FakeStorage::~FakeStorage() {}
-void FakeStorage::Put(const std::string& key, const std::string& data) {
- data_[key] = data;
+void FakeStorage::Put(const std::string& key, scoped_ptr<std::string> data) {
+ data_[key] = *data;
}
void FakeStorage::Get(const std::string& key,
diff --git a/third_party/libaddressinput/chromium/cpp/test/fake_storage.h b/third_party/libaddressinput/chromium/cpp/test/fake_storage.h
index 1987a2d..bafb9a2 100644
--- a/third_party/libaddressinput/chromium/cpp/test/fake_storage.h
+++ b/third_party/libaddressinput/chromium/cpp/test/fake_storage.h
@@ -34,7 +34,7 @@ namespace addressinput {
// ~MyClass() {}
//
// void Write() {
-// storage_.Put("key", "value");
+// storage_.Put("key", make_scoped_ptr(new std::string("value")));
// }
//
// void Read() {
@@ -58,7 +58,7 @@ class FakeStorage : public Storage {
virtual ~FakeStorage();
// Storage implementation.
- virtual void Put(const std::string& key, const std::string& data);
+ virtual void Put(const std::string& key, scoped_ptr<std::string> data);
virtual void Get(const std::string& key, scoped_ptr<Callback> data_ready)
const;
diff --git a/third_party/libaddressinput/chromium/cpp/test/retriever_test.cc b/third_party/libaddressinput/chromium/cpp/test/retriever_test.cc
index f1ba089..95a8d5f 100644
--- a/third_party/libaddressinput/chromium/cpp/test/retriever_test.cc
+++ b/third_party/libaddressinput/chromium/cpp/test/retriever_test.cc
@@ -44,10 +44,11 @@ const char kEmptyData[] = "{}";
// integrity.
const char kEmptyDataChecksum[] = "99914b932bd37a50b983c5e7c90ae93b";
-std::string Wrap(const std::string& data,
- const std::string& checksum,
- const std::string& timestamp) {
- return data + "\n" + "checksum=" + checksum + "\n" + "timestamp=" + timestamp;
+scoped_ptr<std::string> Wrap(const std::string& data,
+ const std::string& checksum,
+ const std::string& timestamp) {
+ return make_scoped_ptr(new std::string(
+ data + "\n" + "checksum=" + checksum + "\n" + "timestamp=" + timestamp));
}
} // namespace
@@ -170,7 +171,7 @@ TEST_F(RetrieverTest, FaultyDownloaderFallback) {
}
TEST_F(RetrieverTest, NoChecksumAndTimestampWillRedownload) {
- storage_->Put(kKey, kEmptyData);
+ storage_->Put(kKey, make_scoped_ptr(new std::string(kEmptyData)));
retriever_->Retrieve(kKey, BuildCallback());
EXPECT_TRUE(success_);
EXPECT_EQ(kKey, key_);
diff --git a/third_party/libaddressinput/chromium/cpp/test/storage_test_runner.cc b/third_party/libaddressinput/chromium/cpp/test/storage_test_runner.cc
index aac52e1..ff9895e 100644
--- a/third_party/libaddressinput/chromium/cpp/test/storage_test_runner.cc
+++ b/third_party/libaddressinput/chromium/cpp/test/storage_test_runner.cc
@@ -63,7 +63,7 @@ void StorageTestRunner::GetWithoutPutReturnsEmptyData() {
void StorageTestRunner::GetReturnsWhatWasPut() {
ClearValues();
- storage_->Put("key", "value");
+ storage_->Put("key", make_scoped_ptr(new std::string("value")));
storage_->Get("key", BuildCallback());
EXPECT_TRUE(success_);
@@ -73,8 +73,8 @@ void StorageTestRunner::GetReturnsWhatWasPut() {
void StorageTestRunner::SecondPutOverwritesData() {
ClearValues();
- storage_->Put("key", "bad-value");
- storage_->Put("key", "good-value");
+ storage_->Put("key", make_scoped_ptr(new std::string("bad-value")));
+ storage_->Put("key", make_scoped_ptr(new std::string("good-value")));
storage_->Get("key", BuildCallback());
EXPECT_TRUE(success_);