| 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_LOADER_RESOURCE_MESSAGE_FILTER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_MESSAGE_FILTER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_RESOURCE_MESSAGE_FILTER_H_ | 6 #define CONTENT_BROWSER_LOADER_RESOURCE_MESSAGE_FILTER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/sequenced_task_runner_helpers.h" | 14 #include "base/sequenced_task_runner_helpers.h" |
| 15 #include "base/single_thread_task_runner.h" |
| 15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 16 #include "content/common/url_loader_factory.mojom.h" | 17 #include "content/common/url_loader_factory.mojom.h" |
| 17 #include "content/public/browser/browser_associated_interface.h" | 18 #include "content/public/browser/browser_associated_interface.h" |
| 18 #include "content/public/browser/browser_message_filter.h" | 19 #include "content/public/browser/browser_message_filter.h" |
| 19 #include "content/public/browser/browser_thread.h" | |
| 20 #include "content/public/common/resource_type.h" | 20 #include "content/public/common/resource_type.h" |
| 21 | 21 |
| 22 namespace storage { | 22 namespace storage { |
| 23 class FileSystemContext; | 23 class FileSystemContext; |
| 24 } // namespace storage | 24 } // namespace storage |
| 25 | 25 |
| 26 namespace net { | 26 namespace net { |
| 27 class URLRequestContext; | 27 class URLRequestContext; |
| 28 } // namespace net | 28 } // namespace net |
| 29 | 29 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 46 public mojom::URLLoaderFactory { | 46 public mojom::URLLoaderFactory { |
| 47 public: | 47 public: |
| 48 typedef base::Callback<void(ResourceType resource_type, | 48 typedef base::Callback<void(ResourceType resource_type, |
| 49 ResourceContext**, | 49 ResourceContext**, |
| 50 net::URLRequestContext**)> GetContextsCallback; | 50 net::URLRequestContext**)> GetContextsCallback; |
| 51 | 51 |
| 52 // |appcache_service|, |blob_storage_context|, |file_system_context|, | 52 // |appcache_service|, |blob_storage_context|, |file_system_context|, |
| 53 // |service_worker_context| may be nullptr in unittests. | 53 // |service_worker_context| may be nullptr in unittests. |
| 54 // InitializeForTest() needs to be manually called for unittests where | 54 // InitializeForTest() needs to be manually called for unittests where |
| 55 // OnFilterAdded() would not otherwise be called. | 55 // OnFilterAdded() would not otherwise be called. |
| 56 ResourceMessageFilter(int child_id, | 56 ResourceMessageFilter( |
| 57 ChromeAppCacheService* appcache_service, | 57 int child_id, |
| 58 ChromeBlobStorageContext* blob_storage_context, | 58 ChromeAppCacheService* appcache_service, |
| 59 storage::FileSystemContext* file_system_context, | 59 ChromeBlobStorageContext* blob_storage_context, |
| 60 ServiceWorkerContextWrapper* service_worker_context, | 60 storage::FileSystemContext* file_system_context, |
| 61 const GetContextsCallback& get_contexts_callback); | 61 ServiceWorkerContextWrapper* service_worker_context, |
| 62 const GetContextsCallback& get_contexts_callback, |
| 63 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_runner); |
| 62 | 64 |
| 63 // BrowserMessageFilter implementation. | 65 // BrowserMessageFilter implementation. |
| 64 void OnFilterAdded(IPC::Channel* channel) override; | 66 void OnFilterAdded(IPC::Channel* channel) override; |
| 65 void OnChannelClosing() override; | 67 void OnChannelClosing() override; |
| 66 bool OnMessageReceived(const IPC::Message& message) override; | 68 bool OnMessageReceived(const IPC::Message& message) override; |
| 67 void OnDestruct() const override; | 69 void OnDestruct() const override; |
| 68 | 70 |
| 69 base::WeakPtr<ResourceMessageFilter> GetWeakPtr(); | 71 base::WeakPtr<ResourceMessageFilter> GetWeakPtr(); |
| 70 | 72 |
| 71 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest request, | 73 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest request, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 82 ResourceRequesterInfo* requester_info_for_test() { | 84 ResourceRequesterInfo* requester_info_for_test() { |
| 83 return requester_info_.get(); | 85 return requester_info_.get(); |
| 84 } | 86 } |
| 85 void InitializeForTest(); | 87 void InitializeForTest(); |
| 86 | 88 |
| 87 protected: | 89 protected: |
| 88 // Protected destructor so that we can be overriden in tests. | 90 // Protected destructor so that we can be overriden in tests. |
| 89 ~ResourceMessageFilter() override; | 91 ~ResourceMessageFilter() override; |
| 90 | 92 |
| 91 private: | 93 private: |
| 92 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; | |
| 93 friend class base::DeleteHelper<ResourceMessageFilter>; | 94 friend class base::DeleteHelper<ResourceMessageFilter>; |
| 94 | 95 |
| 95 // Initializes the weak pointer of this filter in |requester_info_|. | 96 // Initializes the weak pointer of this filter in |requester_info_|. |
| 96 void InitializeOnIOThread(); | 97 void InitializeOnIOThread(); |
| 97 | 98 |
| 98 bool is_channel_closed_; | 99 bool is_channel_closed_; |
| 99 scoped_refptr<ResourceRequesterInfo> requester_info_; | 100 scoped_refptr<ResourceRequesterInfo> requester_info_; |
| 100 | 101 |
| 102 // Task runner for the IO thead. |
| 103 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; |
| 104 |
| 101 // This must come last to make sure weak pointers are invalidated first. | 105 // This must come last to make sure weak pointers are invalidated first. |
| 102 base::WeakPtrFactory<ResourceMessageFilter> weak_ptr_factory_; | 106 base::WeakPtrFactory<ResourceMessageFilter> weak_ptr_factory_; |
| 103 | 107 |
| 104 DISALLOW_IMPLICIT_CONSTRUCTORS(ResourceMessageFilter); | 108 DISALLOW_IMPLICIT_CONSTRUCTORS(ResourceMessageFilter); |
| 105 }; | 109 }; |
| 106 | 110 |
| 107 } // namespace content | 111 } // namespace content |
| 108 | 112 |
| 109 #endif // CONTENT_BROWSER_LOADER_RESOURCE_MESSAGE_FILTER_H_ | 113 #endif // CONTENT_BROWSER_LOADER_RESOURCE_MESSAGE_FILTER_H_ |
| OLD | NEW |