| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/guid.h" | 14 #include "base/guid.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
| 21 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "base/time/default_tick_clock.h" |
| 24 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 25 #include "content/browser/bad_message.h" | 26 #include "content/browser/bad_message.h" |
| 26 #include "content/browser/child_process_security_policy_impl.h" | 27 #include "content/browser/child_process_security_policy_impl.h" |
| 27 #include "content/browser/message_port_message_filter.h" | 28 #include "content/browser/message_port_message_filter.h" |
| 28 #include "content/browser/message_port_service.h" | 29 #include "content/browser/message_port_service.h" |
| 29 #include "content/browser/service_worker/embedded_worker_instance.h" | 30 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 30 #include "content/browser/service_worker/embedded_worker_registry.h" | 31 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 31 #include "content/browser/service_worker/embedded_worker_status.h" | 32 #include "content/browser/service_worker/embedded_worker_status.h" |
| 32 #include "content/browser/service_worker/service_worker_client_utils.h" | 33 #include "content/browser/service_worker/service_worker_client_utils.h" |
| 33 #include "content/browser/service_worker/service_worker_context_core.h" | 34 #include "content/browser/service_worker/service_worker_context_core.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 if (render_process_host->GetHandle() != base::kNullProcessHandle) { | 125 if (render_process_host->GetHandle() != base::kNullProcessHandle) { |
| 125 bad_message::ReceivedBadMessage(render_process_host, | 126 bad_message::ReceivedBadMessage(render_process_host, |
| 126 bad_message::SERVICE_WORKER_BAD_URL); | 127 bad_message::SERVICE_WORKER_BAD_URL); |
| 127 } | 128 } |
| 128 } | 129 } |
| 129 | 130 |
| 130 void ClearTick(base::TimeTicks* time) { | 131 void ClearTick(base::TimeTicks* time) { |
| 131 *time = base::TimeTicks(); | 132 *time = base::TimeTicks(); |
| 132 } | 133 } |
| 133 | 134 |
| 134 void RestartTick(base::TimeTicks* time) { | |
| 135 *time = base::TimeTicks().Now(); | |
| 136 } | |
| 137 | |
| 138 bool RequestExpired(const base::TimeTicks& expiration) { | |
| 139 if (expiration.is_null()) | |
| 140 return false; | |
| 141 return base::TimeTicks().Now() >= expiration; | |
| 142 } | |
| 143 | |
| 144 base::TimeDelta GetTickDuration(const base::TimeTicks& time) { | |
| 145 if (time.is_null()) | |
| 146 return base::TimeDelta(); | |
| 147 return base::TimeTicks().Now() - time; | |
| 148 } | |
| 149 | |
| 150 bool IsInstalled(ServiceWorkerVersion::Status status) { | 135 bool IsInstalled(ServiceWorkerVersion::Status status) { |
| 151 switch (status) { | 136 switch (status) { |
| 152 case ServiceWorkerVersion::NEW: | 137 case ServiceWorkerVersion::NEW: |
| 153 case ServiceWorkerVersion::INSTALLING: | 138 case ServiceWorkerVersion::INSTALLING: |
| 154 case ServiceWorkerVersion::REDUNDANT: | 139 case ServiceWorkerVersion::REDUNDANT: |
| 155 return false; | 140 return false; |
| 156 case ServiceWorkerVersion::INSTALLED: | 141 case ServiceWorkerVersion::INSTALLED: |
| 157 case ServiceWorkerVersion::ACTIVATING: | 142 case ServiceWorkerVersion::ACTIVATING: |
| 158 case ServiceWorkerVersion::ACTIVATED: | 143 case ServiceWorkerVersion::ACTIVATED: |
| 159 return true; | 144 return true; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 180 } |
| 196 | 181 |
| 197 } // namespace | 182 } // namespace |
| 198 | 183 |
| 199 const int ServiceWorkerVersion::kTimeoutTimerDelaySeconds = 30; | 184 const int ServiceWorkerVersion::kTimeoutTimerDelaySeconds = 30; |
| 200 const int ServiceWorkerVersion::kStartInstalledWorkerTimeoutSeconds = 60; | 185 const int ServiceWorkerVersion::kStartInstalledWorkerTimeoutSeconds = 60; |
| 201 const int ServiceWorkerVersion::kStartNewWorkerTimeoutMinutes = 5; | 186 const int ServiceWorkerVersion::kStartNewWorkerTimeoutMinutes = 5; |
| 202 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5; | 187 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5; |
| 203 const int ServiceWorkerVersion::kStopWorkerTimeoutSeconds = 5; | 188 const int ServiceWorkerVersion::kStopWorkerTimeoutSeconds = 5; |
| 204 | 189 |
| 190 void ServiceWorkerVersion::RestartTick(base::TimeTicks* time) const { |
| 191 *time = tick_clock_->NowTicks(); |
| 192 } |
| 193 |
| 194 bool ServiceWorkerVersion::RequestExpired( |
| 195 const base::TimeTicks& expiration) const { |
| 196 if (expiration.is_null()) |
| 197 return false; |
| 198 return tick_clock_->NowTicks() >= expiration; |
| 199 } |
| 200 |
| 201 base::TimeDelta ServiceWorkerVersion::GetTickDuration( |
| 202 const base::TimeTicks& time) const { |
| 203 if (time.is_null()) |
| 204 return base::TimeDelta(); |
| 205 return tick_clock_->NowTicks() - time; |
| 206 } |
| 207 |
| 205 class ServiceWorkerVersion::Metrics { | 208 class ServiceWorkerVersion::Metrics { |
| 206 public: | 209 public: |
| 207 using EventType = ServiceWorkerMetrics::EventType; | 210 using EventType = ServiceWorkerMetrics::EventType; |
| 208 explicit Metrics(ServiceWorkerVersion* owner, EventType start_worker_purpose) | 211 explicit Metrics(ServiceWorkerVersion* owner, EventType start_worker_purpose) |
| 209 : owner_(owner), start_worker_purpose_(start_worker_purpose) {} | 212 : owner_(owner), start_worker_purpose_(start_worker_purpose) {} |
| 210 ~Metrics() { | 213 ~Metrics() { |
| 211 if (owner_->should_exclude_from_uma_) | 214 if (owner_->should_exclude_from_uma_) |
| 212 return; | 215 return; |
| 213 for (const auto& ev : event_stats_) { | 216 for (const auto& ev : event_stats_) { |
| 214 ServiceWorkerMetrics::RecordEventHandledRatio( | 217 ServiceWorkerMetrics::RecordEventHandledRatio( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 260 |
| 258 void OnPongReceived() { ClearTick(&ping_time_); } | 261 void OnPongReceived() { ClearTick(&ping_time_); } |
| 259 | 262 |
| 260 bool IsTimedOut() { return ping_state_ == PING_TIMED_OUT; } | 263 bool IsTimedOut() { return ping_state_ == PING_TIMED_OUT; } |
| 261 | 264 |
| 262 // Checks ping status. This is supposed to be called periodically. | 265 // Checks ping status. This is supposed to be called periodically. |
| 263 // This may call: | 266 // This may call: |
| 264 // - OnPingTimeout() if the worker hasn't reponded within a certain period. | 267 // - OnPingTimeout() if the worker hasn't reponded within a certain period. |
| 265 // - PingWorker() if we're running ping timer and can send next ping. | 268 // - PingWorker() if we're running ping timer and can send next ping. |
| 266 void CheckPingStatus() { | 269 void CheckPingStatus() { |
| 267 if (GetTickDuration(ping_time_) > | 270 if (version_->GetTickDuration(ping_time_) > |
| 268 base::TimeDelta::FromSeconds(kPingTimeoutSeconds)) { | 271 base::TimeDelta::FromSeconds(kPingTimeoutSeconds)) { |
| 269 ping_state_ = PING_TIMED_OUT; | 272 ping_state_ = PING_TIMED_OUT; |
| 270 version_->OnPingTimeout(); | 273 version_->OnPingTimeout(); |
| 271 return; | 274 return; |
| 272 } | 275 } |
| 273 | 276 |
| 274 // Check if we want to send a next ping. | 277 // Check if we want to send a next ping. |
| 275 if (ping_state_ != PINGING || !ping_time_.is_null()) | 278 if (ping_state_ != PINGING || !ping_time_.is_null()) |
| 276 return; | 279 return; |
| 277 | 280 |
| 278 if (version_->PingWorker() != SERVICE_WORKER_OK) { | 281 if (version_->PingWorker() != SERVICE_WORKER_OK) { |
| 279 // TODO(falken): Maybe try resending Ping a few times first? | 282 // TODO(falken): Maybe try resending Ping a few times first? |
| 280 ping_state_ = PING_TIMED_OUT; | 283 ping_state_ = PING_TIMED_OUT; |
| 281 version_->OnPingTimeout(); | 284 version_->OnPingTimeout(); |
| 282 return; | 285 return; |
| 283 } | 286 } |
| 284 RestartTick(&ping_time_); | 287 version_->RestartTick(&ping_time_); |
| 285 } | 288 } |
| 286 | 289 |
| 287 void SimulateTimeoutForTesting() { | 290 void SimulateTimeoutForTesting() { |
| 288 version_->PingWorker(); | 291 version_->PingWorker(); |
| 289 ping_state_ = PING_TIMED_OUT; | 292 ping_state_ = PING_TIMED_OUT; |
| 290 version_->OnPingTimeout(); | 293 version_->OnPingTimeout(); |
| 291 } | 294 } |
| 292 | 295 |
| 293 private: | 296 private: |
| 294 enum PingState { NOT_PINGING, PINGING, PING_TIMED_OUT }; | 297 enum PingState { NOT_PINGING, PINGING, PING_TIMED_OUT }; |
| 295 ServiceWorkerVersion* version_; // Not owned. | 298 ServiceWorkerVersion* version_; // Not owned. |
| 296 base::TimeTicks ping_time_; | 299 base::TimeTicks ping_time_; |
| 297 PingState ping_state_ = NOT_PINGING; | 300 PingState ping_state_ = NOT_PINGING; |
| 298 DISALLOW_COPY_AND_ASSIGN(PingController); | 301 DISALLOW_COPY_AND_ASSIGN(PingController); |
| 299 }; | 302 }; |
| 300 | 303 |
| 301 ServiceWorkerVersion::ServiceWorkerVersion( | 304 ServiceWorkerVersion::ServiceWorkerVersion( |
| 302 ServiceWorkerRegistration* registration, | 305 ServiceWorkerRegistration* registration, |
| 303 const GURL& script_url, | 306 const GURL& script_url, |
| 304 int64_t version_id, | 307 int64_t version_id, |
| 305 base::WeakPtr<ServiceWorkerContextCore> context) | 308 base::WeakPtr<ServiceWorkerContextCore> context) |
| 306 : version_id_(version_id), | 309 : version_id_(version_id), |
| 307 registration_id_(registration->id()), | 310 registration_id_(registration->id()), |
| 308 script_url_(script_url), | 311 script_url_(script_url), |
| 309 scope_(registration->pattern()), | 312 scope_(registration->pattern()), |
| 310 fetch_handler_existence_(FetchHandlerExistence::UNKNOWN), | 313 fetch_handler_existence_(FetchHandlerExistence::UNKNOWN), |
| 311 site_for_uma_(ServiceWorkerMetrics::SiteFromURL(scope_)), | 314 site_for_uma_(ServiceWorkerMetrics::SiteFromURL(scope_)), |
| 312 context_(context), | 315 context_(context), |
| 313 script_cache_map_(this, context), | 316 script_cache_map_(this, context), |
| 317 tick_clock_(base::WrapUnique(new base::DefaultTickClock)), |
| 314 ping_controller_(new PingController(this)), | 318 ping_controller_(new PingController(this)), |
| 315 should_exclude_from_uma_( | 319 should_exclude_from_uma_( |
| 316 ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(site_for_uma_)), | 320 ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(site_for_uma_)), |
| 317 weak_factory_(this) { | 321 weak_factory_(this) { |
| 318 DCHECK_NE(kInvalidServiceWorkerVersionId, version_id); | 322 DCHECK_NE(kInvalidServiceWorkerVersionId, version_id); |
| 319 DCHECK(context_); | 323 DCHECK(context_); |
| 320 DCHECK(registration); | 324 DCHECK(registration); |
| 321 DCHECK(script_url_.is_valid()); | 325 DCHECK(script_url_.is_valid()); |
| 322 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); | 326 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); |
| 323 embedded_worker_->AddListener(this); | 327 embedded_worker_->AddListener(this); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status()) | 557 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status()) |
| 554 << "Can only start a request with a running worker."; | 558 << "Can only start a request with a running worker."; |
| 555 DCHECK(event_type == ServiceWorkerMetrics::EventType::INSTALL || | 559 DCHECK(event_type == ServiceWorkerMetrics::EventType::INSTALL || |
| 556 event_type == ServiceWorkerMetrics::EventType::ACTIVATE || | 560 event_type == ServiceWorkerMetrics::EventType::ACTIVATE || |
| 557 event_type == ServiceWorkerMetrics::EventType::MESSAGE || | 561 event_type == ServiceWorkerMetrics::EventType::MESSAGE || |
| 558 status() == ACTIVATED) | 562 status() == ACTIVATED) |
| 559 << "Event of type " << static_cast<int>(event_type) | 563 << "Event of type " << static_cast<int>(event_type) |
| 560 << " can only be dispatched to an active worker: " << status(); | 564 << " can only be dispatched to an active worker: " << status(); |
| 561 | 565 |
| 562 int request_id = pending_requests_.Add(base::MakeUnique<PendingRequest>( | 566 int request_id = pending_requests_.Add(base::MakeUnique<PendingRequest>( |
| 563 error_callback, base::Time::Now(), base::TimeTicks::Now(), event_type)); | 567 error_callback, base::Time::Now(), tick_clock_->NowTicks(), event_type)); |
| 564 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", "ServiceWorkerVersion::Request", | 568 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", "ServiceWorkerVersion::Request", |
| 565 pending_requests_.Lookup(request_id), "Request id", | 569 pending_requests_.Lookup(request_id), "Request id", |
| 566 request_id, "Event type", | 570 request_id, "Event type", |
| 567 ServiceWorkerMetrics::EventTypeToString(event_type)); | 571 ServiceWorkerMetrics::EventTypeToString(event_type)); |
| 568 base::TimeTicks expiration_time = base::TimeTicks::Now() + timeout; | 572 base::TimeTicks expiration_time = tick_clock_->NowTicks() + timeout; |
| 569 timeout_queue_.push( | 573 timeout_queue_.push( |
| 570 RequestInfo(request_id, event_type, expiration_time, timeout_behavior)); | 574 RequestInfo(request_id, event_type, expiration_time, timeout_behavior)); |
| 571 return request_id; | 575 return request_id; |
| 572 } | 576 } |
| 573 | 577 |
| 574 bool ServiceWorkerVersion::StartExternalRequest( | 578 bool ServiceWorkerVersion::StartExternalRequest( |
| 575 const std::string& request_uuid) { | 579 const std::string& request_uuid) { |
| 576 // It's possible that the renderer is lying or the version started stopping | 580 // It's possible that the renderer is lying or the version started stopping |
| 577 // right around the time of the IPC. | 581 // right around the time of the IPC. |
| 578 if (running_status() != EmbeddedWorkerStatus::RUNNING) | 582 if (running_status() != EmbeddedWorkerStatus::RUNNING) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 591 | 595 |
| 592 bool ServiceWorkerVersion::FinishRequest(int request_id, | 596 bool ServiceWorkerVersion::FinishRequest(int request_id, |
| 593 bool was_handled, | 597 bool was_handled, |
| 594 base::Time dispatch_event_time) { | 598 base::Time dispatch_event_time) { |
| 595 PendingRequest* request = pending_requests_.Lookup(request_id); | 599 PendingRequest* request = pending_requests_.Lookup(request_id); |
| 596 if (!request) | 600 if (!request) |
| 597 return false; | 601 return false; |
| 598 // TODO(kinuko): Record other event statuses too. | 602 // TODO(kinuko): Record other event statuses too. |
| 599 metrics_->RecordEventHandledStatus(request->event_type, was_handled); | 603 metrics_->RecordEventHandledStatus(request->event_type, was_handled); |
| 600 ServiceWorkerMetrics::RecordEventDuration( | 604 ServiceWorkerMetrics::RecordEventDuration( |
| 601 request->event_type, base::TimeTicks::Now() - request->start_time_ticks, | 605 request->event_type, tick_clock_->NowTicks() - request->start_time_ticks, |
| 602 was_handled); | 606 was_handled); |
| 603 ServiceWorkerMetrics::RecordEventDispatchingDelay( | 607 ServiceWorkerMetrics::RecordEventDispatchingDelay( |
| 604 request->event_type, dispatch_event_time - request->start_time, | 608 request->event_type, dispatch_event_time - request->start_time, |
| 605 site_for_uma()); | 609 site_for_uma()); |
| 606 | 610 |
| 607 RestartTick(&idle_time_); | 611 RestartTick(&idle_time_); |
| 608 TRACE_EVENT_ASYNC_END1("ServiceWorker", "ServiceWorkerVersion::Request", | 612 TRACE_EVENT_ASYNC_END1("ServiceWorker", "ServiceWorkerVersion::Request", |
| 609 request, "Handled", was_handled); | 613 request, "Handled", was_handled); |
| 610 pending_requests_.Remove(request_id); | 614 pending_requests_.Remove(request_id); |
| 611 if (!HasWork()) { | 615 if (!HasWork()) { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 // Reactivate the timer for start timeout. | 789 // Reactivate the timer for start timeout. |
| 786 DCHECK(timeout_timer_.IsRunning()); | 790 DCHECK(timeout_timer_.IsRunning()); |
| 787 DCHECK(running_status() == EmbeddedWorkerStatus::STARTING || | 791 DCHECK(running_status() == EmbeddedWorkerStatus::STARTING || |
| 788 running_status() == EmbeddedWorkerStatus::STOPPING) | 792 running_status() == EmbeddedWorkerStatus::STOPPING) |
| 789 << static_cast<int>(running_status()); | 793 << static_cast<int>(running_status()); |
| 790 RestartTick(&start_time_); | 794 RestartTick(&start_time_); |
| 791 } | 795 } |
| 792 | 796 |
| 793 // Reactivate request timeouts, setting them all to the same expiration time. | 797 // Reactivate request timeouts, setting them all to the same expiration time. |
| 794 SetAllRequestExpirations( | 798 SetAllRequestExpirations( |
| 795 base::TimeTicks::Now() + | 799 tick_clock_->NowTicks() + |
| 796 base::TimeDelta::FromMinutes(kRequestTimeoutMinutes)); | 800 base::TimeDelta::FromMinutes(kRequestTimeoutMinutes)); |
| 797 } | 801 } |
| 798 | 802 |
| 799 void ServiceWorkerVersion::SetMainScriptHttpResponseInfo( | 803 void ServiceWorkerVersion::SetMainScriptHttpResponseInfo( |
| 800 const net::HttpResponseInfo& http_info) { | 804 const net::HttpResponseInfo& http_info) { |
| 801 main_script_http_info_.reset(new net::HttpResponseInfo(http_info)); | 805 main_script_http_info_.reset(new net::HttpResponseInfo(http_info)); |
| 802 | 806 |
| 803 // Updates |origin_trial_tokens_| if it is not set yet. This happens when: | 807 // Updates |origin_trial_tokens_| if it is not set yet. This happens when: |
| 804 // 1) The worker is a new one. | 808 // 1) The worker is a new one. |
| 805 // OR | 809 // OR |
| 806 // 2) The worker is an existing one but the entry in ServiceWorkerDatabase | 810 // 2) The worker is an existing one but the entry in ServiceWorkerDatabase |
| 807 // was written by old version Chrome (< M56), so |origin_trial_tokens| | 811 // was written by old version Chrome (< M56), so |origin_trial_tokens| |
| 808 // wasn't set in the entry. | 812 // wasn't set in the entry. |
| 809 if (!origin_trial_tokens_) { | 813 if (!origin_trial_tokens_) { |
| 810 origin_trial_tokens_ = TrialTokenValidator::GetValidTokensFromHeaders( | 814 origin_trial_tokens_ = TrialTokenValidator::GetValidTokensFromHeaders( |
| 811 url::Origin(scope()), http_info.headers.get()); | 815 url::Origin(scope()), http_info.headers.get()); |
| 812 } | 816 } |
| 813 | 817 |
| 814 for (auto& observer : listeners_) | 818 for (auto& observer : listeners_) |
| 815 observer.OnMainScriptHttpResponseInfoSet(this); | 819 observer.OnMainScriptHttpResponseInfoSet(this); |
| 816 } | 820 } |
| 817 | 821 |
| 818 void ServiceWorkerVersion::SimulatePingTimeoutForTesting() { | 822 void ServiceWorkerVersion::SimulatePingTimeoutForTesting() { |
| 819 ping_controller_->SimulateTimeoutForTesting(); | 823 ping_controller_->SimulateTimeoutForTesting(); |
| 820 } | 824 } |
| 821 | 825 |
| 826 void ServiceWorkerVersion::SetTickClockForTesting( |
| 827 std::unique_ptr<base::TickClock> tick_clock) { |
| 828 tick_clock_ = std::move(tick_clock); |
| 829 } |
| 830 |
| 822 const net::HttpResponseInfo* | 831 const net::HttpResponseInfo* |
| 823 ServiceWorkerVersion::GetMainScriptHttpResponseInfo() { | 832 ServiceWorkerVersion::GetMainScriptHttpResponseInfo() { |
| 824 return main_script_http_info_.get(); | 833 return main_script_http_info_.get(); |
| 825 } | 834 } |
| 826 | 835 |
| 827 ServiceWorkerVersion::RequestInfo::RequestInfo( | 836 ServiceWorkerVersion::RequestInfo::RequestInfo( |
| 828 int id, | 837 int id, |
| 829 ServiceWorkerMetrics::EventType event_type, | 838 ServiceWorkerMetrics::EventType event_type, |
| 830 const base::TimeTicks& expiration, | 839 const base::TimeTicks& expiration, |
| 831 TimeoutBehavior timeout_behavior) | 840 TimeoutBehavior timeout_behavior) |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 request_id, "Something went wrong while trying to open the window.")); | 1151 request_id, "Something went wrong while trying to open the window.")); |
| 1143 return; | 1152 return; |
| 1144 } | 1153 } |
| 1145 | 1154 |
| 1146 embedded_worker_->SendMessage( | 1155 embedded_worker_->SendMessage( |
| 1147 ServiceWorkerMsg_OpenWindowResponse(request_id, client_info)); | 1156 ServiceWorkerMsg_OpenWindowResponse(request_id, client_info)); |
| 1148 } | 1157 } |
| 1149 | 1158 |
| 1150 void ServiceWorkerVersion::OnSetCachedMetadata(const GURL& url, | 1159 void ServiceWorkerVersion::OnSetCachedMetadata(const GURL& url, |
| 1151 const std::vector<char>& data) { | 1160 const std::vector<char>& data) { |
| 1152 int64_t callback_id = base::TimeTicks::Now().ToInternalValue(); | 1161 int64_t callback_id = tick_clock_->NowTicks().ToInternalValue(); |
| 1153 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 1162 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| 1154 "ServiceWorkerVersion::OnSetCachedMetadata", | 1163 "ServiceWorkerVersion::OnSetCachedMetadata", |
| 1155 callback_id, "URL", url.spec()); | 1164 callback_id, "URL", url.spec()); |
| 1156 script_cache_map_.WriteMetadata( | 1165 script_cache_map_.WriteMetadata( |
| 1157 url, data, base::Bind(&ServiceWorkerVersion::OnSetCachedMetadataFinished, | 1166 url, data, base::Bind(&ServiceWorkerVersion::OnSetCachedMetadataFinished, |
| 1158 weak_factory_.GetWeakPtr(), callback_id)); | 1167 weak_factory_.GetWeakPtr(), callback_id)); |
| 1159 } | 1168 } |
| 1160 | 1169 |
| 1161 void ServiceWorkerVersion::OnSetCachedMetadataFinished(int64_t callback_id, | 1170 void ServiceWorkerVersion::OnSetCachedMetadataFinished(int64_t callback_id, |
| 1162 int result) { | 1171 int result) { |
| 1163 TRACE_EVENT_ASYNC_END1("ServiceWorker", | 1172 TRACE_EVENT_ASYNC_END1("ServiceWorker", |
| 1164 "ServiceWorkerVersion::OnSetCachedMetadata", | 1173 "ServiceWorkerVersion::OnSetCachedMetadata", |
| 1165 callback_id, "result", result); | 1174 callback_id, "result", result); |
| 1166 for (auto& observer : listeners_) | 1175 for (auto& observer : listeners_) |
| 1167 observer.OnCachedMetadataUpdated(this); | 1176 observer.OnCachedMetadataUpdated(this); |
| 1168 } | 1177 } |
| 1169 | 1178 |
| 1170 void ServiceWorkerVersion::OnClearCachedMetadata(const GURL& url) { | 1179 void ServiceWorkerVersion::OnClearCachedMetadata(const GURL& url) { |
| 1171 int64_t callback_id = base::TimeTicks::Now().ToInternalValue(); | 1180 int64_t callback_id = tick_clock_->NowTicks().ToInternalValue(); |
| 1172 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 1181 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| 1173 "ServiceWorkerVersion::OnClearCachedMetadata", | 1182 "ServiceWorkerVersion::OnClearCachedMetadata", |
| 1174 callback_id, "URL", url.spec()); | 1183 callback_id, "URL", url.spec()); |
| 1175 script_cache_map_.ClearMetadata( | 1184 script_cache_map_.ClearMetadata( |
| 1176 url, base::Bind(&ServiceWorkerVersion::OnClearCachedMetadataFinished, | 1185 url, base::Bind(&ServiceWorkerVersion::OnClearCachedMetadataFinished, |
| 1177 weak_factory_.GetWeakPtr(), callback_id)); | 1186 weak_factory_.GetWeakPtr(), callback_id)); |
| 1178 } | 1187 } |
| 1179 | 1188 |
| 1180 void ServiceWorkerVersion::OnClearCachedMetadataFinished(int64_t callback_id, | 1189 void ServiceWorkerVersion::OnClearCachedMetadataFinished(int64_t callback_id, |
| 1181 int result) { | 1190 int result) { |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1850 observer.OnNoWork(this); | 1859 observer.OnNoWork(this); |
| 1851 } | 1860 } |
| 1852 } | 1861 } |
| 1853 | 1862 |
| 1854 void ServiceWorkerVersion::OnBeginEvent() { | 1863 void ServiceWorkerVersion::OnBeginEvent() { |
| 1855 if (should_exclude_from_uma_ || | 1864 if (should_exclude_from_uma_ || |
| 1856 running_status() != EmbeddedWorkerStatus::RUNNING || | 1865 running_status() != EmbeddedWorkerStatus::RUNNING || |
| 1857 idle_time_.is_null()) { | 1866 idle_time_.is_null()) { |
| 1858 return; | 1867 return; |
| 1859 } | 1868 } |
| 1860 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 1869 ServiceWorkerMetrics::RecordTimeBetweenEvents(tick_clock_->NowTicks() - |
| 1861 idle_time_); | 1870 idle_time_); |
| 1862 } | 1871 } |
| 1863 | 1872 |
| 1864 void ServiceWorkerVersion::FinishStartWorker(ServiceWorkerStatusCode status) { | 1873 void ServiceWorkerVersion::FinishStartWorker(ServiceWorkerStatusCode status) { |
| 1865 start_worker_first_purpose_ = base::nullopt; | 1874 start_worker_first_purpose_ = base::nullopt; |
| 1866 RunCallbacks(this, &start_callbacks_, status); | 1875 RunCallbacks(this, &start_callbacks_, status); |
| 1867 } | 1876 } |
| 1868 | 1877 |
| 1869 void ServiceWorkerVersion::CleanUpExternalRequest( | 1878 void ServiceWorkerVersion::CleanUpExternalRequest( |
| 1870 const std::string& request_uuid, | 1879 const std::string& request_uuid, |
| 1871 ServiceWorkerStatusCode status) { | 1880 ServiceWorkerStatusCode status) { |
| 1872 if (status == SERVICE_WORKER_OK) | 1881 if (status == SERVICE_WORKER_OK) |
| 1873 return; | 1882 return; |
| 1874 external_request_uuid_to_request_id_.erase(request_uuid); | 1883 external_request_uuid_to_request_id_.erase(request_uuid); |
| 1875 } | 1884 } |
| 1876 | 1885 |
| 1877 } // namespace content | 1886 } // namespace content |
| OLD | NEW |