service_worker_context_wrapper.h revision effb81e5f8246d0db0270817048dc992db66e9fb
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
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
6#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
7
8#include "base/files/file_path.h"
9#include "base/memory/ref_counted.h"
10#include "base/memory/scoped_ptr.h"
11#include "content/browser/service_worker/service_worker_context_core.h"
12#include "content/common/content_export.h"
13#include "content/public/browser/service_worker_context.h"
14
15namespace base {
16class FilePath;
17}
18
19namespace quota {
20class QuotaManagerProxy;
21}
22
23namespace content {
24
25class ServiceWorkerContextCore;
26
27// A refcounted wrapper class for our core object. Higher level content lib
28// classes keep references to this class on mutliple threads. The inner core
29// instance is strictly single threaded and is not refcounted, the core object
30// is what is used internally in the service worker lib.
31class CONTENT_EXPORT ServiceWorkerContextWrapper
32    : NON_EXPORTED_BASE(public ServiceWorkerContext),
33      public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> {
34 public:
35  ServiceWorkerContextWrapper();
36
37  // Init and Shutdown are for use on the UI thread when the profile,
38  // storagepartition is being setup and torn down.
39  void Init(const base::FilePath& user_data_directory,
40            quota::QuotaManagerProxy* quota_manager_proxy);
41  void Shutdown();
42
43  // The core context is only for use on the IO thread.
44  ServiceWorkerContextCore* context();
45
46  // ServiceWorkerContext implementation:
47  virtual void RegisterServiceWorker(const GURL& pattern,
48                                     const GURL& script_url,
49                                     int source_process_id,
50                                     const ResultCallback& continuation)
51      OVERRIDE;
52
53  virtual void UnregisterServiceWorker(const GURL& pattern,
54                                       int source_process_id,
55                                       const ResultCallback& continuation)
56      OVERRIDE;
57
58 private:
59  friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>;
60  virtual ~ServiceWorkerContextWrapper();
61
62  scoped_ptr<ServiceWorkerContextCore> context_core_;
63};
64
65}  // namespace content
66
67#endif  // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
68