Chromium Code Reviews| Index: components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle.h |
| diff --git a/components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle.h b/components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0b2dc257013c78b1e0035f197f69b61f37f23ab4 |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle.h |
| @@ -0,0 +1,103 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_RESOURCE_THROTTLE_H_ |
| +#define COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_RESOURCE_THROTTLE_H_ |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.h" |
| +#include "content/public/browser/resource_throttle.h" |
| +#include "content/public/common/resource_type.h" |
| +#include "url/gurl.h" |
| + |
| +namespace net { |
| +class URLRequest; |
| +} |
| + |
| +namespace data_reduction_proxy { |
| + |
| +class DataReductionProxyParams; |
| +class DataReductionProxyUIManager; |
| +class DataReductionProxyUIService; |
| + |
| +// Gets notified at various points during the process of loading a resource. |
| +// Defers the resource load when the data reduction proxy is not going to be |
| +// used. Resumes or cancels a deferred resource load via the ResourceController. |
| +// |
| +// Displays a warning if the data reduction proxy returns a response that |
| +// triggers a bypass, when the proxy will not be used for a request because it |
| +// isn't configured (a previous bypass), when the proxy is supposed to be used, |
| +// but there is a connection error. Will not warn when the data reduction proxy |
| +// is bypassed by local rules, or when the url scheme is not proxied by the data |
| +// reduction proxy. |
| +// |
| +// This feature is for users that wish to be warned when configurations that are |
|
bengr
2014/12/31 01:10:21
Reword:
This class is useful, e.g., for users that
megjablon
2014/12/31 02:12:28
Done.
|
| +// able to go through the data reduction proxy are bypassed. |
| +class DataReductionProxyResourceThrottle |
| + : public content::ResourceThrottle, |
| + public base::SupportsWeakPtr<DataReductionProxyResourceThrottle> { |
| + public: |
| + // Constructs a DataReductionProxyResourceThrottle object with the given |
| + // request, resource type, ui service, and params. |
| + DataReductionProxyResourceThrottle( |
| + const net::URLRequest* request, |
| + content::ResourceType resource_type, |
| + const DataReductionProxyUIService* ui_service, |
| + const DataReductionProxyParams* params); |
| + |
| + virtual ~DataReductionProxyResourceThrottle(); |
| + |
| + // Overrides content::ResourceThrottle. |
| + void WillStartUsingNetwork(bool* defer) override; |
| + void WillRedirectRequest(const GURL& new_url, bool* defer) override; |
| + void WillProcessResponse(bool* defer) override; |
| + const char* GetNameForLogging() const override; |
| + |
| + private: |
| + enum State { |
| + NOT_BYPASSED, // A warning has not been shown yet for this request. |
| + LOCAL_BYPASS, // The request was bypassed by local bypass rules. |
| + REMOTE_BYPASS, // The request was bypassed by the data reduction proxy. |
| + }; |
| + |
| + // Starts displaying the data reduction proxy blocking page if it is not |
| + // prerendering. Must only be called on the UI thread. Takes a bypass |
| + // resource, which is a structure used to pass parameters between the IO and |
| + // UI thread, and shows a blocking page for the resource using the given |
| + // ui_manager. |
| + static void StartDisplayingBlockingPage( |
| + scoped_refptr<DataReductionProxyUIManager> ui_manager, |
| + const DataReductionProxyUIManager::BypassResource& resource); |
| + |
| + // Creates a bypass resource and calls StartDisplayingBlockingPage on the UI |
| + // thread. Sets defer to true. A bypass resource is a structure used to pass |
| + // parameters between the IO and UI thread when interacting with the blocking |
| + // page. Virtual for testing. |
| + virtual void DisplayBlockingPage(bool* defer); |
| + |
| + // Called on the IO thread when the user has decided to proceed with the |
| + // current request, or go back. |
| + void OnBlockingPageComplete(bool proceed); |
| + |
| + // The bypass state of this. |
| + State state_; |
| + |
| + // Must outlive |this|. |
| + const net::URLRequest* request_; |
| + |
| + // Holds the UI manager that shows intersitials. Must outlive |this|. |
| + const DataReductionProxyUIService* ui_service_; |
| + |
| + // Must outlive |this|. |
| + const DataReductionProxyParams* params_; |
| + |
| + const bool is_subresource_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DataReductionProxyResourceThrottle); |
| +}; |
| + |
| +} // namespace data_reduction_proxy |
| + |
| +#endif // COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_RESOURCE_THROTTLE_H_ |