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

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

Issue 126603002: Implement registration job ordering (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Eliminate running_ Created 6 years, 11 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>
9
8 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
9 #include "content/browser/service_worker/service_worker_registration_status.h" 11 #include "content/browser/service_worker/service_worker_registration_status.h"
10 #include "content/browser/service_worker/service_worker_storage.h" 12 #include "content/browser/service_worker/service_worker_storage.h"
11 13
12 namespace content { 14 namespace content {
13 15
16 class ServiceWorkerJobCoordinator;
17
14 // A ServiceWorkerRegisterJob lives only for the lifetime of a single 18 // A ServiceWorkerRegisterJob lives only for the lifetime of a single
15 // registration or unregistration. 19 // registration or unregistration.
16 class ServiceWorkerRegisterJob { 20 class ServiceWorkerRegisterJob {
17 public: 21 public:
22 enum RegistrationType {
23 REGISTER,
24 UNREGISTER,
25 };
26
18 typedef base::Callback<void(ServiceWorkerRegistrationStatus status, 27 typedef base::Callback<void(ServiceWorkerRegistrationStatus status,
19 const scoped_refptr<ServiceWorkerRegistration>& 28 const scoped_refptr<ServiceWorkerRegistration>&
20 registration)> RegistrationCallback; 29 registration)> RegistrationCallback;
21 typedef base::Callback<void(ServiceWorkerRegistrationStatus status)> 30 typedef base::Callback<void(ServiceWorkerRegistrationStatus status)>
22 UnregistrationCallback; 31 UnregistrationCallback;
23 32
24 typedef base::Callback<void(
25 ServiceWorkerRegisterJob* job,
26 ServiceWorkerRegistrationStatus status,
27 ServiceWorkerRegistration* registration)> RegistrationCompleteCallback;
28
29 // All type of jobs (Register and Unregister) complete through a 33 // All type of jobs (Register and Unregister) complete through a
30 // single call to this callback on the IO thread. 34 // single call to this callback on the IO thread.
31 ServiceWorkerRegisterJob(ServiceWorkerStorage* storage, 35 ServiceWorkerRegisterJob(ServiceWorkerStorage* storage,
32 const RegistrationCompleteCallback& callback); 36 ServiceWorkerJobCoordinator* coordinator,
37 const GURL& pattern,
38 const GURL& script_url,
39 RegistrationType type);
33 ~ServiceWorkerRegisterJob(); 40 ~ServiceWorkerRegisterJob();
34 41
42 void AddCallback(const RegistrationCallback& callback);
43
44 void Start();
45
46 const GURL& pattern() const { return pattern_; }
47 const GURL& script_url() const {
48 DCHECK(type_ == REGISTER);
49 return script_url_;
50 }
51 RegistrationType type() const { return type_; }
kinuko 2014/01/09 10:54:08 Looks like these public accessors are no longer ne
alecflett 2014/01/09 21:23:14 Done.
52
53 bool Equals(ServiceWorkerRegisterJob* job);
54
55 private:
35 // The Registration flow includes most or all of the following, 56 // The Registration flow includes most or all of the following,
36 // depending on what is already registered: 57 // depending on what is already registered:
37 // - creating a ServiceWorkerRegistration instance if there isn't 58 // - creating a ServiceWorkerRegistration instance if there isn't
38 // already something registered 59 // already something registered
39 // - creating a ServiceWorkerVersion for the new registration instance. 60 // - creating a ServiceWorkerVersion for the new registration instance.
40 // - starting a worker for the ServiceWorkerVersion 61 // - starting a worker for the ServiceWorkerVersion
41 // - telling the Version to evaluate the script 62 // - telling the Version to evaluate the script
42 // - firing the 'install' event at the ServiceWorkerVersion 63 // - firing the 'install' event at the ServiceWorkerVersion
43 // - firing the 'activate' event at the ServiceWorkerVersion 64 // - firing the 'activate' event at the ServiceWorkerVersion
44 // - Waiting for older ServiceWorkerVersions to deactivate 65 // - Waiting for older ServiceWorkerVersions to deactivate
45 // - designating the new version to be the 'active' version 66 // - designating the new version to be the 'active' version
46 // This method should be called once and only once per job. 67 // This method should be called once and only once per job.
47 void StartRegister(const GURL& pattern, const GURL& script_url); 68 void StartRegister();
48 69
49 // The Unregistration process is primarily cleanup, removing 70 // The Unregistration process is primarily cleanup, removing
50 // everything that was created during the Registration process, 71 // everything that was created during the Registration process,
51 // including the ServiceWorkerRegistration itself. 72 // including the ServiceWorkerRegistration itself.
52 // This method should be called once and only once per job. 73 // This method should be called once and only once per job.
53 void StartUnregister(const GURL& pattern); 74 void StartUnregister();
54 75
55 private:
56 // These are all steps in the registration and unregistration pipeline. 76 // These are all steps in the registration and unregistration pipeline.
57 void RegisterPatternAndContinue( 77 void RegisterPatternAndContinue(
58 const GURL& pattern,
59 const GURL& script_url,
60 const RegistrationCallback& callback, 78 const RegistrationCallback& callback,
61 ServiceWorkerRegistrationStatus previous_status); 79 ServiceWorkerRegistrationStatus previous_status);
62 80
63 void UnregisterPatternAndContinue( 81 void UnregisterPatternAndContinue(
64 const GURL& pattern,
65 const GURL& script_url,
66 const UnregistrationCallback& callback, 82 const UnregistrationCallback& callback,
67 bool found, 83 bool found,
68 ServiceWorkerRegistrationStatus previous_status, 84 ServiceWorkerRegistrationStatus previous_status,
69 const scoped_refptr<ServiceWorkerRegistration>& previous_registration); 85 const scoped_refptr<ServiceWorkerRegistration>& previous_registration);
70 86
71 // These methods are the last internal callback in the callback 87 // These methods are the last internal callback in the callback
72 // chain, and ultimately call callback_. 88 // chain, and ultimately call callback_.
73 void UnregisterComplete(ServiceWorkerRegistrationStatus status); 89 void UnregisterComplete(ServiceWorkerRegistrationStatus status);
74 void RegisterComplete( 90 void RegisterComplete(
75 ServiceWorkerRegistrationStatus status, 91 ServiceWorkerRegistrationStatus status,
76 const scoped_refptr<ServiceWorkerRegistration>& registration); 92 const scoped_refptr<ServiceWorkerRegistration>& registration);
77 93
94 void RunCallbacks(
95 ServiceWorkerRegistrationStatus status,
96 const scoped_refptr<ServiceWorkerRegistration>& registration);
97
78 // The ServiceWorkerStorage object should always outlive 98 // The ServiceWorkerStorage object should always outlive
79 // this. 99 // this.
80 100
81 // TODO(alecflett) When we support job cancelling, if we are keeping 101 // TODO(alecflett) When we support job cancelling, if we are keeping
82 // this job alive for any reason, be sure to clear this variable, 102 // this job alive for any reason, be sure to clear this variable,
83 // because we may be cancelling while there are outstanding 103 // because we may be cancelling while there are outstanding
84 // callbacks that expect access to storage_. 104 // callbacks that expect access to storage_.
85 ServiceWorkerStorage* storage_; 105 ServiceWorkerStorage* storage_;
86 const RegistrationCompleteCallback callback_; 106 ServiceWorkerJobCoordinator* coordinator_;
107 const GURL pattern_;
108 GURL script_url_; // should be unset for register case
109 std::vector<RegistrationCallback> callbacks_;
87 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_; 110 base::WeakPtrFactory<ServiceWorkerRegisterJob> weak_factory_;
111 const RegistrationType type_;
kinuko 2014/01/09 10:54:08 (While it's ok in this particular case) can you mo
alecflett 2014/01/09 21:23:14 Done.
88 112
89 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob); 113 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJob);
90 }; 114 };
91 } // namespace content 115 } // namespace content
92 116
93 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_ 117 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTER_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698