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

Side by Side 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 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 unified diff | Download patch | Annotate | Revision Log
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 "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());
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()) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698