| Index: components/autofill/core/browser/validation_downloader.cc
|
| diff --git a/components/autofill/core/browser/validation_downloader.cc b/components/autofill/core/browser/validation_downloader.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..98bd0a1bf49f24eaf218fec501915adb49d60049
|
| --- /dev/null
|
| +++ b/components/autofill/core/browser/validation_downloader.cc
|
| @@ -0,0 +1,46 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/autofill/core/browser/validation_downloader.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "net/url_request/url_fetcher.h"
|
| +
|
| +namespace autofill {
|
| +
|
| +ValidationDownloader::ValidationDownloader(net::UrlRequestContextGetter* getter)
|
| + : getter_(getter) {}
|
| +
|
| +ValidationDownloader::~ValidationDownloader() {}
|
| +
|
| +void ValidationDownloader::Download(
|
| + const std::string& url,
|
| + const i18n::addressinput::Downloader::Callback& downloaded) {
|
| + net::URLFetcher* fetcher(
|
| + net::URLFetcher::Create(GURL(url), net::URLFetcher::GET, this));
|
| + fetchers_.push_back(fetcher);
|
| + fetcher->SetRequestContext(getter_);
|
| + callbacks_[fetcher] = downloaded;
|
| + fetcher->Start();
|
| +}
|
| +
|
| +void ValidationDownloader::OnURLFetchComplete(const net::URLFetcher* source) {
|
| + DCHECK(fetchers_.find(source) != fetchers_.end());
|
| +
|
| + CallbackMap::iterator it = callbacks_.find(source);
|
| + if (it == callbacks_.end()) {
|
| + NOTREACHED();
|
| + return;
|
| + }
|
| +
|
| + bool ok = source->GetReponseCode() == net::HTTP_OK;
|
| + std::string url = source->GetOriginalURL().spec();
|
| + (it->second)(ok, url, ok ? source->GetResponseAsString() : std::string());
|
| + callbacks_.erase(it);
|
| +
|
| + // |source| is owned by |fetchers_| and will be deleted later.
|
| +}
|
| +
|
| +} // namespace autofill
|
|
|