Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.cc

Issue 684223003: Data Reduction Proxy Interstitials (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing bengr comments Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 <vector>
8
9 #include "base/bind.h"
10 #include "base/time/time.h"
11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/web_contents.h"
13
14 namespace data_reduction_proxy {
15
16 namespace {
17
18 // Once the blocking page is shown, it is not displayed for another five
19 // minutes.
20 const int kBlockingPageDelayInMinutes = 5;
21
22 }
23
24 DataReductionProxyUIManager::BypassResource::BypassResource()
25 : is_subresource(false),
26 render_process_host_id(-1),
27 render_view_id(-1) {
28 }
29
30 DataReductionProxyUIManager::BypassResource::~BypassResource() {
31 }
32
33 DataReductionProxyUIManager::DataReductionProxyUIManager(
34 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
35 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
36 : ui_task_runner_(ui_task_runner),
37 io_task_runner_(io_task_runner) {
38 }
39
40 DataReductionProxyUIManager::~DataReductionProxyUIManager() {
41 }
42
43 bool DataReductionProxyUIManager::IsTabClosed(
44 const BypassResource& resource) const {
45 // The tab might have been closed.
46 content::RenderViewHost* render_view_host =
47 content::RenderViewHost::FromID(resource.render_process_host_id,
48 resource.render_view_id);
49 content::WebContents* web_contents = nullptr;
50 if (render_view_host)
51 web_contents = content::WebContents::FromRenderViewHost(render_view_host);
52
53 if(web_contents)
54 return false;
55 return true;
56 }
57
58 void DataReductionProxyUIManager::DisplayBlockingPage(
59 const BypassResource& resource) {
60 DCHECK(ui_task_runner_->BelongsToCurrentThread());
61 // Check if the user has already ignored the warning for this render_view
62 // and domain.
63 if (base::Time::Now() - blocking_page_last_shown_ <
64 base::TimeDelta::FromMinutes(kBlockingPageDelayInMinutes)) {
65 if (!resource.callback.is_null())
66 io_task_runner_->PostTask(FROM_HERE, base::Bind(resource.callback, true));
67 return;
68 }
69
70 if (IsTabClosed(resource)) {
71 // The tab is gone and there was not a chance to show the interstitial.
72 // Just act as if "Don't Proceed" were chosen.
73 io_task_runner_->PostTask(
74 FROM_HERE,
75 base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone,
76 this, resource, false));
77 return;
78 }
79
80 // TODO(megjablon): Show blocking page. For now, continue on to the page.
81 io_task_runner_->PostTask(
82 FROM_HERE,
83 base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone,
84 this, resource, true));
85 }
86
87 void DataReductionProxyUIManager::OnBlockingPageDone(
88 const BypassResource& resource,
89 bool proceed) {
90 DCHECK(io_task_runner_->BelongsToCurrentThread());
91 if (!resource.callback.is_null())
92 resource.callback.Run(proceed);
93 if (proceed)
94 blocking_page_last_shown_ = base::Time::Now();
95 }
96
97 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698