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

Side by Side Diff: net/url_request/url_request_job.cc

Issue 40138: Use FilterContext to allow filters to access URLRequestJob data... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/url_request_job.h" 5 #include "net/url_request/url_request_job.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "net/base/auth.h" 10 #include "net/base/auth.h"
11 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/url_request/url_request.h" 13 #include "net/url_request/url_request.h"
14 #include "net/url_request/url_request_job_metrics.h" 14 #include "net/url_request/url_request_job_metrics.h"
15 #include "net/url_request/url_request_job_tracker.h" 15 #include "net/url_request/url_request_job_tracker.h"
16 16
17 using base::Time; 17 using base::Time;
18 using base::TimeTicks; 18 using base::TimeTicks;
19 19
20 // Buffer size allocated when de-compressing data. 20 // Buffer size allocated when de-compressing data.
21 static const int kFilterBufSize = 32 * 1024; 21 // static
22 const int URLRequestJob::kFilterBufSize = 32 * 1024;
22 23
23 URLRequestJob::URLRequestJob(URLRequest* request) 24 URLRequestJob::URLRequestJob(URLRequest* request)
24 : request_(request), 25 : request_(request),
25 done_(false), 26 done_(false),
26 filter_needs_more_output_space_(false), 27 filter_needs_more_output_space_(false),
27 read_buffer_(NULL), 28 read_buffer_(NULL),
28 read_buffer_len_(0), 29 read_buffer_len_(0),
29 has_handled_response_(false), 30 has_handled_response_(false),
30 expected_content_size_(-1) { 31 expected_content_size_(-1) {
31 is_profiling_ = request->enable_profiling(); 32 is_profiling_ = request->enable_profiling();
(...skipping 15 matching lines...) Expand all
47 NotifyCanceled(); 48 NotifyCanceled();
48 } 49 }
49 50
50 void URLRequestJob::DetachRequest() { 51 void URLRequestJob::DetachRequest() {
51 request_ = NULL; 52 request_ = NULL;
52 } 53 }
53 54
54 void URLRequestJob::SetupFilter() { 55 void URLRequestJob::SetupFilter() {
55 std::vector<Filter::FilterType> encoding_types; 56 std::vector<Filter::FilterType> encoding_types;
56 if (GetContentEncodings(&encoding_types)) { 57 if (GetContentEncodings(&encoding_types)) {
57 filter_.reset(Filter::Factory(encoding_types, kFilterBufSize)); 58 filter_.reset(Filter::Factory(encoding_types, *this));
58 if (filter_.get()) {
59 std::string mime_type;
60 GetMimeType(&mime_type);
61 filter_->SetURL(request_->url());
62 filter_->SetMimeType(mime_type);
63 // Approximate connect time with request_time. If it is not cached, then
64 // this is a good approximation for when the first bytes went on the
65 // wire.
66 filter_->SetConnectTime(request_->response_info_.request_time,
67 request_->response_info_.was_cached);
68 }
69 } 59 }
70 } 60 }
71 61
72 void URLRequestJob::GetAuthChallengeInfo( 62 void URLRequestJob::GetAuthChallengeInfo(
73 scoped_refptr<net::AuthChallengeInfo>* auth_info) { 63 scoped_refptr<net::AuthChallengeInfo>* auth_info) {
74 // This will only be called if NeedsAuth() returns true, in which 64 // This will only be called if NeedsAuth() returns true, in which
75 // case the derived class should implement this! 65 // case the derived class should implement this!
76 NOTREACHED(); 66 NOTREACHED();
77 } 67 }
78 68
(...skipping 10 matching lines...) Expand all
89 NOTREACHED(); 79 NOTREACHED();
90 } 80 }
91 81
92 void URLRequestJob::ContinueDespiteLastError() { 82 void URLRequestJob::ContinueDespiteLastError() {
93 // Implementations should know how to recover from errors they generate. 83 // Implementations should know how to recover from errors they generate.
94 // If this code was reached, we are trying to recover from an error that 84 // If this code was reached, we are trying to recover from an error that
95 // we don't know how to recover from. 85 // we don't know how to recover from.
96 NOTREACHED(); 86 NOTREACHED();
97 } 87 }
98 88
89 bool URLRequestJob::GetURL(GURL* gurl) const {
90 if (!request_)
91 return false;
92 *gurl = request_->url();
93 return true;
94 }
95
96 base::Time URLRequestJob::GetRequestTime() const {
97 if (!request_)
98 return base::Time();
99 return request_->request_time();
100 };
101
102 bool URLRequestJob::IsCachedContent() const {
103 if (!request_)
104 return false;
105 return request_->was_cached();
106 };
107
99 // This function calls ReadData to get stream data. If a filter exists, passes 108 // This function calls ReadData to get stream data. If a filter exists, passes
100 // the data to the attached filter. Then returns the output from filter back to 109 // the data to the attached filter. Then returns the output from filter back to
101 // the caller. 110 // the caller.
102 bool URLRequestJob::Read(net::IOBuffer* buf, int buf_size, int *bytes_read) { 111 bool URLRequestJob::Read(net::IOBuffer* buf, int buf_size, int *bytes_read) {
103 bool rv = false; 112 bool rv = false;
104 113
105 DCHECK_LT(buf_size, 1000000); // sanity check 114 DCHECK_LT(buf_size, 1000000); // sanity check
106 DCHECK(buf); 115 DCHECK(buf);
107 DCHECK(bytes_read); 116 DCHECK(bytes_read);
108 117
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 return request_->status(); 513 return request_->status();
505 // If the request is gone, we must be cancelled. 514 // If the request is gone, we must be cancelled.
506 return URLRequestStatus(URLRequestStatus::CANCELED, 515 return URLRequestStatus(URLRequestStatus::CANCELED,
507 net::ERR_ABORTED); 516 net::ERR_ABORTED);
508 } 517 }
509 518
510 void URLRequestJob::SetStatus(const URLRequestStatus &status) { 519 void URLRequestJob::SetStatus(const URLRequestStatus &status) {
511 if (request_) 520 if (request_)
512 request_->set_status(status); 521 request_->set_status(status);
513 } 522 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698