OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_u i_manager.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/bind_helpers.h" | |
9 #include "base/threading/thread.h" | |
10 #include "content/public/browser/browser_thread.h" | |
11 #include "content/public/browser/render_view_host.h" | |
12 #include "content/public/browser/web_contents.h" | |
13 #include "net/url_request/url_request_context.h" | |
14 #include "net/url_request/url_request_context_getter.h" | |
15 | |
16 using content::BrowserThread; | |
bengr
2014/12/17 00:30:20
I prefer to avoid using "using"
megjablon
2014/12/23 02:18:05
Done.
| |
17 using content::RenderViewHost; | |
18 using content::WebContents; | |
19 | |
20 namespace data_reduction_proxy { | |
21 | |
22 DataReductionProxyUIManager::BypassResource::BypassResource() | |
23 : is_subresource(false), | |
24 render_process_host_id(-1), | |
25 render_view_id(-1) { | |
26 } | |
27 | |
28 DataReductionProxyUIManager::BypassResource::~BypassResource() { | |
29 } | |
30 | |
31 DataReductionProxyUIManager::DataReductionProxyUIManager() { | |
32 } | |
33 | |
34 DataReductionProxyUIManager::~DataReductionProxyUIManager() { | |
35 } | |
36 | |
37 void DataReductionProxyUIManager::OnBlockingPageDone( | |
38 const std::vector<BypassResource>& resources, | |
39 bool proceed) { | |
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
41 for (std::vector<BypassResource>::const_iterator iter = resources.begin(); | |
42 iter != resources.end(); ++iter) { | |
43 const BypassResource& resource = *iter; | |
44 if (!resource.callback.is_null()) | |
45 resource.callback.Run(proceed); | |
46 | |
47 if (proceed) | |
48 proceed_blocking_page_ = base::Time::Now(); | |
49 } | |
50 } | |
51 | |
52 void DataReductionProxyUIManager::DisplayBlockingPage( | |
53 const BypassResource& resource) { | |
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
55 | |
56 // Check if the user has already ignored our warning for this render_view | |
57 // and domain. | |
58 if (base::Time::Now() - proceed_blocking_page_ < | |
59 base::TimeDelta::FromMinutes(5)) { | |
bengr
2014/12/17 00:30:20
indent 4
megjablon
2014/12/23 02:18:05
Done.
| |
60 if (!resource.callback.is_null()) { | |
61 BrowserThread::PostTask( | |
62 BrowserThread::IO, FROM_HERE, base::Bind(resource.callback, true)); | |
63 } | |
64 return; | |
65 } | |
66 | |
67 // The tab might have been closed. | |
68 RenderViewHost* render_view_host = | |
69 RenderViewHost::FromID(resource.render_process_host_id, | |
bengr
2014/12/17 00:30:20
Indent only 4
megjablon
2014/12/23 02:18:05
Done.
| |
70 resource.render_view_id); | |
71 WebContents* web_contents = NULL; | |
72 if (render_view_host) | |
73 web_contents = WebContents::FromRenderViewHost(render_view_host); | |
74 | |
75 if (!web_contents) { | |
76 // The tab is gone and we did not have a chance at showing the interstitial. | |
77 // Just act as if "Don't Proceed" were chosen. | |
78 std::vector<BypassResource> resources; | |
79 resources.push_back(resource); | |
80 BrowserThread::PostTask( | |
81 BrowserThread::IO, FROM_HERE, | |
82 base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone, | |
83 this, resources, false)); | |
84 return; | |
85 } | |
86 | |
87 // TODO(megjablon): Show blocking page. For now, continue on to the page. | |
88 LOG(WARNING) << "BLOCKING PAGE!"; | |
89 std::vector<BypassResource> resources; | |
90 resources.push_back(resource); | |
91 BrowserThread::PostTask( | |
92 BrowserThread::IO, FROM_HERE, | |
93 base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone, | |
94 this, resources, true)); | |
95 } | |
96 | |
97 } // namespace data_reduction_proxy | |
OLD | NEW |