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 "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/sequenced_task_runner_helpers.h" | 10 #include "base/sequenced_task_runner_helpers.h" |
11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "content/public/browser/blob_context.h" |
12 | 13 |
13 namespace webkit_blob { | 14 namespace webkit_blob { |
14 class BlobStorageContext; | 15 class BlobStorageContext; |
15 } | 16 } |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 class BrowserContext; | 19 class BrowserContext; |
19 struct ChromeBlobStorageContextDeleter; | 20 struct ChromeBlobStorageContextDeleter; |
20 | 21 |
21 // A context class that keeps track of BlobStorageController used by the chrome. | 22 // A context class that keeps track of BlobStorageController used by the chrome. |
22 // There is an instance associated with each BrowserContext. There could be | 23 // There is an instance associated with each BrowserContext. There could be |
23 // multiple URLRequestContexts in the same browser context that refers to the | 24 // multiple URLRequestContexts in the same browser context that refers to the |
24 // same instance. | 25 // same instance. |
25 // | 26 // |
26 // All methods, except the ctor, are expected to be called on | 27 // All methods, except the ctor, are expected to be called on |
27 // the IO thread (unless specifically called out in doc comments). | 28 // the IO thread (unless specifically called out in doc comments). |
28 class CONTENT_EXPORT ChromeBlobStorageContext | 29 class CONTENT_EXPORT ChromeBlobStorageContext |
29 : public base::RefCountedThreadSafe<ChromeBlobStorageContext, | 30 : public BlobContext, |
| 31 public base::RefCountedThreadSafe<ChromeBlobStorageContext, |
30 ChromeBlobStorageContextDeleter> { | 32 ChromeBlobStorageContextDeleter> { |
31 public: | 33 public: |
32 ChromeBlobStorageContext(); | 34 ChromeBlobStorageContext(); |
33 | 35 |
34 static ChromeBlobStorageContext* GetFor( | 36 static ChromeBlobStorageContext* GetFor( |
35 BrowserContext* browser_context); | 37 BrowserContext* browser_context); |
36 | 38 |
37 void InitializeOnIOThread(); | 39 void InitializeOnIOThread(); |
38 | 40 |
39 webkit_blob::BlobStorageContext* context() const { | 41 webkit_blob::BlobStorageContext* context() const { |
40 return context_.get(); | 42 return context_.get(); |
41 } | 43 } |
42 | 44 |
| 45 // BlobContext implementation. |
| 46 virtual void CreateMemoryBackedBlob( |
| 47 const char* data, size_t length, const BlobCallback& callback) OVERRIDE; |
| 48 |
43 protected: | 49 protected: |
44 virtual ~ChromeBlobStorageContext(); | 50 virtual ~ChromeBlobStorageContext(); |
45 | 51 |
46 private: | 52 private: |
47 friend class base::DeleteHelper<ChromeBlobStorageContext>; | 53 friend class base::DeleteHelper<ChromeBlobStorageContext>; |
48 friend class base::RefCountedThreadSafe<ChromeBlobStorageContext, | 54 friend class base::RefCountedThreadSafe<ChromeBlobStorageContext, |
49 ChromeBlobStorageContextDeleter>; | 55 ChromeBlobStorageContextDeleter>; |
50 friend struct ChromeBlobStorageContextDeleter; | 56 friend struct ChromeBlobStorageContextDeleter; |
51 | 57 |
| 58 scoped_ptr<BlobHandle> CreateMemoryBackedBlobOnIOThread( |
| 59 const char* data, size_t length, const BlobCallback& callback); |
| 60 |
52 void DeleteOnCorrectThread() const; | 61 void DeleteOnCorrectThread() const; |
53 | 62 |
54 scoped_ptr<webkit_blob::BlobStorageContext> context_; | 63 scoped_ptr<webkit_blob::BlobStorageContext> context_; |
55 }; | 64 }; |
56 | 65 |
57 struct ChromeBlobStorageContextDeleter { | 66 struct ChromeBlobStorageContextDeleter { |
58 static void Destruct(const ChromeBlobStorageContext* context) { | 67 static void Destruct(const ChromeBlobStorageContext* context) { |
59 context->DeleteOnCorrectThread(); | 68 context->DeleteOnCorrectThread(); |
60 } | 69 } |
61 }; | 70 }; |
62 | 71 |
63 } // namespace content | 72 } // namespace content |
64 | 73 |
65 #endif // CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_ | 74 #endif // CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_ |
OLD | NEW |