service_worker_context_wrapper.h revision f2477e01787aa58f445919b809d89e252beef54f
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.h"
12#include "content/common/content_export.h"
13
14namespace base {
15class FilePath;
16}
17
18namespace quota {
19class QuotaManagerProxy;
20}
21
22namespace content {
23
24class ServiceWorkerContextCore;
25
26// A refcounted wrapper class for our core object. Higher level content lib
27// classes keep references to this class on mutliple threads. The inner core
28// instance is strictly single threaded and is not refcounted, the core object
29// is what is used internally in the service worker lib.
30class CONTENT_EXPORT ServiceWorkerContextWrapper
31    : NON_EXPORTED_BASE(public ServiceWorkerContext),
32      public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> {
33 public:
34  ServiceWorkerContextWrapper();
35
36  // Init and Shutdown are for use on the UI thread when the profile,
37  // storagepartition is being setup and torn down.
38  void Init(const base::FilePath& user_data_directory,
39            quota::QuotaManagerProxy* quota_manager_proxy);
40  void Shutdown();
41
42  // The core context is only for use on the IO thread.
43  ServiceWorkerContextCore* context();
44
45 private:
46  friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>;
47  virtual ~ServiceWorkerContextWrapper();
48
49  scoped_ptr<ServiceWorkerContextCore> context_core_;
50};
51
52}  // namespace content
53
54#endif  // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
55