| 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_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 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 "base/metrics/field_trial.h" | |
| 13 #include "chrome/common/metrics/variations/variation_ids.h" | |
| 14 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 12 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 15 | 13 |
| 16 class DelayedResourceQueue; | 14 class DelayedResourceQueue; |
| 17 class DownloadRequestLimiter; | 15 class DownloadRequestLimiter; |
| 18 class SafeBrowsingService; | 16 class SafeBrowsingService; |
| 19 | 17 |
| 20 namespace extensions { | 18 namespace extensions { |
| 21 class UserScriptListener; | 19 class UserScriptListener; |
| 22 } | 20 } |
| 23 | 21 |
| 24 namespace prerender { | 22 namespace prerender { |
| 25 class PrerenderTracker; | 23 class PrerenderTracker; |
| 26 } | 24 } |
| 27 | 25 |
| 28 // Implements ResourceDispatcherHostDelegate. Currently used by the Prerender | 26 // Implements ResourceDispatcherHostDelegate. Currently used by the Prerender |
| 29 // system to abort requests and add to the load flags when a request begins. | 27 // system to abort requests and add to the load flags when a request begins. |
| 30 class ChromeResourceDispatcherHostDelegate | 28 class ChromeResourceDispatcherHostDelegate |
| 31 : public content::ResourceDispatcherHostDelegate, | 29 : public content::ResourceDispatcherHostDelegate { |
| 32 public base::FieldTrialList::Observer { | |
| 33 public: | 30 public: |
| 34 // This class does not take ownership of the tracker but merely holds a | 31 // This class does not take ownership of the tracker but merely holds a |
| 35 // reference to it to avoid accessing g_browser_process. | 32 // reference to it to avoid accessing g_browser_process. |
| 36 // |prerender_tracker| must outlive |this|. | 33 // |prerender_tracker| must outlive |this|. |
| 37 explicit ChromeResourceDispatcherHostDelegate( | 34 explicit ChromeResourceDispatcherHostDelegate( |
| 38 prerender::PrerenderTracker* prerender_tracker); | 35 prerender::PrerenderTracker* prerender_tracker); |
| 39 virtual ~ChromeResourceDispatcherHostDelegate(); | 36 virtual ~ChromeResourceDispatcherHostDelegate(); |
| 40 | 37 |
| 41 // ResourceDispatcherHostDelegate implementation. | 38 // ResourceDispatcherHostDelegate implementation. |
| 42 virtual bool ShouldBeginRequest( | 39 virtual bool ShouldBeginRequest( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 net::URLRequest* request, | 77 net::URLRequest* request, |
| 81 content::ResourceContext* resource_context, | 78 content::ResourceContext* resource_context, |
| 82 content::ResourceResponse* response, | 79 content::ResourceResponse* response, |
| 83 IPC::Sender* sender) OVERRIDE; | 80 IPC::Sender* sender) OVERRIDE; |
| 84 virtual void OnRequestRedirected( | 81 virtual void OnRequestRedirected( |
| 85 const GURL& redirect_url, | 82 const GURL& redirect_url, |
| 86 net::URLRequest* request, | 83 net::URLRequest* request, |
| 87 content::ResourceContext* resource_context, | 84 content::ResourceContext* resource_context, |
| 88 content::ResourceResponse* response) OVERRIDE; | 85 content::ResourceResponse* response) OVERRIDE; |
| 89 | 86 |
| 90 // base::FieldTrialList::Observer implementation. | |
| 91 // This will add the variation ID associated with |trial_name| and | |
| 92 // |group_name| to the variation ID cache. | |
| 93 virtual void OnFieldTrialGroupFinalized( | |
| 94 const std::string& trial_name, | |
| 95 const std::string& group_name) OVERRIDE; | |
| 96 | |
| 97 private: | 87 private: |
| 98 void AppendStandardResourceThrottles( | 88 void AppendStandardResourceThrottles( |
| 99 net::URLRequest* request, | 89 net::URLRequest* request, |
| 100 content::ResourceContext* resource_context, | 90 content::ResourceContext* resource_context, |
| 101 int child_id, | 91 int child_id, |
| 102 int route_id, | 92 int route_id, |
| 103 ResourceType::Type resource_type, | 93 ResourceType::Type resource_type, |
| 104 ScopedVector<content::ResourceThrottle>* throttles); | 94 ScopedVector<content::ResourceThrottle>* throttles); |
| 105 | 95 |
| 106 // Adds Chrome experiment and metrics state as custom headers to |request|. | 96 // Adds Chrome experiment and metrics state as custom headers to |request|. |
| 107 // This is a best-effort attempt, and does not interrupt the request if the | 97 // This is a best-effort attempt, and does not interrupt the request if the |
| 108 // headers can not be appended. | 98 // headers can not be appended. |
| 109 void AppendChromeMetricsHeaders( | 99 void AppendChromeMetricsHeaders( |
| 110 net::URLRequest* request, | 100 net::URLRequest* request, |
| 111 content::ResourceContext* resource_context, | 101 content::ResourceContext* resource_context, |
| 112 ResourceType::Type resource_type); | 102 ResourceType::Type resource_type); |
| 113 | 103 |
| 114 #if defined(ENABLE_ONE_CLICK_SIGNIN) | 104 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 115 // Append headers required to tell Gaia whether the sync interstitial | 105 // Append headers required to tell Gaia whether the sync interstitial |
| 116 // should be shown or not. This header is only added for valid Gaia URLs. | 106 // should be shown or not. This header is only added for valid Gaia URLs. |
| 117 void AppendChromeSyncGaiaHeader( | 107 void AppendChromeSyncGaiaHeader( |
| 118 net::URLRequest* request, | 108 net::URLRequest* request, |
| 119 content::ResourceContext* resource_context); | 109 content::ResourceContext* resource_context); |
| 120 #endif | 110 #endif |
| 121 | 111 |
| 122 // Prepares the variation IDs cache with initial values if not already done. | |
| 123 // This method also registers the caller with the FieldTrialList to receive | |
| 124 // new variation IDs. | |
| 125 void InitVariationIDsCacheIfNeeded(); | |
| 126 | |
| 127 // Takes whatever is currently in |variation_ids_set_| and recreates | |
| 128 // |variation_ids_header_| with it. | |
| 129 void UpdateVariationIDsHeaderValue(); | |
| 130 | |
| 131 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; | 112 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; |
| 132 scoped_refptr<SafeBrowsingService> safe_browsing_; | 113 scoped_refptr<SafeBrowsingService> safe_browsing_; |
| 133 scoped_refptr<extensions::UserScriptListener> user_script_listener_; | 114 scoped_refptr<extensions::UserScriptListener> user_script_listener_; |
| 134 prerender::PrerenderTracker* prerender_tracker_; | 115 prerender::PrerenderTracker* prerender_tracker_; |
| 135 | 116 |
| 136 // Whether or not we've initialized the Cache. | |
| 137 bool variation_ids_cache_initialized_; | |
| 138 | |
| 139 // Keep a cache of variation IDs that are transmitted in headers to Google. | |
| 140 // This consists of a list of valid IDs, and the actual transmitted header. | |
| 141 // Note that since this cache is both initialized and accessed from the IO | |
| 142 // thread, we do not need to synchronize its uses. | |
| 143 std::set<chrome_variations::VariationID> variation_ids_set_; | |
| 144 std::string variation_ids_header_; | |
| 145 | |
| 146 DISALLOW_COPY_AND_ASSIGN(ChromeResourceDispatcherHostDelegate); | 117 DISALLOW_COPY_AND_ASSIGN(ChromeResourceDispatcherHostDelegate); |
| 147 }; | 118 }; |
| 148 | 119 |
| 149 #endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE
_H_ | 120 #endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RESOURCE_DISPATCHER_HOST_DELEGATE
_H_ |
| OLD | NEW |