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 #ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_STORAGE_IMPL_H_ | 5 #ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_STORAGE_IMPL_H_ |
6 #define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_STORAGE_IMPL_H_ | 6 #define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_STORAGE_IMPL_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/prefs/pref_store.h" | 12 #include "base/prefs/pref_store.h" |
13 #include "base/scoped_observer.h" | 13 #include "base/scoped_observer.h" |
14 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/stora
ge.h" | 14 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/storage.h" |
15 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/util/
scoped_ptr.h" | |
16 | 15 |
17 class WriteablePrefStore; | 16 class WriteablePrefStore; |
18 | 17 |
19 namespace autofill { | 18 namespace autofill { |
20 | 19 |
21 // An implementation of the Storage interface which passes through to an | 20 // An implementation of the Storage interface which passes through to an |
22 // underlying WriteablePrefStore. | 21 // underlying WriteablePrefStore. |
23 class ChromeStorageImpl : public ::i18n::addressinput::Storage, | 22 class ChromeStorageImpl : public ::i18n::addressinput::Storage, |
24 public PrefStore::Observer { | 23 public PrefStore::Observer { |
25 public: | 24 public: |
26 // |store| must outlive |this|. | 25 // |store| must outlive |this|. |
27 explicit ChromeStorageImpl(WriteablePrefStore* store); | 26 explicit ChromeStorageImpl(WriteablePrefStore* store); |
28 virtual ~ChromeStorageImpl(); | 27 virtual ~ChromeStorageImpl(); |
29 | 28 |
30 // ::i18n::addressinput::Storage implementation. | 29 // ::i18n::addressinput::Storage implementation. |
31 virtual void Put(const std::string& key, scoped_ptr<std::string> data) | 30 virtual void Put(const std::string& key, std::string* data) OVERRIDE; |
32 OVERRIDE; | 31 virtual void Get(const std::string& key, const Callback& data_ready) |
33 virtual void Get(const std::string& key, scoped_ptr<Callback> data_ready) | |
34 const OVERRIDE; | 32 const OVERRIDE; |
35 | 33 |
36 // PrefStore::Observer implementation. | 34 // PrefStore::Observer implementation. |
37 virtual void OnPrefValueChanged(const std::string& key) OVERRIDE; | 35 virtual void OnPrefValueChanged(const std::string& key) OVERRIDE; |
38 virtual void OnInitializationCompleted(bool succeeded) OVERRIDE; | 36 virtual void OnInitializationCompleted(bool succeeded) OVERRIDE; |
39 | 37 |
40 private: | 38 private: |
41 struct Request { | 39 struct Request { |
42 Request(const std::string& key, scoped_ptr<Callback> callback); | 40 Request(const std::string& key, const Callback& callback); |
43 | 41 |
44 std::string key; | 42 std::string key; |
45 scoped_ptr<Callback> callback; | 43 const Callback& callback; |
46 }; | 44 }; |
47 | 45 |
48 // Non-const version of Get(). | 46 // Non-const version of Get(). |
49 void DoGet(const std::string& key, scoped_ptr<Callback> data_ready); | 47 void DoGet(const std::string& key, const Callback& data_ready); |
50 | 48 |
51 WriteablePrefStore* backing_store_; // weak | 49 WriteablePrefStore* backing_store_; // weak |
52 | 50 |
53 // Get requests that haven't yet been serviced. | 51 // Get requests that haven't yet been serviced. |
54 ScopedVector<Request> outstanding_requests_; | 52 ScopedVector<Request> outstanding_requests_; |
55 | 53 |
56 ScopedObserver<PrefStore, ChromeStorageImpl> scoped_observer_; | 54 ScopedObserver<PrefStore, ChromeStorageImpl> scoped_observer_; |
57 | 55 |
58 DISALLOW_COPY_AND_ASSIGN(ChromeStorageImpl); | 56 DISALLOW_COPY_AND_ASSIGN(ChromeStorageImpl); |
59 }; | 57 }; |
60 | 58 |
61 } // namespace autofill | 59 } // namespace autofill |
62 | 60 |
63 #endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_STORAGE_IMPL_H_ | 61 #endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_STORAGE_IMPL_H_ |
OLD | NEW |