OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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. |
| 4 |
| 5 #include "components/autofill/core/browser/validation_downloader.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "net/url_request/url_fetcher.h" |
| 10 |
| 11 namespace autofill { |
| 12 |
| 13 ValidationDownloader::ValidationDownloader(net::UrlRequestContextGetter* getter) |
| 14 : getter_(getter) {} |
| 15 |
| 16 ValidationDownloader::~ValidationDownloader() {} |
| 17 |
| 18 void ValidationDownloader::Download( |
| 19 const std::string& url, |
| 20 const i18n::addressinput::Downloader::Callback& downloaded) { |
| 21 net::URLFetcher* fetcher( |
| 22 net::URLFetcher::Create(GURL(url), net::URLFetcher::GET, this)); |
| 23 fetchers_.push_back(fetcher); |
| 24 fetcher->SetRequestContext(getter_); |
| 25 callbacks_[fetcher] = downloaded; |
| 26 fetcher->Start(); |
| 27 } |
| 28 |
| 29 void ValidationDownloader::OnURLFetchComplete(const net::URLFetcher* source) { |
| 30 DCHECK(fetchers_.find(source) != fetchers_.end()); |
| 31 |
| 32 CallbackMap::iterator it = callbacks_.find(source); |
| 33 if (it == callbacks_.end()) { |
| 34 NOTREACHED(); |
| 35 return; |
| 36 } |
| 37 |
| 38 bool ok = source->GetReponseCode() == net::HTTP_OK; |
| 39 std::string url = source->GetOriginalURL().spec(); |
| 40 (it->second)(ok, url, ok ? source->GetResponseAsString() : std::string()); |
| 41 callbacks_.erase(it); |
| 42 |
| 43 // |source| is owned by |fetchers_| and will be deleted later. |
| 44 } |
| 45 |
| 46 } // namespace autofill |
OLD | NEW |