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

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

Issue 145553009: rAc: use libaddressinput to validate international addresses. (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 namespace autofill {
11
10 ChromeStorageImpl::ChromeStorageImpl(WriteablePrefStore* store) 12 ChromeStorageImpl::ChromeStorageImpl(WriteablePrefStore* store)
11 : backing_store_(store), 13 : backing_store_(store),
12 scoped_observer_(this) { 14 scoped_observer_(this) {
13 scoped_observer_.Add(backing_store_); 15 scoped_observer_.Add(backing_store_);
14 } 16 }
15 17
16 ChromeStorageImpl::~ChromeStorageImpl() {} 18 ChromeStorageImpl::~ChromeStorageImpl() {}
17 19
18 void ChromeStorageImpl::Put(const std::string& key, const std::string& data) { 20 void ChromeStorageImpl::Put(const std::string& key, const std::string& data) {
19 backing_store_->SetValue(key, new base::StringValue(data)); 21 backing_store_->SetValue(key, new base::StringValue(data));
20 } 22 }
21 23
22 void ChromeStorageImpl::Get( 24 void ChromeStorageImpl::Get(
23 const std::string& key, 25 const std::string& key,
24 scoped_ptr<Storage::Callback> data_ready) const {
25 // |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 }
28
29 void ChromeStorageImpl::OnPrefValueChanged(const std::string& key) {}
30
31 void ChromeStorageImpl::OnInitializationCompleted(bool succeeded) {
32 for (std::vector<Request*>::iterator iter =
33 outstanding_requests_.begin();
34 iter != outstanding_requests_.end(); ++iter) {
35 DoGet((*iter)->key, (*iter)->callback.Pass());
36 }
37
38 outstanding_requests_.clear();
39 }
40
41 void ChromeStorageImpl::DoGet(
42 const std::string& key,
43 scoped_ptr<Storage::Callback> data_ready) { 26 scoped_ptr<Storage::Callback> data_ready) {
44 if (!backing_store_->IsInitializationComplete()) { 27 if (!backing_store_->IsInitializationComplete()) {
45 outstanding_requests_.push_back( 28 outstanding_requests_.push_back(
46 new Request(key, data_ready.Pass())); 29 new Request(key, data_ready.Pass()));
47 return; 30 return;
48 } 31 }
49 32
50 const base::Value* value; 33 const base::Value* value;
51 std::string result; 34 std::string result;
52 if (backing_store_->GetValue(key, &value) && 35 if (backing_store_->GetValue(key, &value) &&
53 value->GetAsString(&result)) { 36 value->GetAsString(&result)) {
54 (*data_ready)(true, key, result); 37 (*data_ready)(true, key, result);
55 } else { 38 } else {
56 (*data_ready)(false, key, std::string()); 39 (*data_ready)(false, key, std::string());
57 } 40 }
58 } 41 }
59 42
43 void ChromeStorageImpl::OnPrefValueChanged(const std::string& key) {}
44
45 void ChromeStorageImpl::OnInitializationCompleted(bool succeeded) {
46 for (std::vector<Request*>::iterator iter =
47 outstanding_requests_.begin();
48 iter != outstanding_requests_.end(); ++iter) {
49 Get((*iter)->key, (*iter)->callback.Pass());
50 }
51
52 outstanding_requests_.clear();
53 }
54
60 ChromeStorageImpl::Request::Request(const std::string& key, 55 ChromeStorageImpl::Request::Request(const std::string& key,
61 scoped_ptr<Storage::Callback> callback) 56 scoped_ptr<Storage::Callback> callback)
62 : key(key), 57 : key(key),
63 callback(callback.Pass()) {} 58 callback(callback.Pass()) {}
59
60 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698