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

Unified Diff: components/data_reduction_proxy/content/browser/content_lofi_ui_service.cc

Issue 1558553002: Lo-Fi snackbar should only be shown for the first q=low response of a page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tbansal comments Created 4 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 side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/content/browser/content_lofi_ui_service.cc
diff --git a/components/data_reduction_proxy/content/browser/content_lofi_ui_service.cc b/components/data_reduction_proxy/content/browser/content_lofi_ui_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7926bd32c1c3aa11fdaaa88adc92ff1aa4ef7029
--- /dev/null
+++ b/components/data_reduction_proxy/content/browser/content_lofi_ui_service.cc
@@ -0,0 +1,55 @@
+// Copyright 2015 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/content_lofi_ui_service.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/single_thread_task_runner.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/resource_request_info.h"
+#include "content/public/browser/web_contents.h"
+#include "net/url_request/url_request.h"
+
+namespace data_reduction_proxy {
+
+ContentLoFiUIService::ContentLoFiUIService(
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
+ const NotifyLoFiResponseReceivedCallback&
+ notify_lofi_response_received_callback)
+ : ui_task_runner_(ui_task_runner),
+ notify_lofi_response_received_callback_(
+ notify_lofi_response_received_callback) {
+ DCHECK(!notify_lofi_response_received_callback_.is_null());
+}
+
+ContentLoFiUIService::~ContentLoFiUIService() {}
+
+void ContentLoFiUIService::NotifyLoFiReponseReceived(
+ const net::URLRequest& request) {
tbansal1 2016/01/05 21:07:09 Add DCHECK that this is currently on IO thread?
megjablon 2016/01/06 17:20:47 Done.
+ int render_process_id = -1;
+ int render_frame_id = -1;
+ if (content::ResourceRequestInfo::GetRenderFrameForRequest(
+ &request, &render_process_id, &render_frame_id)) {
+ ui_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&ContentLoFiUIService::NotifyLoFiResponseReceivedOnUI,
+ base::Unretained(this), render_process_id, render_frame_id));
+ }
+}
+
+void ContentLoFiUIService::NotifyLoFiResponseReceivedOnUI(int render_process_id,
+ int render_frame_id) {
+ DCHECK(ui_task_runner_->BelongsToCurrentThread());
+ content::RenderFrameHost* frame =
tbansal1 2016/01/05 21:07:09 nit: const
megjablon 2016/01/06 17:20:47 FromRenderFrameHost takes as non-const pointer so
+ content::RenderFrameHost::FromID(render_process_id, render_frame_id);
+ if (frame) {
+ DCHECK(!notify_lofi_response_received_callback_.is_null());
+ content::WebContents* web_contents =
+ content::WebContents::FromRenderFrameHost(frame);
+ notify_lofi_response_received_callback_.Run(web_contents);
+ }
+}
+
+} // namespace data_reduction_proxy

Powered by Google App Engine
This is Rietveld 408576698