This sets up API to release OutputSurface from LTHClient.
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_handle.h
blob8fe2bd9d65bed6dedffa082bab05aa8cf76a0e66
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_HANDLE_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_HANDLE_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "content/browser/service_worker/service_worker_version.h"
13 #include "content/common/content_export.h"
14 #include "content/common/service_worker/service_worker_types.h"
16 namespace IPC {
17 class Sender;
20 namespace content {
22 class ServiceWorkerContextCore;
24 // Roughly corresponds to one WebServiceWorker object in the renderer process.
26 // The renderer process maintains the reference count by owning a
27 // ServiceWorkerHandleReference for each reference it has to the service worker
28 // object. ServiceWorkerHandleReference creation and destruction sends an IPC to
29 // the browser process, which adjusts the ServiceWorkerHandle refcount.
31 // Has references to the corresponding ServiceWorkerVersion in order to ensure
32 // that the version is alive while this handle is around.
33 class CONTENT_EXPORT ServiceWorkerHandle
34 : NON_EXPORTED_BASE(public ServiceWorkerVersion::Listener) {
35 public:
36 // Creates a handle for a live version. This may return nullptr if any of
37 // |context|, |provider_host| and |version| is nullptr.
38 static scoped_ptr<ServiceWorkerHandle> Create(
39 base::WeakPtr<ServiceWorkerContextCore> context,
40 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
41 ServiceWorkerVersion* version);
43 ServiceWorkerHandle(base::WeakPtr<ServiceWorkerContextCore> context,
44 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
45 ServiceWorkerVersion* version);
46 ~ServiceWorkerHandle() override;
48 // ServiceWorkerVersion::Listener overrides.
49 void OnVersionStateChanged(ServiceWorkerVersion* version) override;
51 ServiceWorkerObjectInfo GetObjectInfo();
53 int provider_id() const { return provider_id_; }
54 int handle_id() const { return handle_id_; }
55 ServiceWorkerVersion* version() { return version_.get(); }
57 bool HasNoRefCount() const { return ref_count_ <= 0; }
58 void IncrementRefCount();
59 void DecrementRefCount();
61 private:
62 base::WeakPtr<ServiceWorkerContextCore> context_;
63 base::WeakPtr<ServiceWorkerProviderHost> provider_host_;
64 const int provider_id_;
65 const int handle_id_;
66 int ref_count_; // Created with 1.
67 scoped_refptr<ServiceWorkerVersion> version_;
69 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandle);
72 } // namespace content
74 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_HANDLE_H_