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

Side by Side Diff: content/browser/service_worker/service_worker_url_request_job.cc

Issue 2039743003: Introduce ServiceWorker.ActivatedWorkerPreparationForMainFrame.Time UMA. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
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>
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/bind.h" 17 #include "base/bind.h"
18 #include "base/guid.h" 18 #include "base/guid.h"
19 #include "base/location.h" 19 #include "base/location.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
22 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/time/time.h" 23 #include "base/time/time.h"
24 #include "content/browser/resource_context_impl.h" 24 #include "content/browser/resource_context_impl.h"
25 #include "content/browser/service_worker/embedded_worker_instance.h"
25 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" 26 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
26 #include "content/browser/service_worker/service_worker_provider_host.h" 27 #include "content/browser/service_worker/service_worker_provider_host.h"
27 #include "content/browser/service_worker/service_worker_response_info.h" 28 #include "content/browser/service_worker/service_worker_response_info.h"
28 #include "content/browser/streams/stream.h" 29 #include "content/browser/streams/stream.h"
29 #include "content/browser/streams/stream_context.h" 30 #include "content/browser/streams/stream_context.h"
30 #include "content/browser/streams/stream_registry.h" 31 #include "content/browser/streams/stream_registry.h"
31 #include "content/common/resource_request_body.h" 32 #include "content/common/resource_request_body.h"
32 #include "content/common/service_worker/service_worker_types.h" 33 #include "content/common/service_worker/service_worker_types.h"
33 #include "content/common/service_worker/service_worker_utils.h" 34 #include "content/common/service_worker/service_worker_utils.h"
34 #include "content/public/browser/blob_handle.h" 35 #include "content/public/browser/blob_handle.h"
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 NOTIMPLEMENTED(); 626 NOTIMPLEMENTED();
626 } 627 }
627 } 628 }
628 629
629 request_body_blob_data_handle_ = 630 request_body_blob_data_handle_ =
630 blob_storage_context_->AddFinishedBlob(&blob_builder); 631 blob_storage_context_->AddFinishedBlob(&blob_builder);
631 *blob_uuid = uuid; 632 *blob_uuid = uuid;
632 *blob_size = total_size; 633 *blob_size = total_size;
633 } 634 }
634 635
635 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent() { 636 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent(
637 scoped_refptr<ServiceWorkerVersion> version) {
636 worker_ready_time_ = base::TimeTicks::Now(); 638 worker_ready_time_ = base::TimeTicks::Now();
637 load_timing_info_.send_start = worker_ready_time_; 639 load_timing_info_.send_start = worker_ready_time_;
640
641 // Record the time taken for the browser to find and possibly start an active
642 // worker to which to dispatch a FetchEvent for a main frame resource request.
643 // For context, a FetchEvent can only be dispatched to an ACTIVATED worker
644 // that is running (it has been successfully started). The measurements starts
645 // when the browser process receives the request. The browser then finds the
646 // worker appropriate for this request (if there is none, this metric is not
647 // recorded). If that worker is already started, the browser process can send
648 // the request to it, so the measurement ends quickly. Otherwise the browser
649 // process has to start the worker and the measurement ends when the worker is
650 // successfully started.
651 // The metric is not recorded in the following situations:
652 // 1) The worker was in state INSTALLED or ACTIVATING, and the browser had to
653 // wait for it to become ACTIVATED. This is to avoid including the time to
654 // execute the activate event handlers in the worker's script.
655 // 2) The worker was started for the fetch AND DevTools was attached during
656 // startup. This is intended to avoid including the time for debugging.
657 // 3) The request is for New Tab Page. This is because it tends to dominate
658 // the stats and makes the results largely skewed.
659 if (resource_type_ != RESOURCE_TYPE_MAIN_FRAME)
660 return;
661 if (!worker_already_activated_)
662 return;
663 if (version->skip_recording_startup_time() &&
664 initial_worker_status_ != EmbeddedWorkerStatus::RUNNING) {
665 return;
666 }
667 if (ServiceWorkerMetrics::ShouldExcludeURLFromHistogram(request()->url()))
668 return;
669 ServiceWorkerMetrics::RecordActivatedWorkerPreparationTimeForMainFrame(
670 worker_ready_time_ - request()->creation_time(), initial_worker_status_,
671 version->embedded_worker()->start_situation());
638 } 672 }
639 673
640 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent( 674 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent(
641 ServiceWorkerStatusCode status, 675 ServiceWorkerStatusCode status,
642 ServiceWorkerFetchEventResult fetch_result, 676 ServiceWorkerFetchEventResult fetch_result,
643 const ServiceWorkerResponse& response, 677 const ServiceWorkerResponse& response,
644 const scoped_refptr<ServiceWorkerVersion>& version) { 678 const scoped_refptr<ServiceWorkerVersion>& version) {
645 fetch_dispatcher_.reset(); 679 fetch_dispatcher_.reset();
646 ServiceWorkerMetrics::RecordFetchEventStatus(IsMainResourceLoad(), status); 680 ServiceWorkerMetrics::RecordFetchEventStatus(IsMainResourceLoad(), status);
647 681
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 ServiceWorkerMetrics::URLRequestJobResult result = 989 ServiceWorkerMetrics::URLRequestJobResult result =
956 ServiceWorkerMetrics::REQUEST_JOB_ERROR_BAD_DELEGATE; 990 ServiceWorkerMetrics::REQUEST_JOB_ERROR_BAD_DELEGATE;
957 ServiceWorkerVersion* active_worker = 991 ServiceWorkerVersion* active_worker =
958 delegate_->GetServiceWorkerVersion(&result); 992 delegate_->GetServiceWorkerVersion(&result);
959 if (!active_worker) { 993 if (!active_worker) {
960 RecordResult(result); 994 RecordResult(result);
961 DeliverErrorResponse(); 995 DeliverErrorResponse();
962 return; 996 return;
963 } 997 }
964 998
999 worker_already_activated_ =
1000 active_worker->status() == ServiceWorkerVersion::ACTIVATED;
1001 initial_worker_status_ = active_worker->running_status();
1002
965 DCHECK(!fetch_dispatcher_); 1003 DCHECK(!fetch_dispatcher_);
966 fetch_dispatcher_.reset(new ServiceWorkerFetchDispatcher( 1004 fetch_dispatcher_.reset(new ServiceWorkerFetchDispatcher(
967 CreateFetchRequest(), active_worker, resource_type_, 1005 CreateFetchRequest(), active_worker, resource_type_,
968 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent, 1006 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent,
969 weak_factory_.GetWeakPtr()), 1007 weak_factory_.GetWeakPtr(), active_worker),
970 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, 1008 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent,
971 weak_factory_.GetWeakPtr()))); 1009 weak_factory_.GetWeakPtr())));
972 worker_start_time_ = base::TimeTicks::Now(); 1010 worker_start_time_ = base::TimeTicks::Now();
973 fetch_dispatcher_->Run(); 1011 fetch_dispatcher_->Run();
974 } 1012 }
975 1013
976 } // namespace content 1014 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698