Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: components/autofill/core/browser/validation_downloader.cc

Issue 96323002: Implement i18n::addressinput::Downloader for requestAutocomplete() (and (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/autofill/core/browser/validation_downloader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « components/autofill/core/browser/validation_downloader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698