Home | History | Annotate | Download | only in worker_host
      1 // Copyright (c) 2012 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_WORKER_HOST_WORKER_STORAGE_PARTITION_H_
      6 #define CONTENT_BROWSER_WORKER_HOST_WORKER_STORAGE_PARTITION_H_
      7 
      8 #include "base/memory/ref_counted.h"
      9 #include "content/common/content_export.h"
     10 
     11 namespace quota {
     12 class QuotaManager;
     13 }
     14 
     15 namespace fileapi {
     16 class FileSystemContext;
     17 }  // namespace fileapi
     18 
     19 namespace net {
     20 class URLRequestContextGetter;
     21 }
     22 
     23 namespace webkit_database {
     24 class DatabaseTracker;
     25 }  // namespace webkit_database
     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       quota::QuotaManager* quota_manager,
     51       fileapi::FileSystemContext* filesystem_context,
     52       webkit_database::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   quota::QuotaManager* quota_manager() const {
     78     return quota_manager_.get();
     79   }
     80 
     81   fileapi::FileSystemContext* filesystem_context() const {
     82     return filesystem_context_.get();
     83   }
     84 
     85   webkit_database::DatabaseTracker* database_tracker() const {
     86     return database_tracker_.get();
     87   }
     88 
     89   IndexedDBContextImpl* indexed_db_context() const {
     90     return indexed_db_context_.get();
     91   }
     92 
     93   ServiceWorkerContextWrapper* service_worker_context() const {
     94     return service_worker_context_.get();
     95   }
     96 
     97  private:
     98   void Copy(const WorkerStoragePartition& other);
     99 
    100   scoped_refptr<net::URLRequestContextGetter> url_request_context_;
    101   scoped_refptr<net::URLRequestContextGetter> media_url_request_context_;
    102   scoped_refptr<ChromeAppCacheService> appcache_service_;
    103   scoped_refptr<quota::QuotaManager> quota_manager_;
    104   scoped_refptr<fileapi::FileSystemContext> filesystem_context_;
    105   scoped_refptr<webkit_database::DatabaseTracker> database_tracker_;
    106   scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
    107   scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
    108 };
    109 
    110 // WorkerStoragePartitionId can be used to identify each
    111 // WorkerStoragePartitions. We can hold WorkerStoragePartitionId without
    112 // extending the lifetime of all objects in the WorkerStoragePartition.
    113 // That means that holding a WorkerStoragePartitionId doesn't mean the
    114 // corresponding partition and its members are kept alive.
    115 class CONTENT_EXPORT WorkerStoragePartitionId {
    116  public:
    117   explicit WorkerStoragePartitionId(const WorkerStoragePartition& partition);
    118   ~WorkerStoragePartitionId();
    119   bool Equals(const WorkerStoragePartitionId& other) const;
    120 
    121  private:
    122   net::URLRequestContextGetter* url_request_context_;
    123   net::URLRequestContextGetter* media_url_request_context_;
    124   ChromeAppCacheService* appcache_service_;
    125   quota::QuotaManager* quota_manager_;
    126   fileapi::FileSystemContext* filesystem_context_;
    127   webkit_database::DatabaseTracker* database_tracker_;
    128   IndexedDBContextImpl* indexed_db_context_;
    129   ServiceWorkerContextWrapper* service_worker_context_;
    130 };
    131 
    132 }  // namespace content
    133 
    134 #endif  // CONTENT_BROWSER_WORKER_HOST_WORKER_STORAGE_PARTITION_H_
    135