1 // Copyright 2015 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_CACHE_STORAGE_CONTEXT_IMPL_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_CACHE_STORAGE_CONTEXT_IMPL_H_
8 #include "base/files/file_path.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "content/common/content_export.h"
15 class SequencedTaskRunner
;
19 class URLRequestContextGetter
;
23 class QuotaManagerProxy
;
24 class SpecialStoragePolicy
;
30 class ChromeBlobStorageContext
;
31 class ServiceWorkerCacheStorageManager
;
33 // One instance of this exists per StoragePartition, and services multiple
34 // child processes/origins. Most logic is delegated to the owned
35 // ServiceWorkerCacheStorageManager instance, which is only accessed on the IO
37 // TODO(jsbell): Derive from a public CacheStorageContext. crbug.com/466371
38 class CONTENT_EXPORT CacheStorageContextImpl
39 : public base::RefCountedThreadSafe
<CacheStorageContextImpl
> {
41 explicit CacheStorageContextImpl(BrowserContext
* browser_context
);
43 // Init and Shutdown are for use on the UI thread when the profile,
44 // storagepartition is being setup and torn down.
45 void Init(const base::FilePath
& user_data_directory
,
46 storage::QuotaManagerProxy
* quota_manager_proxy
,
47 storage::SpecialStoragePolicy
* special_storage_policy
);
50 // Only callable on the IO thread.
51 ServiceWorkerCacheStorageManager
* cache_manager() const;
53 bool is_incognito() const { return is_incognito_
; }
55 // The URLRequestContext doesn't exist until after the StoragePartition is
56 // made (which is after this object is made). This function must be called
57 // after this object is created but before any ServiceWorkerCache operations.
58 // It must be called on the IO thread. If either parameter is NULL the
59 // function immediately returns without forwarding to the
60 // ServiceWorkerCacheStorageManager.
61 void SetBlobParametersForCache(
62 net::URLRequestContextGetter
* request_context
,
63 ChromeBlobStorageContext
* blob_storage_context
);
66 friend class base::RefCountedThreadSafe
<CacheStorageContextImpl
>;
68 ~CacheStorageContextImpl();
70 void CreateCacheStorageManager(
71 const base::FilePath
& user_data_directory
,
72 const scoped_refptr
<base::SequencedTaskRunner
>& cache_task_runner
,
73 storage::QuotaManagerProxy
* quota_manager_proxy
,
74 storage::SpecialStoragePolicy
* special_storage_policy
);
78 // Initialized in Init(); true if the user data directory is empty.
79 bool is_incognito_
= false;
81 // Only accessed on the IO thread.
82 scoped_ptr
<ServiceWorkerCacheStorageManager
> cache_manager_
;
85 } // namespace content
87 #endif // CONTENT_BROWSER_SERVICE_WORKER_CACHE_STORAGE_CONTEXT_IMPL_H_