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 "content/browser/service_worker/service_worker_url_request_job.h" | 5 #include "content/browser/service_worker/service_worker_url_request_job.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "content/public/browser/blob_handle.h" | 33 #include "content/public/browser/blob_handle.h" |
34 #include "content/public/browser/resource_request_info.h" | 34 #include "content/public/browser/resource_request_info.h" |
35 #include "content/public/browser/service_worker_context.h" | 35 #include "content/public/browser/service_worker_context.h" |
36 #include "content/public/common/referrer.h" | 36 #include "content/public/common/referrer.h" |
37 #include "net/base/net_errors.h" | 37 #include "net/base/net_errors.h" |
38 #include "net/http/http_request_headers.h" | 38 #include "net/http/http_request_headers.h" |
39 #include "net/http/http_response_headers.h" | 39 #include "net/http/http_response_headers.h" |
40 #include "net/http/http_response_info.h" | 40 #include "net/http/http_response_info.h" |
41 #include "net/http/http_util.h" | 41 #include "net/http/http_util.h" |
42 #include "net/log/net_log.h" | 42 #include "net/log/net_log.h" |
| 43 #include "net/log/net_log_event_type.h" |
43 #include "storage/browser/blob/blob_data_builder.h" | 44 #include "storage/browser/blob/blob_data_builder.h" |
44 #include "storage/browser/blob/blob_data_handle.h" | 45 #include "storage/browser/blob/blob_data_handle.h" |
45 #include "storage/browser/blob/blob_storage_context.h" | 46 #include "storage/browser/blob/blob_storage_context.h" |
46 #include "ui/base/page_transition_types.h" | 47 #include "ui/base/page_transition_types.h" |
47 | 48 |
48 namespace content { | 49 namespace content { |
49 | 50 |
50 namespace { | 51 namespace { |
51 | 52 |
52 net::NetLog::EventType RequestJobResultToNetEventType( | 53 net::NetLogEventType RequestJobResultToNetEventType( |
53 ServiceWorkerMetrics::URLRequestJobResult result) { | 54 ServiceWorkerMetrics::URLRequestJobResult result) { |
54 using n = net::NetLog; | 55 using n = net::NetLogEventType; |
55 using m = ServiceWorkerMetrics; | 56 using m = ServiceWorkerMetrics; |
56 switch (result) { | 57 switch (result) { |
57 case m::REQUEST_JOB_FALLBACK_RESPONSE: | 58 case m::REQUEST_JOB_FALLBACK_RESPONSE: |
58 return n::TYPE_SERVICE_WORKER_FALLBACK_RESPONSE; | 59 return n::SERVICE_WORKER_FALLBACK_RESPONSE; |
59 case m::REQUEST_JOB_FALLBACK_FOR_CORS: | 60 case m::REQUEST_JOB_FALLBACK_FOR_CORS: |
60 return n::TYPE_SERVICE_WORKER_FALLBACK_FOR_CORS; | 61 return n::SERVICE_WORKER_FALLBACK_FOR_CORS; |
61 case m::REQUEST_JOB_HEADERS_ONLY_RESPONSE: | 62 case m::REQUEST_JOB_HEADERS_ONLY_RESPONSE: |
62 return n::TYPE_SERVICE_WORKER_HEADERS_ONLY_RESPONSE; | 63 return n::SERVICE_WORKER_HEADERS_ONLY_RESPONSE; |
63 case m::REQUEST_JOB_STREAM_RESPONSE: | 64 case m::REQUEST_JOB_STREAM_RESPONSE: |
64 return n::TYPE_SERVICE_WORKER_STREAM_RESPONSE; | 65 return n::SERVICE_WORKER_STREAM_RESPONSE; |
65 case m::REQUEST_JOB_BLOB_RESPONSE: | 66 case m::REQUEST_JOB_BLOB_RESPONSE: |
66 return n::TYPE_SERVICE_WORKER_BLOB_RESPONSE; | 67 return n::SERVICE_WORKER_BLOB_RESPONSE; |
67 case m::REQUEST_JOB_ERROR_RESPONSE_STATUS_ZERO: | 68 case m::REQUEST_JOB_ERROR_RESPONSE_STATUS_ZERO: |
68 return n::TYPE_SERVICE_WORKER_ERROR_RESPONSE_STATUS_ZERO; | 69 return n::SERVICE_WORKER_ERROR_RESPONSE_STATUS_ZERO; |
69 case m::REQUEST_JOB_ERROR_BAD_BLOB: | 70 case m::REQUEST_JOB_ERROR_BAD_BLOB: |
70 return n::TYPE_SERVICE_WORKER_ERROR_BAD_BLOB; | 71 return n::SERVICE_WORKER_ERROR_BAD_BLOB; |
71 case m::REQUEST_JOB_ERROR_NO_PROVIDER_HOST: | 72 case m::REQUEST_JOB_ERROR_NO_PROVIDER_HOST: |
72 return n::TYPE_SERVICE_WORKER_ERROR_NO_PROVIDER_HOST; | 73 return n::SERVICE_WORKER_ERROR_NO_PROVIDER_HOST; |
73 case m::REQUEST_JOB_ERROR_NO_ACTIVE_VERSION: | 74 case m::REQUEST_JOB_ERROR_NO_ACTIVE_VERSION: |
74 return n::TYPE_SERVICE_WORKER_ERROR_NO_ACTIVE_VERSION; | 75 return n::SERVICE_WORKER_ERROR_NO_ACTIVE_VERSION; |
75 case m::REQUEST_JOB_ERROR_FETCH_EVENT_DISPATCH: | 76 case m::REQUEST_JOB_ERROR_FETCH_EVENT_DISPATCH: |
76 return n::TYPE_SERVICE_WORKER_ERROR_FETCH_EVENT_DISPATCH; | 77 return n::SERVICE_WORKER_ERROR_FETCH_EVENT_DISPATCH; |
77 case m::REQUEST_JOB_ERROR_BLOB_READ: | 78 case m::REQUEST_JOB_ERROR_BLOB_READ: |
78 return n::TYPE_SERVICE_WORKER_ERROR_BLOB_READ; | 79 return n::SERVICE_WORKER_ERROR_BLOB_READ; |
79 case m::REQUEST_JOB_ERROR_STREAM_ABORTED: | 80 case m::REQUEST_JOB_ERROR_STREAM_ABORTED: |
80 return n::TYPE_SERVICE_WORKER_ERROR_STREAM_ABORTED; | 81 return n::SERVICE_WORKER_ERROR_STREAM_ABORTED; |
81 case m::REQUEST_JOB_ERROR_KILLED: | 82 case m::REQUEST_JOB_ERROR_KILLED: |
82 return n::TYPE_SERVICE_WORKER_ERROR_KILLED; | 83 return n::SERVICE_WORKER_ERROR_KILLED; |
83 case m::REQUEST_JOB_ERROR_KILLED_WITH_BLOB: | 84 case m::REQUEST_JOB_ERROR_KILLED_WITH_BLOB: |
84 return n::TYPE_SERVICE_WORKER_ERROR_KILLED_WITH_BLOB; | 85 return n::SERVICE_WORKER_ERROR_KILLED_WITH_BLOB; |
85 case m::REQUEST_JOB_ERROR_KILLED_WITH_STREAM: | 86 case m::REQUEST_JOB_ERROR_KILLED_WITH_STREAM: |
86 return n::TYPE_SERVICE_WORKER_ERROR_KILLED_WITH_STREAM; | 87 return n::SERVICE_WORKER_ERROR_KILLED_WITH_STREAM; |
87 case m::REQUEST_JOB_ERROR_BAD_DELEGATE: | 88 case m::REQUEST_JOB_ERROR_BAD_DELEGATE: |
88 return n::TYPE_SERVICE_WORKER_ERROR_BAD_DELEGATE; | 89 return n::SERVICE_WORKER_ERROR_BAD_DELEGATE; |
89 case m::REQUEST_JOB_ERROR_REQUEST_BODY_BLOB_FAILED: | 90 case m::REQUEST_JOB_ERROR_REQUEST_BODY_BLOB_FAILED: |
90 return n::TYPE_SERVICE_WORKER_ERROR_REQUEST_BODY_BLOB_FAILED; | 91 return n::SERVICE_WORKER_ERROR_REQUEST_BODY_BLOB_FAILED; |
91 // We can't log if there's no request; fallthrough. | 92 // We can't log if there's no request; fallthrough. |
92 case m::REQUEST_JOB_ERROR_NO_REQUEST: | 93 case m::REQUEST_JOB_ERROR_NO_REQUEST: |
93 // Obsolete types; fallthrough. | 94 // Obsolete types; fallthrough. |
94 case m::REQUEST_JOB_ERROR_DESTROYED: | 95 case m::REQUEST_JOB_ERROR_DESTROYED: |
95 case m::REQUEST_JOB_ERROR_DESTROYED_WITH_BLOB: | 96 case m::REQUEST_JOB_ERROR_DESTROYED_WITH_BLOB: |
96 case m::REQUEST_JOB_ERROR_DESTROYED_WITH_STREAM: | 97 case m::REQUEST_JOB_ERROR_DESTROYED_WITH_STREAM: |
97 // Invalid type. | 98 // Invalid type. |
98 case m::NUM_REQUEST_JOB_RESULT_TYPES: | 99 case m::NUM_REQUEST_JOB_RESULT_TYPES: |
99 NOTREACHED() << result; | 100 NOTREACHED() << result; |
100 } | 101 } |
101 NOTREACHED() << result; | 102 NOTREACHED() << result; |
102 return n::TYPE_FAILED; | 103 return n::FAILED; |
103 } | 104 } |
104 | 105 |
105 } // namespace | 106 } // namespace |
106 | 107 |
107 class ServiceWorkerURLRequestJob::BlobConstructionWaiter { | 108 class ServiceWorkerURLRequestJob::BlobConstructionWaiter { |
108 public: | 109 public: |
109 explicit BlobConstructionWaiter(ServiceWorkerURLRequestJob* owner) | 110 explicit BlobConstructionWaiter(ServiceWorkerURLRequestJob* owner) |
110 : owner_(owner), weak_factory_(this) { | 111 : owner_(owner), weak_factory_(this) { |
111 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", "BlobConstructionWaiter", this, | 112 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", "BlobConstructionWaiter", this, |
112 "URL", owner_->request()->url().spec()); | 113 "URL", owner_->request()->url().spec()); |
113 owner_->request()->net_log().BeginEvent( | 114 owner_->request()->net_log().BeginEvent( |
114 net::NetLog::TYPE_SERVICE_WORKER_WAITING_FOR_REQUEST_BODY_BLOB); | 115 net::NetLogEventType::SERVICE_WORKER_WAITING_FOR_REQUEST_BODY_BLOB); |
115 } | 116 } |
116 | 117 |
117 ~BlobConstructionWaiter() { | 118 ~BlobConstructionWaiter() { |
118 owner_->request()->net_log().EndEvent( | 119 owner_->request()->net_log().EndEvent( |
119 net::NetLog::TYPE_SERVICE_WORKER_WAITING_FOR_REQUEST_BODY_BLOB, | 120 net::NetLogEventType::SERVICE_WORKER_WAITING_FOR_REQUEST_BODY_BLOB, |
120 net::NetLog::BoolCallback("success", phase_ == Phase::SUCCESS)); | 121 net::NetLog::BoolCallback("success", phase_ == Phase::SUCCESS)); |
121 TRACE_EVENT_ASYNC_END1("ServiceWorker", "BlobConstructionWaiter", this, | 122 TRACE_EVENT_ASYNC_END1("ServiceWorker", "BlobConstructionWaiter", this, |
122 "Success", phase_ == Phase::SUCCESS); | 123 "Success", phase_ == Phase::SUCCESS); |
123 } | 124 } |
124 | 125 |
125 void RunOnComplete(const base::Callback<void(bool)>& callback) { | 126 void RunOnComplete(const base::Callback<void(bool)>& callback) { |
126 DCHECK_EQ(static_cast<int>(Phase::INITIAL), static_cast<int>(phase_)); | 127 DCHECK_EQ(static_cast<int>(Phase::INITIAL), static_cast<int>(phase_)); |
127 phase_ = Phase::WAITING; | 128 phase_ = Phase::WAITING; |
128 num_pending_request_body_blobs_ = 0; | 129 num_pending_request_body_blobs_ = 0; |
129 callback_ = callback; | 130 callback_ = callback; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 void ServiceWorkerURLRequestJob::MaybeStartRequest() { | 386 void ServiceWorkerURLRequestJob::MaybeStartRequest() { |
386 if (is_started_ && response_type_ != NOT_DETERMINED) { | 387 if (is_started_ && response_type_ != NOT_DETERMINED) { |
387 // Start asynchronously. | 388 // Start asynchronously. |
388 base::ThreadTaskRunnerHandle::Get()->PostTask( | 389 base::ThreadTaskRunnerHandle::Get()->PostTask( |
389 FROM_HERE, base::Bind(&ServiceWorkerURLRequestJob::StartRequest, | 390 FROM_HERE, base::Bind(&ServiceWorkerURLRequestJob::StartRequest, |
390 weak_factory_.GetWeakPtr())); | 391 weak_factory_.GetWeakPtr())); |
391 } | 392 } |
392 } | 393 } |
393 | 394 |
394 void ServiceWorkerURLRequestJob::StartRequest() { | 395 void ServiceWorkerURLRequestJob::StartRequest() { |
395 request()->net_log().AddEvent(net::NetLog::TYPE_SERVICE_WORKER_START_REQUEST); | 396 request()->net_log().AddEvent( |
| 397 net::NetLogEventType::SERVICE_WORKER_START_REQUEST); |
396 | 398 |
397 switch (response_type_) { | 399 switch (response_type_) { |
398 case NOT_DETERMINED: | 400 case NOT_DETERMINED: |
399 NOTREACHED(); | 401 NOTREACHED(); |
400 return; | 402 return; |
401 | 403 |
402 case FALLBACK_TO_NETWORK: | 404 case FALLBACK_TO_NETWORK: |
403 FinalizeFallbackToNetwork(); | 405 FinalizeFallbackToNetwork(); |
404 return; | 406 return; |
405 | 407 |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 CreateFetchRequest(), active_worker, resource_type_, request()->net_log(), | 889 CreateFetchRequest(), active_worker, resource_type_, request()->net_log(), |
888 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent, | 890 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent, |
889 weak_factory_.GetWeakPtr(), active_worker), | 891 weak_factory_.GetWeakPtr(), active_worker), |
890 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, | 892 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, |
891 weak_factory_.GetWeakPtr()))); | 893 weak_factory_.GetWeakPtr()))); |
892 worker_start_time_ = base::TimeTicks::Now(); | 894 worker_start_time_ = base::TimeTicks::Now(); |
893 fetch_dispatcher_->Run(); | 895 fetch_dispatcher_->Run(); |
894 } | 896 } |
895 | 897 |
896 } // namespace content | 898 } // namespace content |
OLD | NEW |