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

Side by Side Diff: content/test/net/url_request_slow_download_job.cc

Issue 10534100: Decouple URLRequestJob from URLRequestContext; access NetworkDelegate as a contructor parameter. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merged with latest sync Created 8 years, 5 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
« no previous file with comments | « content/test/net/url_request_failed_job.cc ('k') | net/url_request/url_request.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/test/net/url_request_slow_download_job.h" 5 #include "content/test/net/url_request_slow_download_job.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 #include "net/base/io_buffer.h" 15 #include "net/base/io_buffer.h"
16 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
17 #include "net/url_request/url_request.h" 17 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_context.h"
18 #include "net/url_request/url_request_filter.h" 19 #include "net/url_request/url_request_filter.h"
19 20
20 using content::BrowserThread; 21 using content::BrowserThread;
21 22
22 const char URLRequestSlowDownloadJob::kUnknownSizeUrl[] = 23 const char URLRequestSlowDownloadJob::kUnknownSizeUrl[] =
23 "http://url.handled.by.slow.download/download-unknown-size"; 24 "http://url.handled.by.slow.download/download-unknown-size";
24 const char URLRequestSlowDownloadJob::kKnownSizeUrl[] = 25 const char URLRequestSlowDownloadJob::kKnownSizeUrl[] =
25 "http://url.handled.by.slow.download/download-known-size"; 26 "http://url.handled.by.slow.download/download-known-size";
26 const char URLRequestSlowDownloadJob::kFinishDownloadUrl[] = 27 const char URLRequestSlowDownloadJob::kFinishDownloadUrl[] =
27 "http://url.handled.by.slow.download/download-finish"; 28 "http://url.handled.by.slow.download/download-finish";
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 void URLRequestSlowDownloadJob::FinishPendingRequests() { 73 void URLRequestSlowDownloadJob::FinishPendingRequests() {
73 typedef std::set<URLRequestSlowDownloadJob*> JobList; 74 typedef std::set<URLRequestSlowDownloadJob*> JobList;
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
75 for (JobList::iterator it = pending_requests_.Get().begin(); it != 76 for (JobList::iterator it = pending_requests_.Get().begin(); it !=
76 pending_requests_.Get().end(); ++it) { 77 pending_requests_.Get().end(); ++it) {
77 (*it)->set_should_finish_download(); 78 (*it)->set_should_finish_download();
78 } 79 }
79 } 80 }
80 81
81 URLRequestSlowDownloadJob::URLRequestSlowDownloadJob(net::URLRequest* request) 82 URLRequestSlowDownloadJob::URLRequestSlowDownloadJob(net::URLRequest* request)
82 : net::URLRequestJob(request), 83 : net::URLRequestJob(request, request->context()->network_delegate()),
83 bytes_already_sent_(0), 84 bytes_already_sent_(0),
84 should_finish_download_(false), 85 should_finish_download_(false),
85 buffer_size_(0), 86 buffer_size_(0),
86 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 87 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
87 } 88 }
88 89
89 void URLRequestSlowDownloadJob::StartAsync() { 90 void URLRequestSlowDownloadJob::StartAsync() {
90 if (LowerCaseEqualsASCII(kFinishDownloadUrl, request_->url().spec().c_str())) 91 if (LowerCaseEqualsASCII(kFinishDownloadUrl, request_->url().spec().c_str()))
91 URLRequestSlowDownloadJob::FinishPendingRequests(); 92 URLRequestSlowDownloadJob::FinishPendingRequests();
92 93
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // ParseRawHeaders expects \0 to end each header line. 234 // ParseRawHeaders expects \0 to end each header line.
234 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); 235 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1));
235 info->headers = new net::HttpResponseHeaders(raw_headers); 236 info->headers = new net::HttpResponseHeaders(raw_headers);
236 } 237 }
237 238
238 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const { 239 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const {
239 net::HttpResponseInfo info; 240 net::HttpResponseInfo info;
240 GetResponseInfoConst(&info); 241 GetResponseInfoConst(&info);
241 return info.headers && info.headers->GetMimeType(mime_type); 242 return info.headers && info.headers->GetMimeType(mime_type);
242 } 243 }
OLDNEW
« no previous file with comments | « content/test/net/url_request_failed_job.cc ('k') | net/url_request/url_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698