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.
5 #ifndef CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_
6 #define CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/sequenced_task_runner_helpers.h"
11 #include "content/common/content_export.h"
19 class BlobStorageContext
;
25 struct ChromeBlobStorageContextDeleter
;
27 // A context class that keeps track of BlobStorageController used by the chrome.
28 // There is an instance associated with each BrowserContext. There could be
29 // multiple URLRequestContexts in the same browser context that refers to the
32 // All methods, except the ctor, are expected to be called on
33 // the IO thread (unless specifically called out in doc comments).
34 class CONTENT_EXPORT ChromeBlobStorageContext
35 : public base::RefCountedThreadSafe
<ChromeBlobStorageContext
,
36 ChromeBlobStorageContextDeleter
> {
38 ChromeBlobStorageContext();
40 static ChromeBlobStorageContext
* GetFor(
41 BrowserContext
* browser_context
);
43 void InitializeOnIOThread();
45 storage::BlobStorageContext
* context() const { return context_
.get(); }
47 // Returns a NULL scoped_ptr on failure.
48 scoped_ptr
<BlobHandle
> CreateMemoryBackedBlob(const char* data
,
51 // Returns a NULL scoped_ptr on failure.
52 scoped_ptr
<BlobHandle
> CreateFileBackedBlob(
53 const base::FilePath
& path
,
56 const base::Time
& expected_modification_time
);
59 virtual ~ChromeBlobStorageContext();
62 friend class base::DeleteHelper
<ChromeBlobStorageContext
>;
63 friend class base::RefCountedThreadSafe
<ChromeBlobStorageContext
,
64 ChromeBlobStorageContextDeleter
>;
65 friend struct ChromeBlobStorageContextDeleter
;
67 void DeleteOnCorrectThread() const;
69 scoped_ptr
<storage::BlobStorageContext
> context_
;
72 struct ChromeBlobStorageContextDeleter
{
73 static void Destruct(const ChromeBlobStorageContext
* context
) {
74 context
->DeleteOnCorrectThread();
78 } // namespace content
80 #endif // CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_