Chromium Code Reviews| 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 "third_party/libaddressinput/chromium/chrome_downloader_impl.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "net/base/load_flags.h" | |
| 10 #include "net/http/http_status_code.h" | |
| 11 #include "net/url_request/url_fetcher.h" | |
| 12 #include "url/gurl.h" | |
| 13 | |
| 14 ChromeDownloaderImpl::ChromeDownloaderImpl(net::URLRequestContextGetter* getter) | |
| 15 : getter_(getter) {} | |
| 16 | |
| 17 ChromeDownloaderImpl::~ChromeDownloaderImpl() { | |
| 18 STLDeleteContainerPairPointers(requests_.begin(), requests_.end()); | |
| 19 } | |
| 20 | |
| 21 void ChromeDownloaderImpl::Download( | |
| 22 const std::string& url, | |
| 23 scoped_ptr<Callback> downloaded) { | |
| 24 net::URLFetcher* fetcher = | |
| 25 net::URLFetcher::Create(GURL(url), net::URLFetcher::GET, this); | |
| 26 fetcher->SetLoadFlags( | |
| 27 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); | |
| 28 fetcher->SetRequestContext(getter_); | |
| 29 | |
| 30 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.
| |
| 31 fetcher->Start(); | |
| 32 } | |
| 33 | |
| 34 void ChromeDownloaderImpl::OnURLFetchComplete(const net::URLFetcher* source) { | |
| 35 std::map<const net::URLFetcher*, Request*>::iterator request = | |
| 36 requests_.find(source); | |
| 37 DCHECK(request != requests_.end()); | |
| 38 | |
| 39 bool ok = source->GetResponseCode() == net::HTTP_OK; | |
| 40 std::string data; | |
| 41 if (ok) | |
| 42 source->GetResponseAsString(&data); | |
| 43 (*request->second->callback)(ok, request->second->url, data); | |
| 44 | |
| 45 delete request->first; | |
| 46 delete request->second; | |
| 47 requests_.erase(request); | |
| 48 } | |
| 49 | |
| 50 ChromeDownloaderImpl::Request::Request(const std::string& url, | |
| 51 scoped_ptr<Callback> callback) | |
| 52 : url(url), | |
| 53 callback(callback.Pass()) {} | |
| OLD | NEW |