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

Unified Diff: third_party/libaddressinput/chromium/chrome_downloader_impl.cc

Issue 127223003: [rAc - libaddressinput] Chrome download impl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync'd Created 6 years, 11 months 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
Index: third_party/libaddressinput/chromium/chrome_downloader_impl.cc
diff --git a/third_party/libaddressinput/chromium/chrome_downloader_impl.cc b/third_party/libaddressinput/chromium/chrome_downloader_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2502262a17340b78757e776f9b216fadb4c9bc94
--- /dev/null
+++ b/third_party/libaddressinput/chromium/chrome_downloader_impl.cc
@@ -0,0 +1,53 @@
+// 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 "third_party/libaddressinput/chromium/chrome_downloader_impl.h"
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "net/base/load_flags.h"
+#include "net/http/http_status_code.h"
+#include "net/url_request/url_fetcher.h"
+#include "url/gurl.h"
+
+ChromeDownloaderImpl::ChromeDownloaderImpl(net::URLRequestContextGetter* getter)
+ : getter_(getter) {}
+
+ChromeDownloaderImpl::~ChromeDownloaderImpl() {
+ STLDeleteContainerPairPointers(requests_.begin(), requests_.end());
+}
+
+void ChromeDownloaderImpl::Download(
+ const std::string& url,
+ scoped_ptr<Callback> downloaded) {
+ net::URLFetcher* fetcher =
+ net::URLFetcher::Create(GURL(url), net::URLFetcher::GET, this);
+ fetcher->SetLoadFlags(
+ net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES);
+ fetcher->SetRequestContext(getter_);
+
+ requests_[fetcher] = new Request(url, downloaded.Pass());
please use gerrit instead 2014/01/08 01:36:26 nit: requests_.insert(std::make_pair(fetcher, new
Evan Stade 2014/01/09 00:05:12 Do you have documentation for that assertion? inse
please use gerrit instead 2014/01/09 00:21:13 Couldn't find any docs. Carry on.
+ fetcher->Start();
+}
+
+void ChromeDownloaderImpl::OnURLFetchComplete(const net::URLFetcher* source) {
+ std::map<const net::URLFetcher*, Request*>::iterator request =
+ requests_.find(source);
+ DCHECK(request != requests_.end());
+
+ bool ok = source->GetResponseCode() == net::HTTP_OK;
+ std::string data;
+ if (ok)
+ source->GetResponseAsString(&data);
+ (*request->second->callback)(ok, request->second->url, data);
+
+ delete request->first;
+ delete request->second;
+ requests_.erase(request);
+}
+
+ChromeDownloaderImpl::Request::Request(const std::string& url,
+ scoped_ptr<Callback> callback)
+ : url(url),
+ callback(callback.Pass()) {}

Powered by Google App Engine
This is Rietveld 408576698