| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_HANDLE_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_HANDLE_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_HANDLE_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_HANDLE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // (WebServiceWorkerImpl). | 26 // (WebServiceWorkerImpl). |
| 27 // Has references to the corresponding ServiceWorkerVersion and | 27 // Has references to the corresponding ServiceWorkerVersion and |
| 28 // ServiceWorkerRegistration (therefore they're guaranteed to be alive while | 28 // ServiceWorkerRegistration (therefore they're guaranteed to be alive while |
| 29 // this handle is around). | 29 // this handle is around). |
| 30 class CONTENT_EXPORT ServiceWorkerHandle | 30 class CONTENT_EXPORT ServiceWorkerHandle |
| 31 : NON_EXPORTED_BASE(public ServiceWorkerVersion::Listener) { | 31 : NON_EXPORTED_BASE(public ServiceWorkerVersion::Listener) { |
| 32 public: | 32 public: |
| 33 // Creates a handle for a live version. The version's corresponding | 33 // Creates a handle for a live version. The version's corresponding |
| 34 // registration must be also alive. | 34 // registration must be also alive. |
| 35 // This may return NULL if |context|.get() or |version| is NULL. | 35 // This may return NULL if |context|.get() or |version| is NULL. |
| 36 // |sender| will be used to send messages to the corresponding | |
| 37 // WebServiceWorkerImpl in the child process. | |
| 38 static scoped_ptr<ServiceWorkerHandle> Create( | 36 static scoped_ptr<ServiceWorkerHandle> Create( |
| 39 base::WeakPtr<ServiceWorkerContextCore> context, | 37 base::WeakPtr<ServiceWorkerContextCore> context, |
| 40 IPC::Sender* sender, | 38 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 41 ServiceWorkerVersion* version); | 39 ServiceWorkerVersion* version); |
| 42 | 40 |
| 43 ServiceWorkerHandle(base::WeakPtr<ServiceWorkerContextCore> context, | 41 ServiceWorkerHandle(base::WeakPtr<ServiceWorkerContextCore> context, |
| 44 IPC::Sender* sender, | 42 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 45 ServiceWorkerRegistration* registration, | 43 ServiceWorkerRegistration* registration, |
| 46 ServiceWorkerVersion* version); | 44 ServiceWorkerVersion* version); |
| 47 ~ServiceWorkerHandle() override; | 45 ~ServiceWorkerHandle() override; |
| 48 | 46 |
| 49 // ServiceWorkerVersion::Listener overrides. | 47 // ServiceWorkerVersion::Listener overrides. |
| 50 void OnVersionStateChanged(ServiceWorkerVersion* version) override; | 48 void OnVersionStateChanged(ServiceWorkerVersion* version) override; |
| 51 | 49 |
| 52 ServiceWorkerObjectInfo GetObjectInfo(); | 50 ServiceWorkerObjectInfo GetObjectInfo(); |
| 53 | 51 |
| 54 int handle_id() const { return handle_id_; } | 52 int handle_id() const { return handle_id_; } |
| 55 ServiceWorkerRegistration* registration() { return registration_.get(); } | 53 ServiceWorkerRegistration* registration() { return registration_.get(); } |
| 56 ServiceWorkerVersion* version() { return version_.get(); } | 54 ServiceWorkerVersion* version() { return version_.get(); } |
| 57 | 55 |
| 58 bool HasNoRefCount() const { return ref_count_ <= 0; } | 56 bool HasNoRefCount() const { return ref_count_ <= 0; } |
| 59 void IncrementRefCount(); | 57 void IncrementRefCount(); |
| 60 void DecrementRefCount(); | 58 void DecrementRefCount(); |
| 61 | 59 |
| 62 private: | 60 private: |
| 63 base::WeakPtr<ServiceWorkerContextCore> context_; | 61 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 64 IPC::Sender* sender_; // Not owned, it should always outlive this. | 62 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
| 65 const int handle_id_; | 63 const int handle_id_; |
| 66 int ref_count_; // Created with 1. | 64 int ref_count_; // Created with 1. |
| 67 scoped_refptr<ServiceWorkerRegistration> registration_; | 65 scoped_refptr<ServiceWorkerRegistration> registration_; |
| 68 scoped_refptr<ServiceWorkerVersion> version_; | 66 scoped_refptr<ServiceWorkerVersion> version_; |
| 69 | 67 |
| 70 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandle); | 68 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandle); |
| 71 }; | 69 }; |
| 72 | 70 |
| 73 } // namespace content | 71 } // namespace content |
| 74 | 72 |
| 75 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_HANDLE_H_ | 73 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_HANDLE_H_ |
| OLD | NEW |