| 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_metadata_source.h" | 5 #include "third_party/libaddressinput/chromium/chrome_metadata_source.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 11 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
| 12 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 13 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 14 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
| 15 #include "net/url_request/url_fetcher.h" | 17 #include "net/url_request/url_fetcher.h" |
| 16 #include "net/url_request/url_fetcher_response_writer.h" | 18 #include "net/url_request/url_fetcher_response_writer.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 data->swap(request->second->data); | 78 data->swap(request->second->data); |
| 77 request->second->callback(ok, request->second->key, data.release()); | 79 request->second->callback(ok, request->second->key, data.release()); |
| 78 | 80 |
| 79 delete request->second; | 81 delete request->second; |
| 80 requests_.erase(request); | 82 requests_.erase(request); |
| 81 } | 83 } |
| 82 | 84 |
| 83 ChromeMetadataSource::Request::Request(const std::string& key, | 85 ChromeMetadataSource::Request::Request(const std::string& key, |
| 84 scoped_ptr<net::URLFetcher> fetcher, | 86 scoped_ptr<net::URLFetcher> fetcher, |
| 85 const Callback& callback) | 87 const Callback& callback) |
| 86 : key(key), | 88 : key(key), fetcher(std::move(fetcher)), callback(callback) {} |
| 87 fetcher(fetcher.Pass()), | |
| 88 callback(callback) {} | |
| 89 | 89 |
| 90 void ChromeMetadataSource::Download(const std::string& key, | 90 void ChromeMetadataSource::Download(const std::string& key, |
| 91 const Callback& downloaded) { | 91 const Callback& downloaded) { |
| 92 GURL resource(validation_data_url_ + key); | 92 GURL resource(validation_data_url_ + key); |
| 93 if (!resource.SchemeIsCryptographic()) { | 93 if (!resource.SchemeIsCryptographic()) { |
| 94 downloaded(false, key, NULL); | 94 downloaded(false, key, NULL); |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 | 97 |
| 98 scoped_ptr<net::URLFetcher> fetcher = | 98 scoped_ptr<net::URLFetcher> fetcher = |
| 99 net::URLFetcher::Create(resource, net::URLFetcher::GET, this); | 99 net::URLFetcher::Create(resource, net::URLFetcher::GET, this); |
| 100 fetcher->SetLoadFlags( | 100 fetcher->SetLoadFlags( |
| 101 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); | 101 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); |
| 102 fetcher->SetRequestContext(getter_); | 102 fetcher->SetRequestContext(getter_); |
| 103 | 103 |
| 104 Request* request = new Request(key, fetcher.Pass(), downloaded); | 104 Request* request = new Request(key, std::move(fetcher), downloaded); |
| 105 request->fetcher->SaveResponseWithWriter( | 105 request->fetcher->SaveResponseWithWriter( |
| 106 scoped_ptr<net::URLFetcherResponseWriter>( | 106 scoped_ptr<net::URLFetcherResponseWriter>( |
| 107 new UnownedStringWriter(&request->data))); | 107 new UnownedStringWriter(&request->data))); |
| 108 requests_[request->fetcher.get()] = request; | 108 requests_[request->fetcher.get()] = request; |
| 109 request->fetcher->Start(); | 109 request->fetcher->Start(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace autofill | 112 } // namespace autofill |
| OLD | NEW |