OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "third_party/libaddressinput/chromium/chrome_downloader_impl.h" | 5 #include "third_party/libaddressinput/chromium/chrome_downloader_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
10 #include "net/http/http_status_code.h" | 10 #include "net/http/http_status_code.h" |
11 #include "net/url_request/url_fetcher.h" | 11 #include "net/url_request/url_fetcher.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 | 13 |
| 14 namespace autofill { |
| 15 |
14 ChromeDownloaderImpl::ChromeDownloaderImpl(net::URLRequestContextGetter* getter) | 16 ChromeDownloaderImpl::ChromeDownloaderImpl(net::URLRequestContextGetter* getter) |
15 : getter_(getter) {} | 17 : getter_(getter) {} |
16 | 18 |
17 ChromeDownloaderImpl::~ChromeDownloaderImpl() { | 19 ChromeDownloaderImpl::~ChromeDownloaderImpl() { |
18 STLDeleteContainerPairPointers(requests_.begin(), requests_.end()); | 20 STLDeleteContainerPairPointers(requests_.begin(), requests_.end()); |
19 } | 21 } |
20 | 22 |
21 void ChromeDownloaderImpl::Download( | 23 void ChromeDownloaderImpl::Download( |
22 const std::string& url, | 24 const std::string& url, |
23 scoped_ptr<Callback> downloaded) { | 25 scoped_ptr<Callback> downloaded) { |
24 net::URLFetcher* fetcher = | 26 net::URLFetcher* fetcher = |
25 net::URLFetcher::Create(GURL(url), net::URLFetcher::GET, this); | 27 net::URLFetcher::Create(GURL(url), net::URLFetcher::GET, this); |
26 fetcher->SetLoadFlags( | 28 fetcher->SetLoadFlags( |
27 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); | 29 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); |
28 fetcher->SetRequestContext(getter_); | 30 fetcher->SetRequestContext(getter_); |
29 | 31 |
30 requests_[fetcher] = new Request(url, downloaded.Pass()); | 32 requests_[fetcher] = new Request(url, downloaded.Pass()); |
31 fetcher->Start(); | 33 fetcher->Start(); |
32 } | 34 } |
33 | 35 |
34 void ChromeDownloaderImpl::OnURLFetchComplete(const net::URLFetcher* source) { | 36 void ChromeDownloaderImpl::OnURLFetchComplete(const net::URLFetcher* source) { |
35 std::map<const net::URLFetcher*, Request*>::iterator request = | 37 std::map<const net::URLFetcher*, Request*>::iterator request = |
36 requests_.find(source); | 38 requests_.find(source); |
37 DCHECK(request != requests_.end()); | 39 DCHECK(request != requests_.end()); |
38 | 40 |
39 bool ok = source->GetResponseCode() == net::HTTP_OK; | 41 bool ok = source->GetResponseCode() == net::HTTP_OK; |
40 scoped_ptr<std::string> data(new std::string()); | 42 scoped_ptr<std::string> data(new std::string()); |
41 if (ok) | 43 if (ok) |
42 source->GetResponseAsString(&*data); | 44 source->GetResponseAsString(data.get()); |
43 (*request->second->callback)(ok, request->second->url, data.Pass()); | 45 (*request->second->callback)(ok, request->second->url, data.Pass()); |
44 | 46 |
45 delete request->first; | 47 delete request->first; |
46 delete request->second; | 48 delete request->second; |
47 requests_.erase(request); | 49 requests_.erase(request); |
48 } | 50 } |
49 | 51 |
50 ChromeDownloaderImpl::Request::Request(const std::string& url, | 52 ChromeDownloaderImpl::Request::Request(const std::string& url, |
51 scoped_ptr<Callback> callback) | 53 scoped_ptr<Callback> callback) |
52 : url(url), | 54 : url(url), |
53 callback(callback.Pass()) {} | 55 callback(callback.Pass()) {} |
| 56 |
| 57 } // namespace autofill |
OLD | NEW |