Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / libaddressinput / chromium / chrome_metadata_source.h
blob79d337e4f3c1bc03a59a718fa34d8b3eaedc2fbd
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
3 // found in the LICENSE file.
5 #ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_METADATA_SOURCE_H_
6 #define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_METADATA_SOURCE_H_
8 #include <map>
9 #include <string>
11 #include "net/url_request/url_fetcher_delegate.h"
12 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/source.h"
14 namespace net {
15 class URLFetcher;
16 class URLRequestContextGetter;
19 namespace autofill {
21 // A class for downloading rules to let libaddressinput validate international
22 // addresses.
23 class ChromeMetadataSource : public ::i18n::addressinput::Source,
24 public net::URLFetcherDelegate {
25 public:
26 ChromeMetadataSource(const std::string& validation_data_url,
27 net::URLRequestContextGetter* getter);
28 virtual ~ChromeMetadataSource();
30 // ::i18n::addressinput::Source:
31 virtual void Get(const std::string& key,
32 const Callback& downloaded) const override;
34 // net::URLFetcherDelegate:
35 virtual void OnURLFetchComplete(const net::URLFetcher* source) override;
37 private:
38 struct Request {
39 Request(const std::string& key,
40 scoped_ptr<net::URLFetcher> fetcher,
41 const Callback& callback);
43 std::string key;
44 // The data that's received.
45 std::string data;
46 // The object that manages retrieving the data.
47 scoped_ptr<net::URLFetcher> fetcher;
48 const Callback& callback;
51 // Non-const method actually implementing Get().
52 void Download(const std::string& key, const Callback& downloaded);
54 const std::string validation_data_url_;
55 net::URLRequestContextGetter* const getter_; // weak
57 // Maps from active URL fetcher to request metadata. The value is owned.
58 std::map<const net::URLFetcher*, Request*> requests_;
60 DISALLOW_COPY_AND_ASSIGN(ChromeMetadataSource);
63 } // namespace autofill
65 #endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_METADATA_SOURCE_H_