Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: third_party/libaddressinput/chromium/chrome_storage_impl.cc

Issue 148463003: libaddressinput - reduce number of copies in storage class by 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "third_party/libaddressinput/chromium/chrome_storage_impl.h" 5 #include "third_party/libaddressinput/chromium/chrome_storage_impl.h"
6 6
7 #include "base/prefs/writeable_pref_store.h" 7 #include "base/prefs/writeable_pref_store.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 9
10 ChromeStorageImpl::ChromeStorageImpl(WriteablePrefStore* store) 10 ChromeStorageImpl::ChromeStorageImpl(WriteablePrefStore* store)
11 : backing_store_(store), 11 : backing_store_(store),
12 scoped_observer_(this) { 12 scoped_observer_(this) {
13 scoped_observer_.Add(backing_store_); 13 scoped_observer_.Add(backing_store_);
14 } 14 }
15 15
16 ChromeStorageImpl::~ChromeStorageImpl() {} 16 ChromeStorageImpl::~ChromeStorageImpl() {}
17 17
18 void ChromeStorageImpl::Put(const std::string& key, const std::string& data) { 18 void ChromeStorageImpl::Put(const std::string& key,
19 backing_store_->SetValue(key, new base::StringValue(data)); 19 scoped_ptr<std::string> data) {
20 backing_store_->SetValue(key, new base::StringValue(data.Pass()));
20 } 21 }
21 22
22 void ChromeStorageImpl::Get( 23 void ChromeStorageImpl::Get(
23 const std::string& key, 24 const std::string& key,
24 scoped_ptr<Storage::Callback> data_ready) const { 25 scoped_ptr<Storage::Callback> data_ready) const {
25 // |Get()| should not be const, so this is just a thunk that fixes that. 26 // |Get()| should not be const, so this is just a thunk that fixes that.
26 const_cast<ChromeStorageImpl*>(this)->DoGet(key, data_ready.Pass()); 27 const_cast<ChromeStorageImpl*>(this)->DoGet(key, data_ready.Pass());
27 } 28 }
28 29
29 void ChromeStorageImpl::OnPrefValueChanged(const std::string& key) {} 30 void ChromeStorageImpl::OnPrefValueChanged(const std::string& key) {}
(...skipping 11 matching lines...) Expand all
41 void ChromeStorageImpl::DoGet( 42 void ChromeStorageImpl::DoGet(
42 const std::string& key, 43 const std::string& key,
43 scoped_ptr<Storage::Callback> data_ready) { 44 scoped_ptr<Storage::Callback> data_ready) {
44 if (!backing_store_->IsInitializationComplete()) { 45 if (!backing_store_->IsInitializationComplete()) {
45 outstanding_requests_.push_back( 46 outstanding_requests_.push_back(
46 new Request(key, data_ready.Pass())); 47 new Request(key, data_ready.Pass()));
47 return; 48 return;
48 } 49 }
49 50
50 const base::Value* value; 51 const base::Value* value;
51 std::string result; 52 const base::StringValue* string_value;
52 if (backing_store_->GetValue(key, &value) && 53 if (backing_store_->GetValue(key, &value) &&
53 value->GetAsString(&result)) { 54 value->GetAsStringValue(&string_value)) {
54 (*data_ready)(true, key, result); 55 (*data_ready)(true, key, string_value->value());
55 } else { 56 } else {
56 (*data_ready)(false, key, std::string()); 57 (*data_ready)(false, key, std::string());
57 } 58 }
58 } 59 }
59 60
60 ChromeStorageImpl::Request::Request(const std::string& key, 61 ChromeStorageImpl::Request::Request(const std::string& key,
61 scoped_ptr<Storage::Callback> callback) 62 scoped_ptr<Storage::Callback> callback)
62 : key(key), 63 : key(key),
63 callback(callback.Pass()) {} 64 callback(callback.Pass()) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698