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 CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ |
6 #define CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ | 6 #define CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
11 #include "net/base/network_delegate.h" | 13 #include "net/base/network_delegate.h" |
12 | 14 |
13 class CookieSettings; | 15 class CookieSettings; |
14 class ExtensionInfoMap; | 16 class ExtensionInfoMap; |
15 class ManagedModeURLFilter; | 17 class ManagedModeURLFilter; |
16 class PrefService; | 18 class PrefService; |
17 template<class T> class PrefMember; | 19 template<class T> class PrefMember; |
18 | 20 |
19 typedef PrefMember<bool> BooleanPrefMember; | 21 typedef PrefMember<bool> BooleanPrefMember; |
20 | 22 |
21 namespace chrome_browser_net { | 23 namespace chrome_browser_net { |
22 class LoadTimeStats; | 24 class LoadTimeStats; |
23 } | 25 } |
24 | 26 |
25 namespace extensions { | 27 namespace extensions { |
26 class EventRouterForwarder; | 28 class EventRouterForwarder; |
27 } | 29 } |
28 | 30 |
| 31 namespace net { |
| 32 class URLRequest; |
| 33 } |
| 34 |
29 namespace policy { | 35 namespace policy { |
30 class URLBlacklistManager; | 36 class URLBlacklistManager; |
31 } | 37 } |
32 | 38 |
33 // ChromeNetworkDelegate is the central point from within the chrome code to | 39 // ChromeNetworkDelegate is the central point from within the chrome code to |
34 // add hooks into the network stack. | 40 // add hooks into the network stack. |
35 class ChromeNetworkDelegate : public net::NetworkDelegate { | 41 class ChromeNetworkDelegate : public net::NetworkDelegate { |
36 public: | 42 public: |
37 // If |profile| is NULL, events will be broadcasted to all profiles, | 43 // If |profile| is NULL, events will be broadcasted to all profiles, |
38 // otherwise they will only be sent to the specified profile. | 44 // otherwise they will only be sent to the specified profile. |
39 // |enable_referrers| and |enable_do_not_track| should be initialized on the | 45 // |enable_referrers| and |enable_do_not_track| should be initialized on the |
40 // UI thread (see below) beforehand. This object's owner is responsible for | 46 // UI thread (see below) beforehand. This object's owner is responsible for |
41 // cleaning it up at shutdown. |enable_do_not_track| can be NULL. | 47 // cleaning it up at shutdown. |enable_do_not_track| can be NULL. |
42 // If |cookie_settings| is NULL, all cookies are enabled, otherwise, the | 48 // If |cookie_settings| is NULL, all cookies are enabled, otherwise, the |
43 // settings are enforced on all observed network requests. | 49 // settings are enforced on all observed network requests. |
44 ChromeNetworkDelegate( | 50 ChromeNetworkDelegate( |
45 extensions::EventRouterForwarder* event_router, | 51 extensions::EventRouterForwarder* event_router, |
46 ExtensionInfoMap* extension_info_map, | 52 ExtensionInfoMap* extension_info_map, |
47 const policy::URLBlacklistManager* url_blacklist_manager, | 53 const policy::URLBlacklistManager* url_blacklist_manager, |
48 const ManagedModeURLFilter* managed_mode_url_filter, | 54 const ManagedModeURLFilter* managed_mode_url_filter, |
49 void* profile, | 55 void* profile, |
50 CookieSettings* cookie_settings, | 56 CookieSettings* cookie_settings, |
51 BooleanPrefMember* enable_referrers, | 57 BooleanPrefMember* enable_referrers, |
52 BooleanPrefMember* enable_do_not_track, | 58 BooleanPrefMember* enable_do_not_track, |
| 59 BooleanPrefMember* force_google_safesearch, |
53 chrome_browser_net::LoadTimeStats* load_time_stats); | 60 chrome_browser_net::LoadTimeStats* load_time_stats); |
54 virtual ~ChromeNetworkDelegate(); | 61 virtual ~ChromeNetworkDelegate(); |
55 | 62 |
56 // Causes |OnCanThrottleRequest| to always return false, for all | 63 // Causes |OnCanThrottleRequest| to always return false, for all |
57 // instances of this object. | 64 // instances of this object. |
58 static void NeverThrottleRequests(); | 65 static void NeverThrottleRequests(); |
59 | 66 |
60 // Binds the pref members to |pref_service| and moves them to the IO thread. | 67 // Binds the pref members to |pref_service| and moves them to the IO thread. |
61 // |enable_do_not_track| can be NULL. | 68 // |enable_do_not_track| can be NULL. |
62 // This method should be called on the UI thread. | 69 // This method should be called on the UI thread. |
63 static void InitializePrefsOnUIThread(BooleanPrefMember* enable_referrers, | 70 static void InitializePrefsOnUIThread( |
64 BooleanPrefMember* enable_do_not_track, | 71 BooleanPrefMember* enable_referrers, |
65 PrefService* pref_service); | 72 BooleanPrefMember* enable_do_not_track, |
| 73 BooleanPrefMember* force_google_safesearch, |
| 74 PrefService* pref_service); |
66 | 75 |
67 // When called, all file:// URLs will now be accessible. If this is not | 76 // When called, all file:// URLs will now be accessible. If this is not |
68 // called, then some platforms restrict access to file:// paths. | 77 // called, then some platforms restrict access to file:// paths. |
69 static void AllowAccessToAllFiles(); | 78 static void AllowAccessToAllFiles(); |
70 | 79 |
71 private: | 80 private: |
72 friend class ChromeNetworkDelegateTest; | 81 friend class ChromeNetworkDelegateTest; |
73 | 82 |
74 // NetworkDelegate implementation. | 83 // NetworkDelegate implementation. |
75 virtual int OnBeforeURLRequest(net::URLRequest* request, | 84 virtual int OnBeforeURLRequest(net::URLRequest* request, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 126 |
118 scoped_refptr<extensions::EventRouterForwarder> event_router_; | 127 scoped_refptr<extensions::EventRouterForwarder> event_router_; |
119 void* profile_; | 128 void* profile_; |
120 scoped_refptr<CookieSettings> cookie_settings_; | 129 scoped_refptr<CookieSettings> cookie_settings_; |
121 | 130 |
122 scoped_refptr<ExtensionInfoMap> extension_info_map_; | 131 scoped_refptr<ExtensionInfoMap> extension_info_map_; |
123 | 132 |
124 // Weak, owned by our owner. | 133 // Weak, owned by our owner. |
125 BooleanPrefMember* enable_referrers_; | 134 BooleanPrefMember* enable_referrers_; |
126 BooleanPrefMember* enable_do_not_track_; | 135 BooleanPrefMember* enable_do_not_track_; |
| 136 BooleanPrefMember* force_google_safesearch_; |
127 | 137 |
128 // Weak, owned by our owner. | 138 // Weak, owned by our owner. |
129 const policy::URLBlacklistManager* url_blacklist_manager_; | 139 const policy::URLBlacklistManager* url_blacklist_manager_; |
130 | 140 |
131 // Weak pointer. The owner of this object needs to make sure that the | 141 // Weak pointer. The owner of this object needs to make sure that the |
132 // |managed_mode_url_filter_| outlives it. | 142 // |managed_mode_url_filter_| outlives it. |
133 const ManagedModeURLFilter* managed_mode_url_filter_; | 143 const ManagedModeURLFilter* managed_mode_url_filter_; |
134 | 144 |
135 // When true, allow access to all file:// URLs. | 145 // When true, allow access to all file:// URLs. |
136 static bool g_allow_file_access_; | 146 static bool g_allow_file_access_; |
137 | 147 |
138 // True if OnCanThrottleRequest should always return false. | 148 // True if OnCanThrottleRequest should always return false. |
139 // | 149 // |
140 // Note: This needs to be static as the instance of | 150 // Note: This needs to be static as the instance of |
141 // ChromeNetworkDelegate used may change over time, and we need to | 151 // ChromeNetworkDelegate used may change over time, and we need to |
142 // set this variable once at start-up time. It is effectively | 152 // set this variable once at start-up time. It is effectively |
143 // static anyway since it is based on a command-line flag. | 153 // static anyway since it is based on a command-line flag. |
144 static bool g_never_throttle_requests_; | 154 static bool g_never_throttle_requests_; |
145 | 155 |
146 // Pointer to IOThread global, should outlive ChromeNetworkDelegate. | 156 // Pointer to IOThread global, should outlive ChromeNetworkDelegate. |
147 chrome_browser_net::LoadTimeStats* load_time_stats_; | 157 chrome_browser_net::LoadTimeStats* load_time_stats_; |
148 | 158 |
149 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate); | 159 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate); |
150 }; | 160 }; |
151 | 161 |
152 #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ | 162 #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ |
OLD | NEW |