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

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

Issue 380093002: Update installed ServiceWorkers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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"
(...skipping 23 matching lines...) Expand all
34 // - designating the new version to be the 'active' version 34 // - designating the new version to be the 'active' version
35 class ServiceWorkerRegisterJob 35 class ServiceWorkerRegisterJob
36 : public ServiceWorkerRegisterJobBase, 36 : public ServiceWorkerRegisterJobBase,
37 public EmbeddedWorkerInstance::Listener { 37 public EmbeddedWorkerInstance::Listener {
38 public: 38 public:
39 typedef base::Callback<void(ServiceWorkerStatusCode status, 39 typedef base::Callback<void(ServiceWorkerStatusCode status,
40 ServiceWorkerRegistration* registration, 40 ServiceWorkerRegistration* registration,
41 ServiceWorkerVersion* version)> 41 ServiceWorkerVersion* version)>
42 RegistrationCallback; 42 RegistrationCallback;
43 43
44 // For registration jobs.
44 CONTENT_EXPORT ServiceWorkerRegisterJob( 45 CONTENT_EXPORT ServiceWorkerRegisterJob(
45 base::WeakPtr<ServiceWorkerContextCore> context, 46 base::WeakPtr<ServiceWorkerContextCore> context,
46 const GURL& pattern, 47 const GURL& pattern,
47 const GURL& script_url); 48 const GURL& script_url);
49
50 // For update jobs.
51 CONTENT_EXPORT ServiceWorkerRegisterJob(
52 base::WeakPtr<ServiceWorkerContextCore> context,
53 ServiceWorkerRegistration* registration);
48 virtual ~ServiceWorkerRegisterJob(); 54 virtual ~ServiceWorkerRegisterJob();
49 55
50 // Registers a callback to be called when the promise would resolve (whether 56 // Registers a callback to be called when the promise would resolve (whether
51 // successfully or not). Multiple callbacks may be registered. If |process_id| 57 // successfully or not). Multiple callbacks may be registered. If |process_id|
52 // is not -1, it's added to the existing clients when deciding in which 58 // is not -1, it's added to the existing clients when deciding in which
53 // process to create the Service Worker instance. If there are no existing 59 // process to create the Service Worker instance. If there are no existing
54 // clients, a new RenderProcessHost will be created. 60 // clients, a new RenderProcessHost will be created.
55 void AddCallback(const RegistrationCallback& callback, int process_id); 61 void AddCallback(const RegistrationCallback& callback, int process_id);
56 62
57 // ServiceWorkerRegisterJobBase implementation: 63 // ServiceWorkerRegisterJobBase implementation:
58 virtual void Start() OVERRIDE; 64 virtual void Start() OVERRIDE;
59 virtual void Abort() OVERRIDE; 65 virtual void Abort() OVERRIDE;
60 virtual bool Equals(ServiceWorkerRegisterJobBase* job) OVERRIDE; 66 virtual bool Equals(ServiceWorkerRegisterJobBase* job) OVERRIDE;
61 virtual RegistrationJobType GetType() OVERRIDE; 67 virtual RegistrationJobType GetType() OVERRIDE;
62 68
69 // TODO(michaeln): Use the registration listerer's OnVersionAttributesChanged
70 // method to replace these methods, have the host listen for changes
71 // to their registration.
72 CONTENT_EXPORT static void AssociateInstallingVersionToDocuments(
73 base::WeakPtr<ServiceWorkerContextCore> context,
74 ServiceWorkerVersion* version);
75 static void AssociateWaitingVersionToDocuments(
76 base::WeakPtr<ServiceWorkerContextCore> context,
77 ServiceWorkerVersion* version);
78 static void AssociateActiveVersionToDocuments(
79 base::WeakPtr<ServiceWorkerContextCore> context,
80 ServiceWorkerVersion* version);
81 CONTENT_EXPORT static void DisassociateVersionFromDocuments(
82 base::WeakPtr<ServiceWorkerContextCore> context,
83 ServiceWorkerVersion* version);
84
63 private: 85 private:
64 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostWaitingVersionTest, 86 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostWaitingVersionTest,
65 AssociateInstallingVersionToDocuments); 87 AssociateInstallingVersionToDocuments);
66 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostWaitingVersionTest, 88 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProviderHostWaitingVersionTest,
67 DisassociateVersionFromDocuments); 89 DisassociateVersionFromDocuments);
68 90
69 enum Phase { 91 enum Phase {
70 INITIAL, 92 INITIAL,
71 START, 93 START,
72 REGISTER, 94 REGISTER,
(...skipping 17 matching lines...) Expand all
90 scoped_refptr<ServiceWorkerVersion> new_version; 112 scoped_refptr<ServiceWorkerVersion> new_version;
91 }; 113 };
92 114
93 void set_registration(ServiceWorkerRegistration* registration); 115 void set_registration(ServiceWorkerRegistration* registration);
94 ServiceWorkerRegistration* registration(); 116 ServiceWorkerRegistration* registration();
95 void set_new_version(ServiceWorkerVersion* version); 117 void set_new_version(ServiceWorkerVersion* version);
96 ServiceWorkerVersion* new_version(); 118 ServiceWorkerVersion* new_version();
97 119
98 void SetPhase(Phase phase); 120 void SetPhase(Phase phase);
99 121
100 void HandleExistingRegistrationAndContinue( 122 void ContinueWithRegistration(
123 ServiceWorkerStatusCode status,
124 const scoped_refptr<ServiceWorkerRegistration>& registration);
125 void ContinueWithUpdate(
101 ServiceWorkerStatusCode status, 126 ServiceWorkerStatusCode status,
102 const scoped_refptr<ServiceWorkerRegistration>& registration); 127 const scoped_refptr<ServiceWorkerRegistration>& registration);
103 void RegisterAndContinue(ServiceWorkerStatusCode status); 128 void RegisterAndContinue(ServiceWorkerStatusCode status);
104 void UpdateAndContinue(ServiceWorkerStatusCode status); 129 void UpdateAndContinue();
105 void OnStartWorkerFinished(ServiceWorkerStatusCode status); 130 void OnStartWorkerFinished(ServiceWorkerStatusCode status);
106 void OnStoreRegistrationComplete(ServiceWorkerStatusCode status); 131 void OnStoreRegistrationComplete(ServiceWorkerStatusCode status);
107 void InstallAndContinue(); 132 void InstallAndContinue();
108 void OnInstallFinished(ServiceWorkerStatusCode status); 133 void OnInstallFinished(ServiceWorkerStatusCode status);
109 void ActivateAndContinue(); 134 void ActivateAndContinue();
110 void OnActivateFinished(ServiceWorkerStatusCode status); 135 void OnActivateFinished(ServiceWorkerStatusCode status);
111 void Complete(ServiceWorkerStatusCode status); 136 void Complete(ServiceWorkerStatusCode status);
112 void CompleteInternal(ServiceWorkerStatusCode status); 137 void CompleteInternal(ServiceWorkerStatusCode status);
113
114 void ResolvePromise(ServiceWorkerStatusCode status, 138 void ResolvePromise(ServiceWorkerStatusCode status,
115 ServiceWorkerRegistration* registration, 139 ServiceWorkerRegistration* registration,
116 ServiceWorkerVersion* version); 140 ServiceWorkerVersion* version);
117 141
118 // EmbeddedWorkerInstance::Listener override of OnPausedAfterDownload. 142 // EmbeddedWorkerInstance::Listener override of OnPausedAfterDownload.
119 virtual void OnPausedAfterDownload() OVERRIDE; 143 virtual void OnPausedAfterDownload() OVERRIDE;
120 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 144 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
121 145
122 // Associates an installing version to documents matched with a scope of the 146 void OnCompareScriptResourcesComplete(
123 // version. 147 ServiceWorkerVersion* current_version,
124 CONTENT_EXPORT static void AssociateInstallingVersionToDocuments( 148 ServiceWorkerStatusCode status,
125 base::WeakPtr<ServiceWorkerContextCore> context, 149 int compare_result);
126 ServiceWorkerVersion* version);
127
128 // Associates a waiting version to documents matched with a scope of the
129 // version.
130 static void AssociateWaitingVersionToDocuments(
131 base::WeakPtr<ServiceWorkerContextCore> context,
132 ServiceWorkerVersion* version);
133
134 // Associates an active version to documents matched with a scope of the
135 // version.
136 static void AssociateActiveVersionToDocuments(
137 base::WeakPtr<ServiceWorkerContextCore> context,
138 ServiceWorkerVersion* version);
139
140 // Disassociates a version specified by |version_id| from documents.
141 CONTENT_EXPORT static void DisassociateVersionFromDocuments(
142 base::WeakPtr<ServiceWorkerContextCore> context,
143 ServiceWorkerVersion* version);
144 150
145 // The ServiceWorkerContextCore object should always outlive this. 151 // The ServiceWorkerContextCore object should always outlive this.
146 base::WeakPtr<ServiceWorkerContextCore> context_; 152 base::WeakPtr<ServiceWorkerContextCore> context_;
147 153
154 RegistrationJobType job_type_;
148 const GURL pattern_; 155 const GURL pattern_;
149 const GURL script_url_; 156 const GURL script_url_;
150 std::vector<RegistrationCallback> callbacks_; 157 std::vector<RegistrationCallback> callbacks_;
151 std::vector<int> pending_process_ids_; 158 std::vector<int> pending_process_ids_;
152 Phase phase_; 159 Phase phase_;
153 Internal internal_; 160 Internal internal_;
154 bool is_promise_resolved_; 161 bool is_promise_resolved_;
155 ServiceWorkerStatusCode promise_resolved_status_; 162 ServiceWorkerStatusCode promise_resolved_status_;
156 scoped_refptr<ServiceWorkerRegistration> promise_resolved_registration_; 163 scoped_refptr<ServiceWorkerRegistration> promise_resolved_registration_;
157 scoped_refptr<ServiceWorkerVersion> promise_resolved_version_; 164 scoped_refptr<ServiceWorkerVersion> promise_resolved_version_;
158 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; 165 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_;
159 166
160 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); 167 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob);
161 }; 168 };
162 169
163 } // namespace content 170 } // namespace content
164 171
165 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ 172 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698