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

Unified 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: Adding tests and addressing comments Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.cc
diff --git a/components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.cc b/components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6ddcdc888c6b6fbc3f55f0f5021c17b91344848d
--- /dev/null
+++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.cc
@@ -0,0 +1,92 @@
+// Copyright (c) 2012 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.
+
+#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
bengr 2014/12/29 18:45:42 Why is this needed?
megjablon 2014/12/30 23:40:00 Removed.
+#include "base/threading/thread.h"
bengr 2014/12/29 18:45:42 Why is this needed?
megjablon 2014/12/30 23:40:01 Removed.
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+#include "net/url_request/url_request_context.h"
bengr 2014/12/29 18:45:42 Why is this needed?
megjablon 2014/12/30 23:40:00 Removed.
+#include "net/url_request/url_request_context_getter.h"
bengr 2014/12/29 18:45:42 Why is this needed?
megjablon 2014/12/30 23:40:00 Removed.
+
+namespace data_reduction_proxy {
+
+DataReductionProxyUIManager::BypassResource::BypassResource()
+ : is_subresource(false),
+ render_process_host_id(-1),
+ render_view_id(-1) {
+}
+
+DataReductionProxyUIManager::BypassResource::~BypassResource() {
+}
+
+DataReductionProxyUIManager::DataReductionProxyUIManager() {
+}
+
+DataReductionProxyUIManager::~DataReductionProxyUIManager() {
+}
+
+void DataReductionProxyUIManager::OnBlockingPageDone(
bengr 2014/12/29 18:45:42 This needs a test, that checks that the callbacks
megjablon 2014/12/30 23:40:00 Done.
+ const std::vector<BypassResource>& resources,
+ bool proceed) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ for (std::vector<BypassResource>::const_iterator iter = resources.begin();
+ iter != resources.end(); ++iter) {
+ const BypassResource& resource = *iter;
+ if (!resource.callback.is_null())
+ resource.callback.Run(proceed);
+
+ if (proceed)
+ proceed_blocking_page_ = base::Time::Now();
bengr 2014/12/29 18:45:42 #include "base/time/time.h"
megjablon 2014/12/30 23:40:00 Done.
+ }
+}
+
+void DataReductionProxyUIManager::DisplayBlockingPage(
bengr 2014/12/29 18:45:42 This needs tests. You should cover what happens if
megjablon 2014/12/30 23:40:00 Done.
+ const BypassResource& resource) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ // Check if the user has already ignored our warning for this render_view
+ // and domain.
+ if (base::Time::Now() - proceed_blocking_page_ <
+ base::TimeDelta::FromMinutes(5)) {
bengr 2014/12/29 18:45:42 define 5 as a constant at the top of the file and
megjablon 2014/12/30 23:40:00 Done.
+ if (!resource.callback.is_null()) {
+ content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
+ base::Bind(resource.callback, true));
+ }
+ return;
+ }
+
+ // The tab might have been closed.
+ content::RenderViewHost* render_view_host =
+ content::RenderViewHost::FromID(resource.render_process_host_id,
+ resource.render_view_id);
+ content::WebContents* web_contents = NULL;
bengr 2014/12/29 18:45:42 nullptr
megjablon 2014/12/30 23:40:00 Done.
+ if (render_view_host)
+ web_contents = content::WebContents::FromRenderViewHost(render_view_host);
+
+ if (!web_contents) {
+ // The tab is gone and we did not have a chance at showing the interstitial.
+ // Just act as if "Don't Proceed" were chosen.
+ std::vector<BypassResource> resources;
+ resources.push_back(resource);
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone,
+ this, resources, false));
+ return;
+ }
+
+ // TODO(megjablon): Show blocking page. For now, continue on to the page.
+ LOG(WARNING) << "BLOCKING PAGE!";
bengr 2014/12/29 18:45:42 Remove.
megjablon 2014/12/30 23:40:01 Done.
+ std::vector<BypassResource> resources;
bengr 2014/12/29 18:45:42 #include <vector>
megjablon 2014/12/30 23:40:00 Done.
+ resources.push_back(resource);
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&DataReductionProxyUIManager::OnBlockingPageDone,
+ this, resources, true));
+}
+
+} // namespace data_reduction_proxy

Powered by Google App Engine
This is Rietveld 408576698