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/memory/ptr_util.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 | 32 |
33 void ChromeStorageImpl::Get(const std::string& key, | 33 void ChromeStorageImpl::Get(const std::string& key, |
34 const Storage::Callback& data_ready) const { | 34 const Storage::Callback& data_ready) const { |
35 // |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. |
36 const_cast<ChromeStorageImpl*>(this)->DoGet(key, data_ready); | 36 const_cast<ChromeStorageImpl*>(this)->DoGet(key, data_ready); |
37 } | 37 } |
38 | 38 |
39 void ChromeStorageImpl::OnPrefValueChanged(const std::string& key) {} | 39 void ChromeStorageImpl::OnPrefValueChanged(const std::string& key) {} |
40 | 40 |
41 void ChromeStorageImpl::OnInitializationCompleted(bool succeeded) { | 41 void ChromeStorageImpl::OnInitializationCompleted(bool succeeded) { |
42 for (std::vector<Request*>::iterator iter = outstanding_requests_.begin(); | 42 for (const auto& request : outstanding_requests_) |
43 iter != outstanding_requests_.end(); ++iter) { | 43 DoGet(request->key, request->callback); |
44 DoGet((*iter)->key, (*iter)->callback); | |
45 } | |
46 | 44 |
47 outstanding_requests_.clear(); | 45 outstanding_requests_.clear(); |
48 } | 46 } |
49 | 47 |
50 void ChromeStorageImpl::DoGet(const std::string& key, | 48 void ChromeStorageImpl::DoGet(const std::string& key, |
51 const Storage::Callback& data_ready) { | 49 const Storage::Callback& data_ready) { |
52 if (!backing_store_->IsInitializationComplete()) { | 50 if (!backing_store_->IsInitializationComplete()) { |
53 outstanding_requests_.push_back(new Request(key, data_ready)); | 51 outstanding_requests_.push_back(base::MakeUnique<Request>(key, data_ready)); |
please use gerrit instead
2017/07/07 13:41:18
Would this work?
outstanding_requests_.emplace_ba
Avi (use Gerrit)
2017/07/07 14:56:01
outstanding_requests_ is a vector of unique_ptr, s
| |
54 return; | 52 return; |
55 } | 53 } |
56 | 54 |
57 const base::Value* value = NULL; | 55 const base::Value* value = NULL; |
58 std::unique_ptr<std::string> data(new std::string); | 56 std::unique_ptr<std::string> data(new std::string); |
59 if (backing_store_->GetValue(key, &value) && value->GetAsString(data.get())) { | 57 if (backing_store_->GetValue(key, &value) && value->GetAsString(data.get())) { |
60 data_ready(true, key, data.release()); | 58 data_ready(true, key, data.release()); |
61 } else if (FallbackDataStore::Get(key, data.get())) { | 59 } else if (FallbackDataStore::Get(key, data.get())) { |
62 data_ready(true, key, data.release()); | 60 data_ready(true, key, data.release()); |
63 } else { | 61 } else { |
64 data_ready(false, key, NULL); | 62 data_ready(false, key, NULL); |
65 } | 63 } |
66 } | 64 } |
67 | 65 |
68 ChromeStorageImpl::Request::Request(const std::string& key, | 66 ChromeStorageImpl::Request::Request(const std::string& key, |
69 const Callback& callback) | 67 const Callback& callback) |
70 : key(key), | 68 : key(key), |
71 callback(callback) {} | 69 callback(callback) {} |
72 | 70 |
73 } // namespace autofill | 71 } // namespace autofill |
OLD | NEW |