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 "content/browser/appcache/appcache_url_request_job.h" | 5 #include "content/browser/appcache/appcache_url_request_job.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "content/browser/appcache/appcache.h" | 18 #include "content/browser/appcache/appcache.h" |
19 #include "content/browser/appcache/appcache_group.h" | 19 #include "content/browser/appcache/appcache_group.h" |
20 #include "content/browser/appcache/appcache_histograms.h" | 20 #include "content/browser/appcache/appcache_histograms.h" |
21 #include "content/browser/appcache/appcache_host.h" | 21 #include "content/browser/appcache/appcache_host.h" |
22 #include "content/browser/appcache/appcache_service_impl.h" | 22 #include "content/browser/appcache/appcache_service_impl.h" |
23 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
25 #include "net/http/http_request_headers.h" | 25 #include "net/http/http_request_headers.h" |
26 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
27 #include "net/http/http_util.h" | 27 #include "net/http/http_util.h" |
28 #include "net/log/net_log.h" | 28 #include "net/log/net_log.h" |
| 29 #include "net/log/net_log_event_type.h" |
29 #include "net/url_request/url_request.h" | 30 #include "net/url_request/url_request.h" |
30 #include "net/url_request/url_request_status.h" | 31 #include "net/url_request/url_request_status.h" |
31 | 32 |
32 namespace content { | 33 namespace content { |
33 | 34 |
34 AppCacheURLRequestJob::AppCacheURLRequestJob( | 35 AppCacheURLRequestJob::AppCacheURLRequestJob( |
35 net::URLRequest* request, | 36 net::URLRequest* request, |
36 net::NetworkDelegate* network_delegate, | 37 net::NetworkDelegate* network_delegate, |
37 AppCacheStorage* storage, | 38 AppCacheStorage* storage, |
38 AppCacheHost* host, | 39 AppCacheHost* host, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // cause a new job to be created to retrieve the resource from the | 115 // cause a new job to be created to retrieve the resource from the |
115 // network. Our caller is responsible for arranging to not re-intercept | 116 // network. Our caller is responsible for arranging to not re-intercept |
116 // the same request. | 117 // the same request. |
117 NotifyRestartRequired(); | 118 NotifyRestartRequired(); |
118 break; | 119 break; |
119 | 120 |
120 case ERROR_DELIVERY: | 121 case ERROR_DELIVERY: |
121 AppCacheHistograms::AddErrorJobStartDelaySample( | 122 AppCacheHistograms::AddErrorJobStartDelaySample( |
122 base::TimeTicks::Now() - start_time_tick_); | 123 base::TimeTicks::Now() - start_time_tick_); |
123 request()->net_log().AddEvent( | 124 request()->net_log().AddEvent( |
124 net::NetLog::TYPE_APPCACHE_DELIVERING_ERROR_RESPONSE); | 125 net::NetLogEventType::APPCACHE_DELIVERING_ERROR_RESPONSE); |
125 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 126 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
126 net::ERR_FAILED)); | 127 net::ERR_FAILED)); |
127 break; | 128 break; |
128 | 129 |
129 case APPCACHED_DELIVERY: | 130 case APPCACHED_DELIVERY: |
130 if (entry_.IsExecutable()) { | 131 if (entry_.IsExecutable()) { |
131 BeginExecutableHandlerDelivery(); | 132 BeginExecutableHandlerDelivery(); |
132 return; | 133 return; |
133 } | 134 } |
134 AppCacheHistograms::AddAppCacheJobStartDelaySample( | 135 AppCacheHistograms::AddAppCacheJobStartDelaySample( |
135 base::TimeTicks::Now() - start_time_tick_); | 136 base::TimeTicks::Now() - start_time_tick_); |
136 request()->net_log().AddEvent( | 137 request()->net_log().AddEvent( |
137 is_fallback_ ? | 138 is_fallback_ |
138 net::NetLog::TYPE_APPCACHE_DELIVERING_FALLBACK_RESPONSE : | 139 ? net::NetLogEventType::APPCACHE_DELIVERING_FALLBACK_RESPONSE |
139 net::NetLog::TYPE_APPCACHE_DELIVERING_CACHED_RESPONSE); | 140 : net::NetLogEventType::APPCACHE_DELIVERING_CACHED_RESPONSE); |
140 storage_->LoadResponseInfo(manifest_url_, entry_.response_id(), this); | 141 storage_->LoadResponseInfo(manifest_url_, entry_.response_id(), this); |
141 break; | 142 break; |
142 | 143 |
143 default: | 144 default: |
144 NOTREACHED(); | 145 NOTREACHED(); |
145 break; | 146 break; |
146 } | 147 } |
147 } | 148 } |
148 | 149 |
149 void AppCacheURLRequestJob::BeginExecutableHandlerDelivery() { | 150 void AppCacheURLRequestJob::BeginExecutableHandlerDelivery() { |
150 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 151 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
151 kEnableExecutableHandlers)); | 152 kEnableExecutableHandlers)); |
152 if (!storage_->service()->handler_factory()) { | 153 if (!storage_->service()->handler_factory()) { |
153 BeginErrorDelivery("missing handler factory"); | 154 BeginErrorDelivery("missing handler factory"); |
154 return; | 155 return; |
155 } | 156 } |
156 | 157 |
157 request()->net_log().AddEvent( | 158 request()->net_log().AddEvent( |
158 net::NetLog::TYPE_APPCACHE_DELIVERING_EXECUTABLE_RESPONSE); | 159 net::NetLogEventType::APPCACHE_DELIVERING_EXECUTABLE_RESPONSE); |
159 | 160 |
160 // We defer job delivery until the executable handler is spun up and | 161 // We defer job delivery until the executable handler is spun up and |
161 // provides a response. The sequence goes like this... | 162 // provides a response. The sequence goes like this... |
162 // | 163 // |
163 // 1. First we load the cache. | 164 // 1. First we load the cache. |
164 // 2. Then if the handler is not spun up, we load the script resource which | 165 // 2. Then if the handler is not spun up, we load the script resource which |
165 // is needed to spin it up. | 166 // is needed to spin it up. |
166 // 3. Then we ask then we ask the handler to compute a response. | 167 // 3. Then we ask then we ask the handler to compute a response. |
167 // 4. Finally we deilver that response to the caller. | 168 // 4. Finally we deilver that response to the caller. |
168 storage_->LoadCache(cache_id_, this); | 169 storage_->LoadCache(cache_id_, this); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 if (ranges.size() == 1U) | 453 if (ranges.size() == 1U) |
453 range_requested_ = ranges[0]; | 454 range_requested_ = ranges[0]; |
454 } | 455 } |
455 | 456 |
456 void AppCacheURLRequestJob::NotifyRestartRequired() { | 457 void AppCacheURLRequestJob::NotifyRestartRequired() { |
457 on_prepare_to_restart_callback_.Run(); | 458 on_prepare_to_restart_callback_.Run(); |
458 URLRequestJob::NotifyRestartRequired(); | 459 URLRequestJob::NotifyRestartRequired(); |
459 } | 460 } |
460 | 461 |
461 } // namespace content | 462 } // namespace content |
OLD | NEW |