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 <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "components/prefs/writeable_pref_store.h" | 12 #include "components/prefs/writeable_pref_store.h" |
12 #include "third_party/libaddressinput/chromium/fallback_data_store.h" | 13 #include "third_party/libaddressinput/chromium/fallback_data_store.h" |
13 | 14 |
14 namespace autofill { | 15 namespace autofill { |
15 | 16 |
16 ChromeStorageImpl::ChromeStorageImpl(WriteablePrefStore* store) | 17 ChromeStorageImpl::ChromeStorageImpl(WriteablePrefStore* store) |
17 : backing_store_(store), | 18 : backing_store_(store), |
18 scoped_observer_(this) { | 19 scoped_observer_(this) { |
19 scoped_observer_.Add(backing_store_); | 20 scoped_observer_.Add(backing_store_); |
20 } | 21 } |
21 | 22 |
22 ChromeStorageImpl::~ChromeStorageImpl() {} | 23 ChromeStorageImpl::~ChromeStorageImpl() {} |
23 | 24 |
24 void ChromeStorageImpl::Put(const std::string& key, std::string* data) { | 25 void ChromeStorageImpl::Put(const std::string& key, std::string* data) { |
25 DCHECK(data); | 26 DCHECK(data); |
26 std::unique_ptr<std::string> owned_data(data); | 27 std::unique_ptr<std::string> owned_data(data); |
27 std::unique_ptr<base::StringValue> string_value( | 28 backing_store_->SetValue( |
28 new base::StringValue(std::string())); | 29 key, base::MakeUnique<base::StringValue>(std::move(*owned_data)), |
29 string_value->GetString()->swap(*owned_data); | 30 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
30 backing_store_->SetValue(key, std::move(string_value), | |
31 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | |
32 } | 31 } |
33 | 32 |
34 void ChromeStorageImpl::Get(const std::string& key, | 33 void ChromeStorageImpl::Get(const std::string& key, |
35 const Storage::Callback& data_ready) const { | 34 const Storage::Callback& data_ready) const { |
36 // |Get()| should not be const, so this is just a thunk that fixes that. | 35 // |Get()| should not be const, so this is just a thunk that fixes that. |
37 const_cast<ChromeStorageImpl*>(this)->DoGet(key, data_ready); | 36 const_cast<ChromeStorageImpl*>(this)->DoGet(key, data_ready); |
38 } | 37 } |
39 | 38 |
40 void ChromeStorageImpl::OnPrefValueChanged(const std::string& key) {} | 39 void ChromeStorageImpl::OnPrefValueChanged(const std::string& key) {} |
41 | 40 |
(...skipping 23 matching lines...) Expand all Loading... |
65 data_ready(false, key, NULL); | 64 data_ready(false, key, NULL); |
66 } | 65 } |
67 } | 66 } |
68 | 67 |
69 ChromeStorageImpl::Request::Request(const std::string& key, | 68 ChromeStorageImpl::Request::Request(const std::string& key, |
70 const Callback& callback) | 69 const Callback& callback) |
71 : key(key), | 70 : key(key), |
72 callback(callback) {} | 71 callback(callback) {} |
73 | 72 |
74 } // namespace autofill | 73 } // namespace autofill |
OLD | NEW |