| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/url_request/test_url_fetcher_factory.h" | 5 #include "net/url_request/test_url_fetcher_factory.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 11 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 12 #include "base/location.h" | 13 #include "base/location.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 16 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 17 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 173 |
| 173 void TestURLFetcher::SaveResponseWithWriter( | 174 void TestURLFetcher::SaveResponseWithWriter( |
| 174 scoped_ptr<URLFetcherResponseWriter> response_writer) { | 175 scoped_ptr<URLFetcherResponseWriter> response_writer) { |
| 175 // In class URLFetcherCore this method is called by all three: | 176 // In class URLFetcherCore this method is called by all three: |
| 176 // GetResponseAsString() / SaveResponseToFileAtPath() / | 177 // GetResponseAsString() / SaveResponseToFileAtPath() / |
| 177 // SaveResponseToTemporaryFile(). But here (in TestURLFetcher), this method | 178 // SaveResponseToTemporaryFile(). But here (in TestURLFetcher), this method |
| 178 // is never used by any of these three methods. So, file writing is expected | 179 // is never used by any of these three methods. So, file writing is expected |
| 179 // to be done in SaveResponseToFileAtPath(), and this method supports only | 180 // to be done in SaveResponseToFileAtPath(), and this method supports only |
| 180 // URLFetcherStringWriter (for testing of this method only). | 181 // URLFetcherStringWriter (for testing of this method only). |
| 181 if (fake_response_destination_ == STRING) { | 182 if (fake_response_destination_ == STRING) { |
| 182 response_writer_ = response_writer.Pass(); | 183 response_writer_ = std::move(response_writer); |
| 183 int response = response_writer_->Initialize(CompletionCallback()); | 184 int response = response_writer_->Initialize(CompletionCallback()); |
| 184 // The TestURLFetcher doesn't handle asynchronous writes. | 185 // The TestURLFetcher doesn't handle asynchronous writes. |
| 185 DCHECK_EQ(OK, response); | 186 DCHECK_EQ(OK, response); |
| 186 | 187 |
| 187 scoped_refptr<IOBuffer> buffer(new StringIOBuffer(fake_response_string_)); | 188 scoped_refptr<IOBuffer> buffer(new StringIOBuffer(fake_response_string_)); |
| 188 response = response_writer_->Write(buffer.get(), | 189 response = response_writer_->Write(buffer.get(), |
| 189 fake_response_string_.size(), | 190 fake_response_string_.size(), |
| 190 CompletionCallback()); | 191 CompletionCallback()); |
| 191 DCHECK_EQ(static_cast<int>(fake_response_string_.size()), response); | 192 DCHECK_EQ(static_cast<int>(fake_response_string_.size()), response); |
| 192 response = response_writer_->Finish(CompletionCallback()); | 193 response = response_writer_->Finish(CompletionCallback()); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 | 486 |
| 486 scoped_ptr<URLFetcher> URLFetcherImplFactory::CreateURLFetcher( | 487 scoped_ptr<URLFetcher> URLFetcherImplFactory::CreateURLFetcher( |
| 487 int id, | 488 int id, |
| 488 const GURL& url, | 489 const GURL& url, |
| 489 URLFetcher::RequestType request_type, | 490 URLFetcher::RequestType request_type, |
| 490 URLFetcherDelegate* d) { | 491 URLFetcherDelegate* d) { |
| 491 return scoped_ptr<URLFetcher>(new URLFetcherImpl(url, request_type, d)); | 492 return scoped_ptr<URLFetcher>(new URLFetcherImpl(url, request_type, d)); |
| 492 } | 493 } |
| 493 | 494 |
| 494 } // namespace net | 495 } // namespace net |
| OLD | NEW |