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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/core/browser/validation_downloader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« 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