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

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

Issue 1795863006: service worker: Attribute purpose to start worker attempts for UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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_fetch_dispatcher.h" 5 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
11 #include "content/browser/service_worker/service_worker_version.h" 11 #include "content/browser/service_worker/service_worker_version.h"
12 #include "content/common/service_worker/service_worker_messages.h" 12 #include "content/common/service_worker/service_worker_messages.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 namespace {
17 using EventType = ServiceWorkerMetrics::EventType;
18 EventType ResourceTypeToEventType(ResourceType resource_type) {
19 switch (resource_type) {
20 case RESOURCE_TYPE_MAIN_FRAME:
21 return EventType::FETCH_MAIN_FRAME;
22 case RESOURCE_TYPE_SUB_FRAME:
23 return EventType::FETCH_SUB_FRAME;
24 case RESOURCE_TYPE_SHARED_WORKER:
25 return EventType::FETCH_SHARED_WORKER;
26 case RESOURCE_TYPE_LAST_TYPE:
nhiroki 2016/03/15 02:18:14 Maybe RESOURCE_TYPE_SERVICE_WORKER should not reac
falken 2016/03/15 05:15:53 Done.
27 NOTREACHED();
28 default:
29 return EventType::FETCH_SUB_RESOURCE;
30 }
31 }
32 } // namespace
33
16 ServiceWorkerFetchDispatcher::ServiceWorkerFetchDispatcher( 34 ServiceWorkerFetchDispatcher::ServiceWorkerFetchDispatcher(
17 scoped_ptr<ServiceWorkerFetchRequest> request, 35 scoped_ptr<ServiceWorkerFetchRequest> request,
18 ServiceWorkerVersion* version, 36 ServiceWorkerVersion* version,
37 ResourceType resource_type,
19 const base::Closure& prepare_callback, 38 const base::Closure& prepare_callback,
20 const FetchCallback& fetch_callback) 39 const FetchCallback& fetch_callback)
21 : version_(version), 40 : version_(version),
22 prepare_callback_(prepare_callback), 41 prepare_callback_(prepare_callback),
23 fetch_callback_(fetch_callback), 42 fetch_callback_(fetch_callback),
24 request_(std::move(request)), 43 request_(std::move(request)),
44 resource_type_(resource_type),
25 weak_factory_(this) {} 45 weak_factory_(this) {}
26 46
27 ServiceWorkerFetchDispatcher::~ServiceWorkerFetchDispatcher() {} 47 ServiceWorkerFetchDispatcher::~ServiceWorkerFetchDispatcher() {}
28 48
29 void ServiceWorkerFetchDispatcher::Run() { 49 void ServiceWorkerFetchDispatcher::Run() {
30 DCHECK(version_->status() == ServiceWorkerVersion::ACTIVATING || 50 DCHECK(version_->status() == ServiceWorkerVersion::ACTIVATING ||
31 version_->status() == ServiceWorkerVersion::ACTIVATED) 51 version_->status() == ServiceWorkerVersion::ACTIVATED)
32 << version_->status(); 52 << version_->status();
33 53
34 if (version_->status() == ServiceWorkerVersion::ACTIVATING) { 54 if (version_->status() == ServiceWorkerVersion::ACTIVATING) {
35 version_->RegisterStatusChangeCallback( 55 version_->RegisterStatusChangeCallback(
36 base::Bind(&ServiceWorkerFetchDispatcher::DidWaitActivation, 56 base::Bind(&ServiceWorkerFetchDispatcher::DidWaitActivation,
37 weak_factory_.GetWeakPtr())); 57 weak_factory_.GetWeakPtr()));
38 return; 58 return;
39 } 59 }
40 DidWaitActivation(); 60 DidWaitActivation();
41 } 61 }
42 62
43 void ServiceWorkerFetchDispatcher::DidWaitActivation() { 63 void ServiceWorkerFetchDispatcher::DidWaitActivation() {
44 if (version_->status() != ServiceWorkerVersion::ACTIVATED) { 64 if (version_->status() != ServiceWorkerVersion::ACTIVATED) {
45 DCHECK_EQ(ServiceWorkerVersion::INSTALLED, version_->status()); 65 DCHECK_EQ(ServiceWorkerVersion::INSTALLED, version_->status());
46 DidFailActivation(); 66 DidFailActivation();
47 return; 67 return;
48 } 68 }
49 version_->RunAfterStartWorker( 69 version_->RunAfterStartWorker(
50 base::Bind(&ServiceWorkerFetchDispatcher::DispatchFetchEvent, 70 base::Bind(&ServiceWorkerFetchDispatcher::DispatchFetchEvent,
51 weak_factory_.GetWeakPtr()), 71 weak_factory_.GetWeakPtr()),
52 base::Bind(&ServiceWorkerFetchDispatcher::DidFail, 72 base::Bind(&ServiceWorkerFetchDispatcher::DidFail,
53 weak_factory_.GetWeakPtr())); 73 weak_factory_.GetWeakPtr()),
74 ResourceTypeToEventType(resource_type_));
54 } 75 }
55 76
56 void ServiceWorkerFetchDispatcher::DidFailActivation() { 77 void ServiceWorkerFetchDispatcher::DidFailActivation() {
57 // The previous activation seems to have failed, abort the step 78 // The previous activation seems to have failed, abort the step
58 // with activate error. (The error should be separately reported 79 // with activate error. (The error should be separately reported
59 // to the associated documents and association must be dropped 80 // to the associated documents and association must be dropped
60 // at this point) 81 // at this point)
61 DidFinish(SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED, 82 DidFinish(SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED,
62 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, 83 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK,
63 ServiceWorkerResponse()); 84 ServiceWorkerResponse());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (!version_->FinishRequest(request_id, handled)) 125 if (!version_->FinishRequest(request_id, handled))
105 NOTREACHED() << "Should only receive one reply per event"; 126 NOTREACHED() << "Should only receive one reply per event";
106 127
107 DCHECK(!fetch_callback_.is_null()); 128 DCHECK(!fetch_callback_.is_null());
108 FetchCallback fetch_callback = fetch_callback_; 129 FetchCallback fetch_callback = fetch_callback_;
109 scoped_refptr<ServiceWorkerVersion> version = version_; 130 scoped_refptr<ServiceWorkerVersion> version = version_;
110 fetch_callback.Run(SERVICE_WORKER_OK, fetch_result, response, version); 131 fetch_callback.Run(SERVICE_WORKER_OK, fetch_result, response, version);
111 } 132 }
112 133
113 } // namespace content 134 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698