| 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 namespace autofill { | 10 namespace autofill { |
| 11 | 11 |
| 12 ChromeStorageImpl::ChromeStorageImpl(WriteablePrefStore* store) | 12 ChromeStorageImpl::ChromeStorageImpl(WriteablePrefStore* store) |
| 13 : backing_store_(store), | 13 : backing_store_(store), |
| 14 scoped_observer_(this) { | 14 scoped_observer_(this) { |
| 15 scoped_observer_.Add(backing_store_); | 15 scoped_observer_.Add(backing_store_); |
| 16 } | 16 } |
| 17 | 17 |
| 18 ChromeStorageImpl::~ChromeStorageImpl() {} | 18 ChromeStorageImpl::~ChromeStorageImpl() {} |
| 19 | 19 |
| 20 void ChromeStorageImpl::Put(const std::string& key, const std::string& data) { | 20 void ChromeStorageImpl::Put(const std::string& key, |
| 21 backing_store_->SetValue(key, new base::StringValue(data)); | 21 scoped_ptr<std::string> data) { |
| 22 scoped_ptr<base::StringValue> string_value( |
| 23 new base::StringValue(std::string())); |
| 24 string_value->GetString()->swap(*data); |
| 25 backing_store_->SetValue(key, string_value.release()); |
| 22 } | 26 } |
| 23 | 27 |
| 24 void ChromeStorageImpl::Get( | 28 void ChromeStorageImpl::Get( |
| 25 const std::string& key, | 29 const std::string& key, |
| 26 scoped_ptr<Storage::Callback> data_ready) const { | 30 scoped_ptr<Storage::Callback> data_ready) const { |
| 27 // |Get()| should not be const, so this is just a thunk that fixes that. | 31 // |Get()| should not be const, so this is just a thunk that fixes that. |
| 28 const_cast<ChromeStorageImpl*>(this)->DoGet(key, data_ready.Pass()); | 32 const_cast<ChromeStorageImpl*>(this)->DoGet(key, data_ready.Pass()); |
| 29 } | 33 } |
| 30 | 34 |
| 31 void ChromeStorageImpl::OnPrefValueChanged(const std::string& key) {} | 35 void ChromeStorageImpl::OnPrefValueChanged(const std::string& key) {} |
| (...skipping 11 matching lines...) Expand all Loading... |
| 43 void ChromeStorageImpl::DoGet( | 47 void ChromeStorageImpl::DoGet( |
| 44 const std::string& key, | 48 const std::string& key, |
| 45 scoped_ptr<Storage::Callback> data_ready) { | 49 scoped_ptr<Storage::Callback> data_ready) { |
| 46 if (!backing_store_->IsInitializationComplete()) { | 50 if (!backing_store_->IsInitializationComplete()) { |
| 47 outstanding_requests_.push_back( | 51 outstanding_requests_.push_back( |
| 48 new Request(key, data_ready.Pass())); | 52 new Request(key, data_ready.Pass())); |
| 49 return; | 53 return; |
| 50 } | 54 } |
| 51 | 55 |
| 52 const base::Value* value; | 56 const base::Value* value; |
| 53 std::string result; | 57 const base::StringValue* string_value; |
| 54 if (backing_store_->GetValue(key, &value) && | 58 if (backing_store_->GetValue(key, &value) && |
| 55 value->GetAsString(&result)) { | 59 value->GetAsString(&string_value)) { |
| 56 (*data_ready)(true, key, result); | 60 (*data_ready)(true, key, string_value->GetString()); |
| 57 } else { | 61 } else { |
| 58 (*data_ready)(false, key, std::string()); | 62 (*data_ready)(false, key, std::string()); |
| 59 } | 63 } |
| 60 } | 64 } |
| 61 | 65 |
| 62 ChromeStorageImpl::Request::Request(const std::string& key, | 66 ChromeStorageImpl::Request::Request(const std::string& key, |
| 63 scoped_ptr<Storage::Callback> callback) | 67 scoped_ptr<Storage::Callback> callback) |
| 64 : key(key), | 68 : key(key), |
| 65 callback(callback.Pass()) {} | 69 callback(callback.Pass()) {} |
| 66 | 70 |
| 67 } // namespace autofill | 71 } // namespace autofill |
| OLD | NEW |