Chromium Code Reviews| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "net/base/network_delegate.h" | 12 #include "net/base/network_delegate.h" |
| 13 | 13 |
| 14 class CookieSettings; | 14 class CookieSettings; |
| 15 class ExtensionEventRouterForwarder; | 15 class ExtensionEventRouterForwarder; |
| 16 class ExtensionInfoMap; | 16 class ExtensionInfoMap; |
| 17 class PrefService; | 17 class PrefService; |
| 18 template<class T> class PrefMember; | 18 template<class T> class PrefMember; |
| 19 | 19 |
| 20 typedef PrefMember<bool> BooleanPrefMember; | 20 typedef PrefMember<bool> BooleanPrefMember; |
| 21 | 21 |
| 22 namespace policy { | 22 namespace policy { |
| 23 class URLBlacklistManager; | 23 class URLBlacklistManager; |
| 24 } | 24 } |
| 25 | 25 |
| 26 // ChromeNetworkDelegate is the central point from within the chrome code to | 26 // ChromeNetworkDelegate is the central point from within the chrome code to |
| 27 // add hooks into the network stack. | 27 // add hooks into the network stack. |
| 28 class ChromeNetworkDelegate : public net::NetworkDelegate { | 28 class ChromeNetworkDelegate : public net::NetworkDelegate { |
| 29 public: | 29 public: |
| 30 // The level of visibility of the browser window using this delegate. This | |
| 31 // determines if we are permitted to transmit certain bits of information or | |
| 32 // not. | |
| 33 enum BrowserVisibility { | |
| 34 NORMAL, | |
| 35 INCOGNITO, | |
|
Ilya Sherman
2012/04/19 18:52:59
nit: I know it makes for longer lines, but perhaps
SteveT
2012/04/20 16:50:32
Okay, okay. Done :)
| |
| 36 }; | |
| 37 | |
| 30 // If |profile| is NULL, events will be broadcasted to all profiles, | 38 // If |profile| is NULL, events will be broadcasted to all profiles, |
| 31 // otherwise they will only be sent to the specified profile. | 39 // otherwise they will only be sent to the specified profile. |
| 32 // |enable_referrers| should be initialized on the UI thread (see below) | 40 // |enable_referrers| and |enable_metrics| should be initialized on the UI |
| 33 // beforehand. This object's owner is responsible for cleaning it up at | 41 // thread (see below) beforehand, though |enable_metrics| is optional and |
| 34 // shutdown. If |cookie_settings| is NULL, all cookies are enabled, | 42 // will be treated as false if not passed in. This object's owner is |
| 35 // otherwise, the settings are enforced on all observed network requests. | 43 // responsible for cleaning it up at shutdown. If |cookie_settings| is NULL, |
| 44 // all cookies are enabled, otherwise, the settings are enforced on all | |
| 45 // observed network requests. | |
| 36 ChromeNetworkDelegate( | 46 ChromeNetworkDelegate( |
| 37 ExtensionEventRouterForwarder* event_router, | 47 ExtensionEventRouterForwarder* event_router, |
| 38 ExtensionInfoMap* extension_info_map, | 48 ExtensionInfoMap* extension_info_map, |
| 39 const policy::URLBlacklistManager* url_blacklist_manager, | 49 const policy::URLBlacklistManager* url_blacklist_manager, |
| 40 void* profile, | 50 void* profile, |
| 41 CookieSettings* cookie_settings, | 51 CookieSettings* cookie_settings, |
| 42 BooleanPrefMember* enable_referrers); | 52 BrowserVisibility visibility, |
| 53 BooleanPrefMember* enable_referrers, | |
| 54 BooleanPrefMember* enable_metrics); | |
| 43 virtual ~ChromeNetworkDelegate(); | 55 virtual ~ChromeNetworkDelegate(); |
| 44 | 56 |
| 45 // Binds |enable_referrers| to |pref_service| and moves it to the IO thread. | 57 // Binds |enable_referrers| to the kReferrersEnabled pref in |pref_service| |
| 46 // This method should be called on the UI thread. | 58 // and moves it to the IO thread. This method should be called on the UI |
| 59 // thread. | |
| 47 static void InitializeReferrersEnabled(BooleanPrefMember* enable_referrers, | 60 static void InitializeReferrersEnabled(BooleanPrefMember* enable_referrers, |
| 48 PrefService* pref_service); | 61 PrefService* pref_service); |
| 49 | 62 |
| 63 // Binds |enable_referrers| to the kMetricsReportingEnabled pref in | |
| 64 // |pref_service| and moves it to the IO thread. This method should be called | |
| 65 // on the UI thread. | |
| 66 static void InitializeMetricsEnabled(BooleanPrefMember* enable_metrics, | |
| 67 PrefService* pref_service); | |
| 68 | |
| 50 private: | 69 private: |
| 51 // NetworkDelegate implementation. | 70 // NetworkDelegate implementation. |
| 52 virtual int OnBeforeURLRequest(net::URLRequest* request, | 71 virtual int OnBeforeURLRequest(net::URLRequest* request, |
| 53 const net::CompletionCallback& callback, | 72 const net::CompletionCallback& callback, |
| 54 GURL* new_url) OVERRIDE; | 73 GURL* new_url) OVERRIDE; |
| 55 virtual int OnBeforeSendHeaders(net::URLRequest* request, | 74 virtual int OnBeforeSendHeaders(net::URLRequest* request, |
| 56 const net::CompletionCallback& callback, | 75 const net::CompletionCallback& callback, |
| 57 net::HttpRequestHeaders* headers) OVERRIDE; | 76 net::HttpRequestHeaders* headers) OVERRIDE; |
| 58 virtual void OnSendHeaders(net::URLRequest* request, | 77 virtual void OnSendHeaders(net::URLRequest* request, |
| 59 const net::HttpRequestHeaders& headers) OVERRIDE; | 78 const net::HttpRequestHeaders& headers) OVERRIDE; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 76 net::URLRequest* request, | 95 net::URLRequest* request, |
| 77 const net::AuthChallengeInfo& auth_info, | 96 const net::AuthChallengeInfo& auth_info, |
| 78 const AuthCallback& callback, | 97 const AuthCallback& callback, |
| 79 net::AuthCredentials* credentials) OVERRIDE; | 98 net::AuthCredentials* credentials) OVERRIDE; |
| 80 virtual bool CanGetCookies(const net::URLRequest* request, | 99 virtual bool CanGetCookies(const net::URLRequest* request, |
| 81 const net::CookieList& cookie_list) OVERRIDE; | 100 const net::CookieList& cookie_list) OVERRIDE; |
| 82 virtual bool CanSetCookie(const net::URLRequest* request, | 101 virtual bool CanSetCookie(const net::URLRequest* request, |
| 83 const std::string& cookie_line, | 102 const std::string& cookie_line, |
| 84 net::CookieOptions* options) OVERRIDE; | 103 net::CookieOptions* options) OVERRIDE; |
| 85 | 104 |
| 105 // Adds Chrome experiment and metrics state as custom headers to |headers| | |
| 106 // based on local state and |request|. | |
| 107 void AddChromeMetricsStateHeader(net::URLRequest* request, | |
| 108 net::HttpRequestHeaders* headers); | |
| 109 | |
| 86 scoped_refptr<ExtensionEventRouterForwarder> event_router_; | 110 scoped_refptr<ExtensionEventRouterForwarder> event_router_; |
| 87 void* profile_; | 111 void* profile_; |
| 88 scoped_refptr<CookieSettings> cookie_settings_; | 112 scoped_refptr<CookieSettings> cookie_settings_; |
| 89 | 113 |
| 114 // The visibility of the browser window that uses this delegate. Note that | |
| 115 // this field is not valid if |profile_| is NULL, so always check profile_ | |
| 116 // first before this field. | |
| 117 BrowserVisibility visibility_; | |
| 118 | |
| 90 scoped_refptr<ExtensionInfoMap> extension_info_map_; | 119 scoped_refptr<ExtensionInfoMap> extension_info_map_; |
| 91 | 120 |
| 92 // Weak, owned by our owner. | 121 // Weak, owned by our owner. |
| 93 BooleanPrefMember* enable_referrers_; | 122 BooleanPrefMember* enable_referrers_; |
| 94 | 123 |
| 95 // Weak, owned by our owner. | 124 // Weak, owned by our owner. |
| 125 BooleanPrefMember* enable_metrics_; | |
| 126 | |
| 127 // Weak, owned by our owner. | |
| 96 const policy::URLBlacklistManager* url_blacklist_manager_; | 128 const policy::URLBlacklistManager* url_blacklist_manager_; |
| 97 | 129 |
| 98 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate); | 130 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate); |
| 99 }; | 131 }; |
| 100 | 132 |
| 101 #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ | 133 #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ |
| OLD | NEW |