Chromium Code Reviews| 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() {} |
|
please use gerrit instead
2013/12/02 17:33:26
Please invoke the remaining |callbacks_| with para
|
| + |
| +void ValidationDownloader::Download( |
| + const std::string& url, |
| + const i18n::addressinput::Downloader::Callback& downloaded) { |
| + net::URLFetcher* fetcher( |
|
Evan Stade
2013/12/02 21:50:04
The entirety of this function should be:
new I1
|
| + net::URLFetcher::Create(GURL(url), net::URLFetcher::GET, this)); |
| + fetchers_.push_back(fetcher); |
| + fetcher->SetRequestContext(getter_); |
|
Evan Stade
2013/12/04 20:23:38
Also you will want:
fetcher->SetLoadFlags(
|
| + 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. |
|
please use gerrit instead
2013/12/02 17:03:54
You could also do:
fetchers_.erase(source);
|
| +} |
| + |
| +} // namespace autofill |