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 "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
12 #include "content/public/browser/browser_message_filter.h" | 12 #include "content/public/browser/browser_message_filter.h" |
13 #include "content/public/common/resource_type.h" | 13 #include "content/public/common/resource_type.h" |
14 | 14 |
15 struct ResourceHostMsg_Request; | 15 struct ResourceHostMsg_Request; |
16 | 16 |
17 namespace storage { | 17 namespace storage { |
18 class FileSystemContext; | 18 class FileSystemContext; |
19 } // namespace storage | 19 } // namespace storage |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 class URLRequestContext; | 22 class URLRequestContext; |
23 } // namespace net | 23 } // namespace net |
24 | 24 |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 class ChromeAppCacheService; | 27 class ChromeAppCacheService; |
28 class ChromeBlobStorageContext; | 28 class ChromeBlobStorageContext; |
| 29 class HostZoomLevelContext; |
| 30 class HostZoomMap; |
29 class ResourceContext; | 31 class ResourceContext; |
30 class ServiceWorkerContextWrapper; | 32 class ServiceWorkerContextWrapper; |
31 | 33 |
32 // This class filters out incoming IPC messages for network requests and | 34 // This class filters out incoming IPC messages for network requests and |
33 // processes them on the IPC thread. As a result, network requests are not | 35 // processes them on the IPC thread. As a result, network requests are not |
34 // delayed by costly UI processing that may be occuring on the main thread of | 36 // delayed by costly UI processing that may be occuring on the main thread of |
35 // the browser. It also means that any hangs in starting a network request | 37 // the browser. It also means that any hangs in starting a network request |
36 // will not interfere with browser UI. | 38 // will not interfere with browser UI. |
37 class CONTENT_EXPORT ResourceMessageFilter : public BrowserMessageFilter { | 39 class CONTENT_EXPORT ResourceMessageFilter : public BrowserMessageFilter { |
38 public: | 40 public: |
39 typedef base::Callback<void(const ResourceHostMsg_Request&, | 41 typedef base::Callback<void(const ResourceHostMsg_Request&, |
40 ResourceContext**, | 42 ResourceContext**, |
41 net::URLRequestContext**)> GetContextsCallback; | 43 net::URLRequestContext**)> GetContextsCallback; |
42 | 44 |
43 // |appcache_service|, |blob_storage_context|, |file_system_context| may be | 45 // |appcache_service|, |blob_storage_context|, |file_system_context| may be |
44 // NULL in unittests or for requests from the (NPAPI) plugin process. | 46 // NULL in unittests or for requests from the (NPAPI) plugin process. |
45 ResourceMessageFilter(int child_id, | 47 ResourceMessageFilter(int child_id, |
46 int process_type, | 48 int process_type, |
47 ChromeAppCacheService* appcache_service, | 49 ChromeAppCacheService* appcache_service, |
48 ChromeBlobStorageContext* blob_storage_context, | 50 ChromeBlobStorageContext* blob_storage_context, |
49 storage::FileSystemContext* file_system_context, | 51 storage::FileSystemContext* file_system_context, |
50 ServiceWorkerContextWrapper* service_worker_context, | 52 ServiceWorkerContextWrapper* service_worker_context, |
| 53 HostZoomLevelContext* host_zoom_level_context, |
51 const GetContextsCallback& get_contexts_callback); | 54 const GetContextsCallback& get_contexts_callback); |
52 | 55 |
53 // BrowserMessageFilter implementation. | 56 // BrowserMessageFilter implementation. |
54 void OnChannelClosing() override; | 57 void OnChannelClosing() override; |
55 bool OnMessageReceived(const IPC::Message& message) override; | 58 bool OnMessageReceived(const IPC::Message& message) override; |
56 | 59 |
57 void GetContexts(const ResourceHostMsg_Request& request, | 60 void GetContexts(const ResourceHostMsg_Request& request, |
58 ResourceContext** resource_context, | 61 ResourceContext** resource_context, |
59 net::URLRequestContext** request_context); | 62 net::URLRequestContext** request_context); |
60 | 63 |
61 // Returns the net::URLRequestContext for the given request. | 64 // Returns the net::URLRequestContext for the given request. |
62 net::URLRequestContext* GetURLRequestContext(ResourceType request_type); | 65 net::URLRequestContext* GetURLRequestContext(ResourceType request_type); |
63 | 66 |
64 ChromeAppCacheService* appcache_service() const { | 67 ChromeAppCacheService* appcache_service() const { |
65 return appcache_service_.get(); | 68 return appcache_service_.get(); |
66 } | 69 } |
67 | 70 |
68 ChromeBlobStorageContext* blob_storage_context() const { | 71 ChromeBlobStorageContext* blob_storage_context() const { |
69 return blob_storage_context_.get(); | 72 return blob_storage_context_.get(); |
70 } | 73 } |
71 | 74 |
72 storage::FileSystemContext* file_system_context() const { | 75 storage::FileSystemContext* file_system_context() const { |
73 return file_system_context_.get(); | 76 return file_system_context_.get(); |
74 } | 77 } |
75 | 78 |
76 ServiceWorkerContextWrapper* service_worker_context() const { | 79 ServiceWorkerContextWrapper* service_worker_context() const { |
77 return service_worker_context_.get(); | 80 return service_worker_context_.get(); |
78 } | 81 } |
79 | 82 |
| 83 // Returns a raw pointer to the HostZoomLevelContext's associated HostZoomMap, |
| 84 // or NULL if no context is present. |
| 85 HostZoomMap* GetHostZoomMap() const; |
| 86 |
80 int child_id() const { return child_id_; } | 87 int child_id() const { return child_id_; } |
81 int process_type() const { return process_type_; } | 88 int process_type() const { return process_type_; } |
82 | 89 |
83 base::WeakPtr<ResourceMessageFilter> GetWeakPtr(); | 90 base::WeakPtr<ResourceMessageFilter> GetWeakPtr(); |
84 | 91 |
85 protected: | 92 protected: |
86 // Protected destructor so that we can be overriden in tests. | 93 // Protected destructor so that we can be overriden in tests. |
87 ~ResourceMessageFilter() override; | 94 ~ResourceMessageFilter() override; |
88 | 95 |
89 private: | 96 private: |
90 // The ID of the child process. | 97 // The ID of the child process. |
91 int child_id_; | 98 int child_id_; |
92 | 99 |
93 int process_type_; | 100 int process_type_; |
94 | 101 |
95 scoped_refptr<ChromeAppCacheService> appcache_service_; | 102 scoped_refptr<ChromeAppCacheService> appcache_service_; |
96 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 103 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
97 scoped_refptr<storage::FileSystemContext> file_system_context_; | 104 scoped_refptr<storage::FileSystemContext> file_system_context_; |
98 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 105 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| 106 scoped_refptr<HostZoomLevelContext> host_zoom_level_context_; |
99 | 107 |
100 GetContextsCallback get_contexts_callback_; | 108 GetContextsCallback get_contexts_callback_; |
101 | 109 |
102 // This must come last to make sure weak pointers are invalidated first. | 110 // This must come last to make sure weak pointers are invalidated first. |
103 base::WeakPtrFactory<ResourceMessageFilter> weak_ptr_factory_; | 111 base::WeakPtrFactory<ResourceMessageFilter> weak_ptr_factory_; |
104 | 112 |
105 DISALLOW_IMPLICIT_CONSTRUCTORS(ResourceMessageFilter); | 113 DISALLOW_IMPLICIT_CONSTRUCTORS(ResourceMessageFilter); |
106 }; | 114 }; |
107 | 115 |
108 } // namespace content | 116 } // namespace content |
109 | 117 |
110 #endif // CONTENT_BROWSER_LOADER_RESOURCE_MESSAGE_FILTER_H_ | 118 #endif // CONTENT_BROWSER_LOADER_RESOURCE_MESSAGE_FILTER_H_ |
OLD | NEW |