| 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 "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/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/base/load_flags.h" | 10 #include "net/base/load_flags.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/http/http_status_code.h" | 12 #include "net/http/http_status_code.h" |
| 13 #include "net/url_request/url_fetcher.h" | 13 #include "net/url_request/url_fetcher.h" |
| 14 #include "net/url_request/url_fetcher_response_writer.h" | 14 #include "net/url_request/url_fetcher_response_writer.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 namespace autofill { | 17 namespace autofill { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // A URLFetcherResponseWriter that writes into a provided buffer. | 21 // A URLFetcherResponseWriter that writes into a provided buffer. |
| 22 class UnownedStringWriter : public net::URLFetcherResponseWriter { | 22 class UnownedStringWriter : public net::URLFetcherResponseWriter { |
| 23 public: | 23 public: |
| 24 UnownedStringWriter(std::string* data) : data_(data) {} | 24 UnownedStringWriter(std::string* data) : data_(data) {} |
| 25 virtual ~UnownedStringWriter() {} | 25 virtual ~UnownedStringWriter() {} |
| 26 | 26 |
| 27 virtual int Initialize(const net::CompletionCallback& callback) OVERRIDE { | 27 virtual int Initialize(const net::CompletionCallback& callback) override { |
| 28 data_->clear(); | 28 data_->clear(); |
| 29 return net::OK; | 29 return net::OK; |
| 30 } | 30 } |
| 31 | 31 |
| 32 virtual int Write(net::IOBuffer* buffer, | 32 virtual int Write(net::IOBuffer* buffer, |
| 33 int num_bytes, | 33 int num_bytes, |
| 34 const net::CompletionCallback& callback) OVERRIDE { | 34 const net::CompletionCallback& callback) override { |
| 35 data_->append(buffer->data(), num_bytes); | 35 data_->append(buffer->data(), num_bytes); |
| 36 return num_bytes; | 36 return num_bytes; |
| 37 } | 37 } |
| 38 | 38 |
| 39 virtual int Finish(const net::CompletionCallback& callback) OVERRIDE { | 39 virtual int Finish(const net::CompletionCallback& callback) override { |
| 40 return net::OK; | 40 return net::OK; |
| 41 } | 41 } |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 std::string* data_; // weak reference. | 44 std::string* data_; // weak reference. |
| 45 | 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(UnownedStringWriter); | 46 DISALLOW_COPY_AND_ASSIGN(UnownedStringWriter); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 Request* request = new Request(key, fetcher.Pass(), downloaded); | 102 Request* request = new Request(key, fetcher.Pass(), downloaded); |
| 103 request->fetcher->SaveResponseWithWriter( | 103 request->fetcher->SaveResponseWithWriter( |
| 104 scoped_ptr<net::URLFetcherResponseWriter>( | 104 scoped_ptr<net::URLFetcherResponseWriter>( |
| 105 new UnownedStringWriter(&request->data))); | 105 new UnownedStringWriter(&request->data))); |
| 106 requests_[request->fetcher.get()] = request; | 106 requests_[request->fetcher.get()] = request; |
| 107 request->fetcher->Start(); | 107 request->fetcher->Start(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace autofill | 110 } // namespace autofill |
| OLD | NEW |