Chromium Code Reviews| Index: components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.h |
| diff --git a/components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.h b/components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..28f95b7c57ed4025452eb9b94a7e9dda7741f5a5 |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.h |
| @@ -0,0 +1,85 @@ |
| +// 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_UI_MANAGER_H_ |
| +#define COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_UI_MANAGER_H_ |
| + |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/message_loop/message_loop_proxy.h" |
| +#include "base/time/time.h" |
| +#include "url/gurl.h" |
| + |
| +namespace data_reduction_proxy { |
| + |
| +class TestDataReducitonProxyUIManager; |
| + |
| +// Construction needs to happen on the main thread. |
| +class DataReductionProxyUIManager |
| + : public base::RefCountedThreadSafe<DataReductionProxyUIManager> { |
| + public: |
| + // Passed a boolean indicating whether or not it is OK to proceed with |
| + // loading an URL. |
| + typedef base::Callback<void(bool /*proceed*/)> UrlCheckCallback; |
| + |
| + // Structure used to pass parameters between the IO and UI thread when |
| + // interacting with the blocking page. |
| + struct BypassResource { |
| + BypassResource(); |
| + ~BypassResource(); |
| + |
| + GURL url; |
| + bool is_subresource; |
| + UrlCheckCallback callback; // This is called back on the IO thread. |
| + int render_process_host_id; |
| + int render_view_id; |
| + }; |
| + |
| + // The DataReductionProxyUIManager handles displaying blocking pages. After |
| + // a page is loaded from the blocking page, another blocking page will not be |
| + // shown for five minutes. |
| + DataReductionProxyUIManager( |
| + const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| + |
| + // Using |resource.render_process_host_id| and |resource.render_view_id| |
| + // checks if WebContents exists for the RenderViewHost retreived from these |
| + // id's. |
| + virtual bool IsTabClosed(const BypassResource& resource) const; |
| + |
| + // Called on the UI thread to display an interstitial page. |url| is the url |
| + // of the resource that bypassed. If the request contained a chain of |
| + // redirects, |url| is the last url in the chain, and |original_url| is the |
| + // first one (the root of the chain). Otherwise, |original_url| = |url|. |
| + virtual void DisplayBlockingPage(const BypassResource& resource); |
| + |
| + // The blocking page on the UI thread has completed. |
| + void OnBlockingPageDone(const BypassResource& resource, bool proceed); |
| + |
| + private: |
| + // Ref counted classes have private destructors to avoid any code deleting the |
| + // object accidentally while there are still references to it. |
| + friend class base::RefCountedThreadSafe<DataReductionProxyUIManager>; |
| + friend class TestDataReductionProxyUIManager; |
| + |
| + virtual ~DataReductionProxyUIManager(); |
| + |
| + // Records the last time the blocking page was shown. Once the blocking page |
|
bengr
2014/12/31 01:10:21
"for another five minutes" -> "for a period of tim
megjablon
2014/12/31 02:12:28
Done.
|
| + // is shown, it is not displayed for another five minutes. |
| + base::Time blocking_page_last_shown_; |
| + |
| + // A task runner to ensure that calls to DisplayBlockingPage take place on the |
| + // UI thread. |
| + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
|
bengr
2014/12/31 01:10:21
Add a blank line below.
megjablon
2014/12/31 02:12:28
Done.
|
| + // A task runner to post OnBlockingPageDone to the IO thread. |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUIManager); |
| +}; |
| + |
| +} // namespace data_reduction_proxy |
| + |
| +#endif // COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_UI_MANAGER_H_ |