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

Side by Side Diff: content/browser/service_worker/service_worker_version.h

Issue 2118243002: [proof-of-concept] SW thread independent of the main thread Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 3 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 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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <functional> 10 #include <functional>
(...skipping 21 matching lines...) Expand all
32 #include "content/browser/service_worker/embedded_worker_status.h" 32 #include "content/browser/service_worker/embedded_worker_status.h"
33 #include "content/browser/service_worker/service_worker_metrics.h" 33 #include "content/browser/service_worker/service_worker_metrics.h"
34 #include "content/browser/service_worker/service_worker_script_cache_map.h" 34 #include "content/browser/service_worker/service_worker_script_cache_map.h"
35 #include "content/common/content_export.h" 35 #include "content/common/content_export.h"
36 #include "content/common/service_worker/service_worker_status_code.h" 36 #include "content/common/service_worker/service_worker_status_code.h"
37 #include "content/common/service_worker/service_worker_types.h" 37 #include "content/common/service_worker/service_worker_types.h"
38 #include "ipc/ipc_message.h" 38 #include "ipc/ipc_message.h"
39 #include "mojo/public/cpp/bindings/interface_ptr.h" 39 #include "mojo/public/cpp/bindings/interface_ptr.h"
40 #include "services/shell/public/cpp/interface_provider.h" 40 #include "services/shell/public/cpp/interface_provider.h"
41 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerEventResult.h" 41 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerEventResult.h"
42 #include "third_party/WebKit/public/platform/modules/serviceworker/service_worke r.mojom.h"
42 #include "url/gurl.h" 43 #include "url/gurl.h"
43 #include "url/origin.h" 44 #include "url/origin.h"
44 45
45 // Windows headers will redefine SendMessage. 46 // Windows headers will redefine SendMessage.
46 #ifdef SendMessage 47 #ifdef SendMessage
47 #undef SendMessage 48 #undef SendMessage
48 #endif 49 #endif
49 50
50 namespace net { 51 namespace net {
51 class HttpResponseInfo; 52 class HttpResponseInfo;
52 } 53 }
53 54
54 namespace content { 55 namespace content {
55 56
56 class EmbeddedWorkerRegistry; 57 class EmbeddedWorkerRegistry;
57 class ServiceWorkerContextCore; 58 class ServiceWorkerContextCore;
58 class ServiceWorkerProviderHost; 59 class ServiceWorkerProviderHost;
59 class ServiceWorkerRegistration; 60 class ServiceWorkerRegistration;
60 class ServiceWorkerURLRequestJob; 61 class ServiceWorkerURLRequestJob;
61 struct ServiceWorkerClientInfo; 62 struct ServiceWorkerClientInfo;
62 struct ServiceWorkerVersionInfo; 63 struct ServiceWorkerVersionInfo;
64 class IsolatedWorkerInstance;
63 65
64 // This class corresponds to a specific version of a ServiceWorker 66 // This class corresponds to a specific version of a ServiceWorker
65 // script for a given pattern. When a script is upgraded, there may be 67 // script for a given pattern. When a script is upgraded, there may be
66 // more than one ServiceWorkerVersion "running" at a time, but only 68 // more than one ServiceWorkerVersion "running" at a time, but only
67 // one of them is activated. This class connects the actual script with a 69 // one of them is activated. This class connects the actual script with a
68 // running worker. 70 // running worker.
69 class CONTENT_EXPORT ServiceWorkerVersion 71 class CONTENT_EXPORT ServiceWorkerVersion
70 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), 72 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>),
71 public EmbeddedWorkerInstance::Listener { 73 public EmbeddedWorkerInstance::Listener {
72 public: 74 public:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 132
131 ServiceWorkerVersion(ServiceWorkerRegistration* registration, 133 ServiceWorkerVersion(ServiceWorkerRegistration* registration,
132 const GURL& script_url, 134 const GURL& script_url,
133 int64_t version_id, 135 int64_t version_id,
134 base::WeakPtr<ServiceWorkerContextCore> context); 136 base::WeakPtr<ServiceWorkerContextCore> context);
135 137
136 int64_t version_id() const { return version_id_; } 138 int64_t version_id() const { return version_id_; }
137 int64_t registration_id() const { return registration_id_; } 139 int64_t registration_id() const { return registration_id_; }
138 const GURL& script_url() const { return script_url_; } 140 const GURL& script_url() const { return script_url_; }
139 const GURL& scope() const { return scope_; } 141 const GURL& scope() const { return scope_; }
140 EmbeddedWorkerStatus running_status() const { 142 EmbeddedWorkerStatus running_status() const;
141 return embedded_worker_->status();
142 }
143 ServiceWorkerVersionInfo GetInfo(); 143 ServiceWorkerVersionInfo GetInfo();
144 Status status() const { return status_; } 144 Status status() const { return status_; }
145 145
146 // This status is set to EXISTS or DOES_NOT_EXIST when the install event has 146 // This status is set to EXISTS or DOES_NOT_EXIST when the install event has
147 // been executed in a new version or when an installed version is loaded from 147 // been executed in a new version or when an installed version is loaded from
148 // the storage. When a new version is not installed yet, it is UNKNOW. 148 // the storage. When a new version is not installed yet, it is UNKNOW.
149 FetchHandlerExistence fetch_handler_existence() const { 149 FetchHandlerExistence fetch_handler_existence() const {
150 return fetch_handler_existence_; 150 return fetch_handler_existence_;
151 } 151 }
152 // This also updates |site_for_uma_| when it was Site::OTHER. 152 // This also updates |site_for_uma_| when it was Site::OTHER.
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo& http_info); 361 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo& http_info);
362 const net::HttpResponseInfo* GetMainScriptHttpResponseInfo(); 362 const net::HttpResponseInfo* GetMainScriptHttpResponseInfo();
363 363
364 // Simulate ping timeout. Should be used for tests-only. 364 // Simulate ping timeout. Should be used for tests-only.
365 void SimulatePingTimeoutForTesting(); 365 void SimulatePingTimeoutForTesting();
366 366
367 // Returns true if the service worker has work to do: it has pending 367 // Returns true if the service worker has work to do: it has pending
368 // requests, in-progress streaming URLRequestJobs, or pending start callbacks. 368 // requests, in-progress streaming URLRequestJobs, or pending start callbacks.
369 bool HasWork() const; 369 bool HasWork() const;
370 370
371 bool IsIsolatedWorker() const;
372 blink::mojom::IsolatedWorkerClientPtr& isolated_worker_ptr() {
373 return isolated_worker_client_;
374 }
375 void OnIsolatedWorkerStartFailed();
376 void OnIsolatedWorkerThreadStarted(
377 blink::mojom::IsolatedWorkerClientPtr lient);
378 void OnIsolatedWorkerScriptEvaluated();
379 void OnIsolatedWorkerStarted();
380
371 private: 381 private:
372 friend class base::RefCounted<ServiceWorkerVersion>; 382 friend class base::RefCounted<ServiceWorkerVersion>;
373 friend class ServiceWorkerMetrics; 383 friend class ServiceWorkerMetrics;
374 friend class ServiceWorkerReadFromCacheJobTest; 384 friend class ServiceWorkerReadFromCacheJobTest;
375 friend class ServiceWorkerStallInStoppingTest; 385 friend class ServiceWorkerStallInStoppingTest;
376 friend class ServiceWorkerURLRequestJobTest; 386 friend class ServiceWorkerURLRequestJobTest;
377 friend class ServiceWorkerVersionBrowserTest; 387 friend class ServiceWorkerVersionBrowserTest;
378 friend class ServiceWorkerVersionTest; 388 friend class ServiceWorkerVersionTest;
379 389
380 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, 390 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 const int64_t registration_id_; 693 const int64_t registration_id_;
684 const GURL script_url_; 694 const GURL script_url_;
685 const GURL scope_; 695 const GURL scope_;
686 std::vector<GURL> foreign_fetch_scopes_; 696 std::vector<GURL> foreign_fetch_scopes_;
687 std::vector<url::Origin> foreign_fetch_origins_; 697 std::vector<url::Origin> foreign_fetch_origins_;
688 FetchHandlerExistence fetch_handler_existence_; 698 FetchHandlerExistence fetch_handler_existence_;
689 ServiceWorkerMetrics::Site site_for_uma_; 699 ServiceWorkerMetrics::Site site_for_uma_;
690 700
691 Status status_ = NEW; 701 Status status_ = NEW;
692 std::unique_ptr<EmbeddedWorkerInstance> embedded_worker_; 702 std::unique_ptr<EmbeddedWorkerInstance> embedded_worker_;
703 std::unique_ptr<IsolatedWorkerInstance> isolated_worker_;
693 std::vector<StatusCallback> start_callbacks_; 704 std::vector<StatusCallback> start_callbacks_;
694 std::vector<StatusCallback> stop_callbacks_; 705 std::vector<StatusCallback> stop_callbacks_;
695 std::vector<base::Closure> status_change_callbacks_; 706 std::vector<base::Closure> status_change_callbacks_;
696 707
697 // Holds in-flight requests, including requests due to outstanding push, 708 // Holds in-flight requests, including requests due to outstanding push,
698 // fetch, sync, etc. events. 709 // fetch, sync, etc. events.
699 IDMap<PendingRequest, IDMapOwnPointer> pending_requests_; 710 IDMap<PendingRequest, IDMapOwnPointer> pending_requests_;
700 711
701 // Stores all open connections to mojo services. Maps the service name to 712 // Stores all open connections to mojo services. Maps the service name to
702 // the actual interface pointer. When a connection is closed it is removed 713 // the actual interface pointer. When a connection is closed it is removed
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 std::unique_ptr<PingController> ping_controller_; 764 std::unique_ptr<PingController> ping_controller_;
754 std::unique_ptr<Metrics> metrics_; 765 std::unique_ptr<Metrics> metrics_;
755 const bool should_exclude_from_uma_ = false; 766 const bool should_exclude_from_uma_ = false;
756 767
757 bool stop_when_devtools_detached_ = false; 768 bool stop_when_devtools_detached_ = false;
758 769
759 // Keeps the first purpose of starting the worker for UMA. Cleared in 770 // Keeps the first purpose of starting the worker for UMA. Cleared in
760 // FinishStartWorker(). 771 // FinishStartWorker().
761 base::Optional<ServiceWorkerMetrics::EventType> start_worker_first_purpose_; 772 base::Optional<ServiceWorkerMetrics::EventType> start_worker_first_purpose_;
762 773
774 blink::mojom::IsolatedWorkerClientPtr isolated_worker_client_;
763 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; 775 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_;
764 776
765 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); 777 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion);
766 }; 778 };
767 779
768 template <typename Interface> 780 template <typename Interface>
769 base::WeakPtr<Interface> ServiceWorkerVersion::GetMojoServiceForRequest( 781 base::WeakPtr<Interface> ServiceWorkerVersion::GetMojoServiceForRequest(
770 int request_id) { 782 int request_id) {
771 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status()); 783 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status());
772 PendingRequest* request = pending_requests_.Lookup(request_id); 784 PendingRequest* request = pending_requests_.Lookup(request_id);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 848
837 // At this point |this| can have been deleted, so don't do anything other 849 // At this point |this| can have been deleted, so don't do anything other
838 // than returning. 850 // than returning.
839 851
840 return true; 852 return true;
841 } 853 }
842 854
843 } // namespace content 855 } // namespace content
844 856
845 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 857 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698