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

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

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

Powered by Google App Engine
This is Rietveld 408576698