OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_UI_ MANAGER_H_ | |
6 #define COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_UI_ MANAGER_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/message_loop/message_loop_proxy.h" | |
13 #include "base/time/time.h" | |
14 #include "url/gurl.h" | |
15 | |
16 namespace data_reduction_proxy { | |
17 | |
18 class TestDataReducitonProxyUIManager; | |
19 | |
20 // Construction needs to happen on the main thread. | |
21 class DataReductionProxyUIManager | |
22 : public base::RefCountedThreadSafe<DataReductionProxyUIManager> { | |
23 public: | |
24 // Passed a boolean indicating whether or not it is OK to proceed with | |
25 // loading an URL. | |
26 typedef base::Callback<void(bool /*proceed*/)> UrlCheckCallback; | |
27 | |
28 // Structure used to pass parameters between the IO and UI thread when | |
29 // interacting with the blocking page. | |
30 struct BypassResource { | |
31 BypassResource(); | |
32 ~BypassResource(); | |
33 | |
34 GURL url; | |
35 bool is_subresource; | |
36 UrlCheckCallback callback; // This is called back on the IO thread. | |
37 int render_process_host_id; | |
38 int render_view_id; | |
39 }; | |
40 | |
41 // The DataReductionProxyUIManager handles displaying blocking pages. After | |
42 // a page is loaded from the blocking page, another blocking page will not be | |
43 // shown for five minutes. | |
44 DataReductionProxyUIManager( | |
45 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | |
46 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | |
47 | |
48 // Using |resource.render_process_host_id| and |resource.render_view_id| | |
49 // checks if WebContents exists for the RenderViewHost retreived from these | |
50 // id's. | |
51 virtual bool IsTabClosed(const BypassResource& resource) const; | |
52 | |
53 // Called on the UI thread to display an interstitial page. |url| is the url | |
54 // of the resource that bypassed. If the request contained a chain of | |
55 // redirects, |url| is the last url in the chain, and |original_url| is the | |
56 // first one (the root of the chain). Otherwise, |original_url| = |url|. | |
57 virtual void DisplayBlockingPage(const BypassResource& resource); | |
58 | |
59 // The blocking page on the UI thread has completed. | |
60 void OnBlockingPageDone(const BypassResource& resource, bool proceed); | |
61 | |
62 private: | |
63 // Ref counted classes have private destructors to avoid any code deleting the | |
64 // object accidentally while there are still references to it. | |
65 friend class base::RefCountedThreadSafe<DataReductionProxyUIManager>; | |
66 friend class TestDataReductionProxyUIManager; | |
67 | |
68 virtual ~DataReductionProxyUIManager(); | |
69 | |
70 // 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.
| |
71 // is shown, it is not displayed for another five minutes. | |
72 base::Time blocking_page_last_shown_; | |
73 | |
74 // A task runner to ensure that calls to DisplayBlockingPage take place on the | |
75 // UI thread. | |
76 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.
| |
77 // A task runner to post OnBlockingPageDone to the IO thread. | |
78 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUIManager); | |
81 }; | |
82 | |
83 } // namespace data_reduction_proxy | |
84 | |
85 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_ UI_MANAGER_H_ | |
OLD | NEW |