OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_ | 5 #ifndef CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_ |
6 #define CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_ | 6 #define CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
| 13 #include "base/files/file_path.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/sequenced_task_runner_helpers.h" | 15 #include "base/sequenced_task_runner_helpers.h" |
15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class FilePath; | 19 class FilePath; |
| 20 class TaskRunner; |
19 class Time; | 21 class Time; |
20 } | 22 } |
21 | 23 |
22 namespace storage { | 24 namespace storage { |
23 class BlobStorageContext; | 25 class BlobStorageContext; |
24 } | 26 } |
25 | 27 |
26 namespace content { | 28 namespace content { |
27 class BlobHandle; | 29 class BlobHandle; |
28 class BrowserContext; | 30 class BrowserContext; |
29 struct ChromeBlobStorageContextDeleter; | 31 struct ChromeBlobStorageContextDeleter; |
30 | 32 |
31 // A context class that keeps track of BlobStorageController used by the chrome. | 33 // A context class that keeps track of BlobStorageController used by the chrome. |
32 // There is an instance associated with each BrowserContext. There could be | 34 // There is an instance associated with each BrowserContext. There could be |
33 // multiple URLRequestContexts in the same browser context that refers to the | 35 // multiple URLRequestContexts in the same browser context that refers to the |
34 // same instance. | 36 // same instance. |
35 // | 37 // |
36 // All methods, except the ctor, are expected to be called on | 38 // All methods, except the ctor, are expected to be called on |
37 // the IO thread (unless specifically called out in doc comments). | 39 // the IO thread (unless specifically called out in doc comments). |
38 class CONTENT_EXPORT ChromeBlobStorageContext | 40 class CONTENT_EXPORT ChromeBlobStorageContext |
39 : public base::RefCountedThreadSafe<ChromeBlobStorageContext, | 41 : public base::RefCountedThreadSafe<ChromeBlobStorageContext, |
40 ChromeBlobStorageContextDeleter> { | 42 ChromeBlobStorageContextDeleter> { |
41 public: | 43 public: |
42 ChromeBlobStorageContext(); | 44 ChromeBlobStorageContext(); |
43 | 45 |
44 static ChromeBlobStorageContext* GetFor( | 46 static ChromeBlobStorageContext* GetFor( |
45 BrowserContext* browser_context); | 47 BrowserContext* browser_context); |
46 | 48 |
47 void InitializeOnIOThread(); | 49 void InitializeOnIOThread(base::FilePath blob_storage_dir, |
| 50 scoped_refptr<base::TaskRunner> file_task_runner); |
48 | 51 |
49 storage::BlobStorageContext* context() const { return context_.get(); } | 52 storage::BlobStorageContext* context() const { return context_.get(); } |
50 | 53 |
51 // Returns a NULL scoped_ptr on failure. | 54 // Returns a NULL scoped_ptr on failure. |
52 std::unique_ptr<BlobHandle> CreateMemoryBackedBlob(const char* data, | 55 std::unique_ptr<BlobHandle> CreateMemoryBackedBlob(const char* data, |
53 size_t length); | 56 size_t length); |
54 | 57 |
55 // Returns a NULL scoped_ptr on failure. | 58 // Returns a NULL scoped_ptr on failure. |
56 std::unique_ptr<BlobHandle> CreateFileBackedBlob( | 59 std::unique_ptr<BlobHandle> CreateFileBackedBlob( |
57 const base::FilePath& path, | 60 const base::FilePath& path, |
58 int64_t offset, | 61 int64_t offset, |
59 int64_t size, | 62 int64_t size, |
60 const base::Time& expected_modification_time); | 63 const base::Time& expected_modification_time); |
61 | 64 |
62 protected: | 65 protected: |
63 virtual ~ChromeBlobStorageContext(); | 66 virtual ~ChromeBlobStorageContext(); |
64 | 67 |
65 private: | 68 private: |
66 friend class base::DeleteHelper<ChromeBlobStorageContext>; | 69 friend class base::DeleteHelper<ChromeBlobStorageContext>; |
67 friend class base::RefCountedThreadSafe<ChromeBlobStorageContext, | 70 friend class base::RefCountedThreadSafe<ChromeBlobStorageContext, |
68 ChromeBlobStorageContextDeleter>; | 71 ChromeBlobStorageContextDeleter>; |
69 friend struct ChromeBlobStorageContextDeleter; | 72 friend struct ChromeBlobStorageContextDeleter; |
70 | 73 |
71 void DeleteOnCorrectThread() const; | 74 void DeleteOnCorrectThread() const; |
72 | 75 |
| 76 base::FilePath blob_storage_dir_; |
73 std::unique_ptr<storage::BlobStorageContext> context_; | 77 std::unique_ptr<storage::BlobStorageContext> context_; |
74 }; | 78 }; |
75 | 79 |
76 struct ChromeBlobStorageContextDeleter { | 80 struct ChromeBlobStorageContextDeleter { |
77 static void Destruct(const ChromeBlobStorageContext* context) { | 81 static void Destruct(const ChromeBlobStorageContext* context) { |
78 context->DeleteOnCorrectThread(); | 82 context->DeleteOnCorrectThread(); |
79 } | 83 } |
80 }; | 84 }; |
81 | 85 |
82 } // namespace content | 86 } // namespace content |
83 | 87 |
84 #endif // CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_ | 88 #endif // CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_ |
OLD | NEW |