Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_handle.h
blob7dae8823fa71181c7df1a95de6e44f57fc013452
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 ServiceWorker object in the renderer process
25 // (WebServiceWorkerImpl).
26 // Has references to the corresponding ServiceWorkerVersion in order to ensure
27 // that the version is alive while this handle is around.
28 class CONTENT_EXPORT ServiceWorkerHandle
29 : NON_EXPORTED_BASE(public ServiceWorkerVersion::Listener) {
30 public:
31 // Creates a handle for a live version. This may return nullptr if any of
32 // |context|, |provider_host| and |version| is nullptr.
33 static scoped_ptr<ServiceWorkerHandle> Create(
34 base::WeakPtr<ServiceWorkerContextCore> context,
35 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
36 ServiceWorkerVersion* version);
38 ServiceWorkerHandle(base::WeakPtr<ServiceWorkerContextCore> context,
39 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
40 ServiceWorkerVersion* version);
41 ~ServiceWorkerHandle() override;
43 // ServiceWorkerVersion::Listener overrides.
44 void OnVersionStateChanged(ServiceWorkerVersion* version) override;
46 ServiceWorkerObjectInfo GetObjectInfo();
48 int provider_id() const { return provider_id_; }
49 int handle_id() const { return handle_id_; }
50 ServiceWorkerVersion* version() { return version_.get(); }
52 bool HasNoRefCount() const { return ref_count_ <= 0; }
53 void IncrementRefCount();
54 void DecrementRefCount();
56 private:
57 base::WeakPtr<ServiceWorkerContextCore> context_;
58 base::WeakPtr<ServiceWorkerProviderHost> provider_host_;
59 const int provider_id_;
60 const int handle_id_;
61 int ref_count_; // Created with 1.
62 scoped_refptr<ServiceWorkerVersion> version_;
64 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandle);
67 } // namespace content
69 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_HANDLE_H_