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

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

Issue 140743012: Start EmbeddedWorker during registration - take 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up existing registration case Created 6 years, 10 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 | Annotate | Revision Log
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_REGISTER_JOB_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "content/browser/service_worker/service_worker_registration_status.h" 11 #include "content/browser/service_worker/service_worker_registration_status.h"
12 #include "content/browser/service_worker/service_worker_storage.h" 12 #include "content/browser/service_worker/service_worker_storage.h"
13 #include "content/browser/service_worker/service_worker_version.h"
13 14
14 namespace content { 15 namespace content {
15 16
17 class EmbeddedWorkerRegistry;
16 class ServiceWorkerJobCoordinator; 18 class ServiceWorkerJobCoordinator;
17 19
18 // A ServiceWorkerRegisterJob lives only for the lifetime of a single 20 // A ServiceWorkerRegisterJob lives only for the lifetime of a single
19 // registration or unregistration. 21 // registration or unregistration.
20 class ServiceWorkerRegisterJob { 22 class ServiceWorkerRegisterJob {
21 public: 23 public:
22 enum RegistrationType { 24 enum RegistrationType {
23 REGISTER, 25 REGISTER,
24 UNREGISTER, 26 UNREGISTER,
25 }; 27 };
26 28
27 typedef base::Callback<void(ServiceWorkerStatusCode status, 29 typedef base::Callback<void(ServiceWorkerStatusCode status,
28 const scoped_refptr<ServiceWorkerRegistration>& 30 const scoped_refptr<ServiceWorkerRegistration>&
29 registration)> RegistrationCallback; 31 registration)> RegistrationCallback;
30 typedef base::Callback<void(ServiceWorkerStatusCode status)> 32 typedef base::Callback<void(ServiceWorkerStatusCode status)>
31 UnregistrationCallback; 33 UnregistrationCallback;
34 // TODO(alecflett): Unify this with RegistrationCallback
35 typedef base::Callback<
36 void(const scoped_refptr<ServiceWorkerRegistration>& registration,
37 ServiceWorkerStatusCode status)> StatusCallback;
32 38
33 // All type of jobs (Register and Unregister) complete through a 39 // All type of jobs (Register and Unregister) complete through a
34 // single call to this callback on the IO thread. 40 // single call to this callback on the IO thread.
35 ServiceWorkerRegisterJob(ServiceWorkerStorage* storage, 41 ServiceWorkerRegisterJob(ServiceWorkerStorage* storage,
42 EmbeddedWorkerRegistry* worker_registry,
36 ServiceWorkerJobCoordinator* coordinator, 43 ServiceWorkerJobCoordinator* coordinator,
37 const GURL& pattern, 44 const GURL& pattern,
38 const GURL& script_url, 45 const GURL& script_url,
39 RegistrationType type); 46 RegistrationType type);
40 ~ServiceWorkerRegisterJob(); 47 ~ServiceWorkerRegisterJob();
41 48
42 void AddCallback(const RegistrationCallback& callback); 49 void AddCallback(const RegistrationCallback& callback, int process_id);
43 50
44 void Start(); 51 void Start();
45 52
46 bool Equals(ServiceWorkerRegisterJob* job); 53 bool Equals(ServiceWorkerRegisterJob* job);
47 54
48 private: 55 private:
49 // The Registration flow includes most or all of the following, 56 // The Registration flow includes most or all of the following,
50 // depending on what is already registered: 57 // depending on what is already registered:
51 // - creating a ServiceWorkerRegistration instance if there isn't 58 // - creating a ServiceWorkerRegistration instance if there isn't
52 // already something registered 59 // already something registered
(...skipping 17 matching lines...) Expand all
70 void RegisterPatternAndContinue( 77 void RegisterPatternAndContinue(
71 const RegistrationCallback& callback, 78 const RegistrationCallback& callback,
72 ServiceWorkerStatusCode previous_status); 79 ServiceWorkerStatusCode previous_status);
73 80
74 void UnregisterPatternAndContinue( 81 void UnregisterPatternAndContinue(
75 const UnregistrationCallback& callback, 82 const UnregistrationCallback& callback,
76 bool found, 83 bool found,
77 ServiceWorkerStatusCode previous_status, 84 ServiceWorkerStatusCode previous_status,
78 const scoped_refptr<ServiceWorkerRegistration>& previous_registration); 85 const scoped_refptr<ServiceWorkerRegistration>& previous_registration);
79 86
87 void StartWorkerAndContinue(
88 const StatusCallback& callback,
89 ServiceWorkerStatusCode status,
90 const scoped_refptr<ServiceWorkerRegistration>& registration);
91
80 // These methods are the last internal callback in the callback 92 // These methods are the last internal callback in the callback
81 // chain, and ultimately call callback_. 93 // chain, and ultimately call callback_.
82 void UnregisterComplete(ServiceWorkerStatusCode status); 94 void UnregisterComplete(ServiceWorkerStatusCode status);
83 void RegisterComplete( 95 void RegisterComplete(
84 ServiceWorkerStatusCode status, 96 const scoped_refptr<ServiceWorkerRegistration>& registration,
85 const scoped_refptr<ServiceWorkerRegistration>& registration); 97 ServiceWorkerStatusCode start_status);
86 98
87 void RunCallbacks( 99 void RunCallbacks(
88 ServiceWorkerStatusCode status, 100 ServiceWorkerStatusCode status,
89 const scoped_refptr<ServiceWorkerRegistration>& registration); 101 const scoped_refptr<ServiceWorkerRegistration>& registration);
90 102
91 // The ServiceWorkerStorage object should always outlive 103 // The ServiceWorkerStorage object should always outlive
92 // this. 104 // this.
93 105
94 // TODO(alecflett) When we support job cancelling, if we are keeping 106 // TODO(alecflett) When we support job cancelling, if we are keeping
95 // this job alive for any reason, be sure to clear this variable, 107 // this job alive for any reason, be sure to clear this variable,
96 // because we may be cancelling while there are outstanding 108 // because we may be cancelling while there are outstanding
97 // callbacks that expect access to storage_. 109 // callbacks that expect access to storage_.
98 ServiceWorkerStorage* storage_; 110 ServiceWorkerStorage* storage_;
111 EmbeddedWorkerRegistry* worker_registry_;
99 ServiceWorkerJobCoordinator* coordinator_; 112 ServiceWorkerJobCoordinator* coordinator_;
113 scoped_refptr<ServiceWorkerVersion> pending_version_;
100 const GURL pattern_; 114 const GURL pattern_;
101 const GURL script_url_; 115 const GURL script_url_;
102 const RegistrationType type_; 116 const RegistrationType type_;
103 std::vector<RegistrationCallback> callbacks_; 117 std::vector<RegistrationCallback> callbacks_;
118 std::vector<int> pending_process_ids_;
104 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; 119 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_;
105 120
106 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); 121 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob);
107 }; 122 };
108 } // namespace content 123 } // namespace content
109 124
110 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ 125 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698