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_
11 #include "base/memory/scoped_vector.h"
12 #include "net/url_request/url_fetcher_delegate.h"
13 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/source.h"
17 class URLRequestContextGetter
;
22 // A class for downloading rules to let libaddressinput validate international
24 class ChromeMetadataSource
: public ::i18n::addressinput::Source
,
25 public net::URLFetcherDelegate
{
27 ChromeMetadataSource(const std::string
& validation_data_url
,
28 net::URLRequestContextGetter
* getter
);
29 virtual ~ChromeMetadataSource();
31 // ::i18n::addressinput::Source:
32 virtual void Get(const std::string
& key
,
33 const Callback
& downloaded
) const override
;
35 // net::URLFetcherDelegate:
36 virtual void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
40 Request(const std::string
& key
,
41 scoped_ptr
<net::URLFetcher
> fetcher
,
42 const Callback
& callback
);
45 // The data that's received.
47 // The object that manages retrieving the data.
48 scoped_ptr
<net::URLFetcher
> fetcher
;
49 const Callback
& callback
;
52 // Non-const method actually implementing Get().
53 void Download(const std::string
& key
, const Callback
& downloaded
);
55 const std::string validation_data_url_
;
56 net::URLRequestContextGetter
* const getter_
; // weak
58 // Maps from active URL fetcher to request metadata. The value is owned.
59 std::map
<const net::URLFetcher
*, Request
*> requests_
;
61 DISALLOW_COPY_AND_ASSIGN(ChromeMetadataSource
);
64 } // namespace autofill
66 #endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_METADATA_SOURCE_H_