OLD | NEW |
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 // TODO(estade): this shouldn't be necessary. | |
18 for (std::vector<Request*>::iterator iter = | |
19 outstanding_requests_.begin(); | |
20 iter != outstanding_requests_.end(); ++iter) { | |
21 (*(*iter)->callback)(false, (*iter)->key, std::string()); | |
22 } | |
23 } | |
24 | 17 |
25 void ChromeStorageImpl::Put(const std::string& key, const std::string& data) { | 18 void ChromeStorageImpl::Put(const std::string& key, const std::string& data) { |
26 backing_store_->SetValue(key, new base::StringValue(data)); | 19 backing_store_->SetValue(key, new base::StringValue(data)); |
27 } | 20 } |
28 | 21 |
29 void ChromeStorageImpl::Get( | 22 void ChromeStorageImpl::Get( |
30 const std::string& key, | 23 const std::string& key, |
31 scoped_ptr<Storage::Callback> data_ready) const { | 24 scoped_ptr<Storage::Callback> data_ready) const { |
32 // |Get()| should not be const, so this is just a thunk that fixes that. | 25 // |Get()| should not be const, so this is just a thunk that fixes that. |
33 const_cast<ChromeStorageImpl*>(this)->DoGet(key, data_ready.Pass()); | 26 const_cast<ChromeStorageImpl*>(this)->DoGet(key, data_ready.Pass()); |
(...skipping 27 matching lines...) Expand all Loading... |
61 (*data_ready)(true, key, result); | 54 (*data_ready)(true, key, result); |
62 } else { | 55 } else { |
63 (*data_ready)(false, key, std::string()); | 56 (*data_ready)(false, key, std::string()); |
64 } | 57 } |
65 } | 58 } |
66 | 59 |
67 ChromeStorageImpl::Request::Request(const std::string& key, | 60 ChromeStorageImpl::Request::Request(const std::string& key, |
68 scoped_ptr<Storage::Callback> callback) | 61 scoped_ptr<Storage::Callback> callback) |
69 : key(key), | 62 : key(key), |
70 callback(callback.Pass()) {} | 63 callback(callback.Pass()) {} |
OLD | NEW |