OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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_BLOB_STORAGE_BLOB_URL_LOADER_FACTORY_H_ |
| 6 #define CONTENT_BROWSER_BLOB_STORAGE_BLOB_URL_LOADER_FACTORY_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "content/common/content_export.h" |
| 12 #include "content/common/url_loader_factory.mojom.h" |
| 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "mojo/public/cpp/bindings/binding_set.h" |
| 15 |
| 16 namespace storage { |
| 17 class BlobStorageContext; |
| 18 class FileSystemContext; |
| 19 } |
| 20 |
| 21 namespace content { |
| 22 |
| 23 // A class for creating URLLoaderFactory for blob scheme. |
| 24 // There should be one owned per StoragePartition. |
| 25 class BlobURLLoaderFactory |
| 26 : public base::RefCountedThreadSafe<BlobURLLoaderFactory, |
| 27 BrowserThread::DeleteOnIOThread>, |
| 28 public mojom::URLLoaderFactory { |
| 29 public: |
| 30 using BlobContextGetter = |
| 31 base::OnceCallback<base::WeakPtr<storage::BlobStorageContext>()>; |
| 32 CONTENT_EXPORT BlobURLLoaderFactory( |
| 33 BlobContextGetter blob_storage_context_getter, |
| 34 scoped_refptr<storage::FileSystemContext> file_system_context); |
| 35 |
| 36 // Creates a URLLoaderFactory interface pointer for serving blob requests. |
| 37 // Called on the UI thread. |
| 38 mojom::URLLoaderFactoryPtr CreateFactory(); |
| 39 |
| 40 // mojom::URLLoaderFactory implementation: |
| 41 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest loader, |
| 42 int32_t routing_id, |
| 43 int32_t request_id, |
| 44 uint32_t options, |
| 45 const ResourceRequest& request, |
| 46 mojom::URLLoaderClientPtr client) override; |
| 47 void SyncLoad(int32_t routing_id, |
| 48 int32_t request_id, |
| 49 const ResourceRequest& request, |
| 50 SyncLoadCallback callback) override; |
| 51 |
| 52 private: |
| 53 friend class base::DeleteHelper<BlobURLLoaderFactory>; |
| 54 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; |
| 55 |
| 56 ~BlobURLLoaderFactory() override; |
| 57 |
| 58 void InitializeOnIO(BlobContextGetter blob_storage_context_getter); |
| 59 void BindOnIO(mojom::URLLoaderFactoryRequest request); |
| 60 |
| 61 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
| 62 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 63 |
| 64 // Used on the IO thread. |
| 65 mojo::BindingSet<mojom::URLLoaderFactory> loader_factory_bindings_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(BlobURLLoaderFactory); |
| 68 }; |
| 69 |
| 70 } // namespace content |
| 71 |
| 72 #endif // CONTENT_BROWSER_BLOB_STORAGE_BLOB_URL_LOADER_FACTORY_H_ |
OLD | NEW |