| 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_METADATA_SOURCE_H_ | 5 #ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_METADATA_SOURCE_H_ |
| 6 #define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_METADATA_SOURCE_H_ | 6 #define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_METADATA_SOURCE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "net/url_request/url_fetcher_delegate.h" | 13 #include "net/url_request/url_fetcher_delegate.h" |
| 14 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/source.h" | 14 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/source.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 class URLFetcher; | 17 class URLFetcher; |
| 18 class URLRequestContextGetter; | 18 class URLRequestContextGetter; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace autofill { | 21 namespace autofill { |
| 22 | 22 |
| 23 // A class for downloading rules to let libaddressinput validate international | 23 // A class for downloading rules to let libaddressinput validate international |
| 24 // addresses. | 24 // addresses. |
| 25 class ChromeMetadataSource : public ::i18n::addressinput::Source, | 25 class ChromeMetadataSource : public ::i18n::addressinput::Source, |
| 26 public net::URLFetcherDelegate { | 26 public net::URLFetcherDelegate { |
| 27 public: | 27 public: |
| 28 ChromeMetadataSource(const std::string& validation_data_url, | 28 ChromeMetadataSource(const std::string& validation_data_url, |
| 29 net::URLRequestContextGetter* getter); | 29 net::URLRequestContextGetter* getter); |
| 30 virtual ~ChromeMetadataSource(); | 30 virtual ~ChromeMetadataSource(); |
| 31 | 31 |
| 32 // ::i18n::addressinput::Source: | 32 // ::i18n::addressinput::Source: |
| 33 virtual void Get(const std::string& key, | 33 virtual void Get(const std::string& key, |
| 34 const Callback& downloaded) const override; | 34 const Callback& downloaded) const override; |
| 35 | 35 |
| 36 // net::URLFetcherDelegate: | 36 // net::URLFetcherDelegate: |
| 37 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; | 37 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 struct Request { | 40 struct Request { |
| 41 Request(const std::string& key, | 41 Request(const std::string& key, |
| 42 scoped_ptr<net::URLFetcher> fetcher, | 42 std::unique_ptr<net::URLFetcher> fetcher, |
| 43 const Callback& callback); | 43 const Callback& callback); |
| 44 | 44 |
| 45 std::string key; | 45 std::string key; |
| 46 // The data that's received. | 46 // The data that's received. |
| 47 std::string data; | 47 std::string data; |
| 48 // The object that manages retrieving the data. | 48 // The object that manages retrieving the data. |
| 49 scoped_ptr<net::URLFetcher> fetcher; | 49 std::unique_ptr<net::URLFetcher> fetcher; |
| 50 const Callback& callback; | 50 const Callback& callback; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 // Non-const method actually implementing Get(). | 53 // Non-const method actually implementing Get(). |
| 54 void Download(const std::string& key, const Callback& downloaded); | 54 void Download(const std::string& key, const Callback& downloaded); |
| 55 | 55 |
| 56 const std::string validation_data_url_; | 56 const std::string validation_data_url_; |
| 57 net::URLRequestContextGetter* const getter_; // weak | 57 net::URLRequestContextGetter* const getter_; // weak |
| 58 | 58 |
| 59 // Maps from active URL fetcher to request metadata. The value is owned. | 59 // Maps from active URL fetcher to request metadata. The value is owned. |
| 60 std::map<const net::URLFetcher*, Request*> requests_; | 60 std::map<const net::URLFetcher*, Request*> requests_; |
| 61 | 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(ChromeMetadataSource); | 62 DISALLOW_COPY_AND_ASSIGN(ChromeMetadataSource); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 } // namespace autofill | 65 } // namespace autofill |
| 66 | 66 |
| 67 #endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_METADATA_SOURCE_H_ | 67 #endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_METADATA_SOURCE_H_ |
| OLD | NEW |