Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / browser / shared_worker / worker_storage_partition.h
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.
4
5 #ifndef CONTENT_BROWSER_SHARED_WORKERT_WORKER_STORAGE_PARTITION_H_
6 #define CONTENT_BROWSER_SHARED_WORKERT_WORKER_STORAGE_PARTITION_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "content/common/content_export.h"
10
11 namespace storage {
12 class QuotaManager;
13 }
14
15 namespace storage {
16 class FileSystemContext;
17 }  // namespace storage
18
19 namespace net {
20 class URLRequestContextGetter;
21 }
22
23 namespace storage {
24 class DatabaseTracker;
25 }  // namespace storage
26
27 namespace content {
28 class ChromeAppCacheService;
29 class IndexedDBContextImpl;
30 class ServiceWorkerContextWrapper;
31
32 // Contains the data from StoragePartition for use by Worker APIs.
33 //
34 // StoragePartition meant for the UI so we can't use it directly in many
35 // Worker APIs that run on the IO thread. While we could make it RefCounted,
36 // the Worker system is the only place that really needs access on the IO
37 // thread. Instead of changing the lifetime semantics of StoragePartition,
38 // we just create a parallel struct here to simplify the APIs of various
39 // methods in WorkerServiceImpl.
40 //
41 // This class is effectively a struct, but we make it a class because we want to
42 // define copy constructors, assignment operators, and an Equals() function for
43 // it which makes it look awkward as a struct.
44 class CONTENT_EXPORT WorkerStoragePartition {
45  public:
46   WorkerStoragePartition(
47       net::URLRequestContextGetter* url_request_context,
48       net::URLRequestContextGetter* media_url_request_context,
49       ChromeAppCacheService* appcache_service,
50       storage::QuotaManager* quota_manager,
51       storage::FileSystemContext* filesystem_context,
52       storage::DatabaseTracker* database_tracker,
53       IndexedDBContextImpl* indexed_db_context,
54       ServiceWorkerContextWrapper* service_worker_context);
55   ~WorkerStoragePartition();
56
57   // Declaring so these don't get inlined which has the unfortunate effect of
58   // requiring all including classes to have the full definition of every member
59   // type.
60   WorkerStoragePartition(const WorkerStoragePartition& other);
61   const WorkerStoragePartition& operator=(const WorkerStoragePartition& rhs);
62
63   bool Equals(const WorkerStoragePartition& other) const;
64
65   net::URLRequestContextGetter* url_request_context() const {
66     return url_request_context_.get();
67   }
68
69   net::URLRequestContextGetter* media_url_request_context() const {
70     return media_url_request_context_.get();
71   }
72
73   ChromeAppCacheService* appcache_service() const {
74     return appcache_service_.get();
75   }
76
77   storage::QuotaManager* quota_manager() const { return quota_manager_.get(); }
78
79   storage::FileSystemContext* filesystem_context() const {
80     return filesystem_context_.get();
81   }
82
83   storage::DatabaseTracker* database_tracker() const {
84     return database_tracker_.get();
85   }
86
87   IndexedDBContextImpl* indexed_db_context() const {
88     return indexed_db_context_.get();
89   }
90
91   ServiceWorkerContextWrapper* service_worker_context() const {
92     return service_worker_context_.get();
93   }
94
95  private:
96   void Copy(const WorkerStoragePartition& other);
97
98   scoped_refptr<net::URLRequestContextGetter> url_request_context_;
99   scoped_refptr<net::URLRequestContextGetter> media_url_request_context_;
100   scoped_refptr<ChromeAppCacheService> appcache_service_;
101   scoped_refptr<storage::QuotaManager> quota_manager_;
102   scoped_refptr<storage::FileSystemContext> filesystem_context_;
103   scoped_refptr<storage::DatabaseTracker> database_tracker_;
104   scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
105   scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
106 };
107
108 // WorkerStoragePartitionId can be used to identify each
109 // WorkerStoragePartitions. We can hold WorkerStoragePartitionId without
110 // extending the lifetime of all objects in the WorkerStoragePartition.
111 // That means that holding a WorkerStoragePartitionId doesn't mean the
112 // corresponding partition and its members are kept alive.
113 class CONTENT_EXPORT WorkerStoragePartitionId {
114  public:
115   explicit WorkerStoragePartitionId(const WorkerStoragePartition& partition);
116   ~WorkerStoragePartitionId();
117   bool Equals(const WorkerStoragePartitionId& other) const;
118
119  private:
120   net::URLRequestContextGetter* url_request_context_;
121   net::URLRequestContextGetter* media_url_request_context_;
122   ChromeAppCacheService* appcache_service_;
123   storage::QuotaManager* quota_manager_;
124   storage::FileSystemContext* filesystem_context_;
125   storage::DatabaseTracker* database_tracker_;
126   IndexedDBContextImpl* indexed_db_context_;
127   ServiceWorkerContextWrapper* service_worker_context_;
128 };
129
130 }  // namespace content
131
132 #endif  // CONTENT_BROWSER_SHARED_WORKERT_WORKER_STORAGE_PARTITION_H_