Chromium Code Reviews| Index: content/browser/service_worker/service_worker_registration.h |
| diff --git a/content/browser/service_worker/service_worker_registration.h b/content/browser/service_worker/service_worker_registration.h |
| index 5b71848da6b45db88ac18fd9cfecef86b75b3a5c..7d70a7c79d79cbb6a2be32e1f84fcbc100fce6a1 100644 |
| --- a/content/browser/service_worker/service_worker_registration.h |
| +++ b/content/browser/service_worker/service_worker_registration.h |
| @@ -9,13 +9,17 @@ |
| #include <memory> |
| #include <string> |
| +#include <vector> |
| #include "base/logging.h" |
| #include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
| +#include "base/single_thread_task_runner.h" |
| +#include "base/timer/timer.h" |
| #include "content/browser/service_worker/service_worker_version.h" |
| #include "content/common/content_export.h" |
| #include "content/common/service_worker/service_worker_types.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "url/gurl.h" |
| namespace content { |
| @@ -28,8 +32,10 @@ struct ServiceWorkerRegistrationInfo; |
| // to this class. This is refcounted via ServiceWorkerRegistrationHandle to |
| // facilitate multiple controllees being associated with the same registration. |
| class CONTENT_EXPORT ServiceWorkerRegistration |
| - : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>), |
| - public ServiceWorkerVersion::Listener { |
| + : public NON_EXPORTED_BASE( |
| + base::RefCountedThreadSafe<ServiceWorkerRegistration, |
| + BrowserThread::DeleteOnIOThread>), |
| + public NON_EXPORTED_BASE(ServiceWorkerVersion::Listener) { |
| public: |
| typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; |
| @@ -71,6 +77,12 @@ class CONTENT_EXPORT ServiceWorkerRegistration |
| resources_total_size_bytes_ = resources_total_size_bytes; |
| } |
| + // Returns the active version. This version may be in ACTIVATING or ACTIVATED |
| + // state. If you require an ACTIVATED version, use |
| + // ServiceWorkerContextWrapper::FindReadyRegistration* to get a registration |
| + // with such a version. Alternatively, use |
| + // ServiceWorkerVersion::Listener::OnVersionStateChanged to wait for the |
| + // ACTIVATING version to become ACTIVATED. |
| ServiceWorkerVersion* active_version() const { |
| return active_version_.get(); |
| } |
| @@ -139,8 +151,15 @@ class CONTENT_EXPORT ServiceWorkerRegistration |
| void RegisterRegistrationFinishedCallback(const base::Closure& callback); |
| void NotifyRegistrationFinished(); |
| + void SetTimerTaskRunnerForTest( |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| + |
| private: |
| - friend class base::RefCounted<ServiceWorkerRegistration>; |
| + friend class base::RefCountedThreadSafe< |
| + ServiceWorkerRegistration, |
| + content::BrowserThread::DeleteOnIOThread>; |
| + friend class base::DeleteHelper<ServiceWorkerRegistration>; |
| + friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; |
| ~ServiceWorkerRegistration() override; |
| @@ -151,13 +170,24 @@ class CONTENT_EXPORT ServiceWorkerRegistration |
| // ServiceWorkerVersion::Listener override. |
| void OnNoControllees(ServiceWorkerVersion* version) override; |
| - // This method corresponds to the [[Activate]] algorithm. |
| - void ActivateWaitingVersion(); |
| + // Promotes the waiting version to active version. If |delay| is true, waits |
| + // a short time before attempting to start and dispatch the activate event |
| + // to the version. |
| + void ActivateWaitingVersion(bool delay); |
| + void ContinueActivation( |
| + const scoped_refptr<ServiceWorkerVersion>& activating_version); |
|
nhiroki
2016/06/01 05:51:48
[Optional] As you might already know, passing "con
falken
2016/06/01 09:20:05
I changed to use scoped_refptr and std::move when
nhiroki
2016/06/03 00:54:29
I use std::move if an object is not used anymore a
|
| void DispatchActivateEvent( |
| const scoped_refptr<ServiceWorkerVersion>& activating_version); |
| void OnActivateEventFinished( |
| const scoped_refptr<ServiceWorkerVersion>& activating_version, |
| ServiceWorkerStatusCode status); |
| + // Actually sets |activating_version| to ACTIVATED and writes to |
| + // storage that it's active. |
| + void CompleteActivation( |
| + const scoped_refptr<ServiceWorkerVersion>& activating_version, |
| + ServiceWorkerStatusCode status, |
| + bool is_shutdown); |
| + |
| void OnDeleteFinished(ServiceWorkerStatusCode status); |
| // This method corresponds to the [[ClearRegistration]] algorithm. |
| @@ -175,6 +205,7 @@ class CONTENT_EXPORT ServiceWorkerRegistration |
| bool should_activate_when_ready_; |
| base::Time last_update_check_; |
| int64_t resources_total_size_bytes_; |
| + base::OneShotTimer timer_; |
| // This registration is the primary owner of these versions. |
| scoped_refptr<ServiceWorkerVersion> active_version_; |