Chromium Code Reviews| 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..01ed1b8179d72acd08b90d7f5d3e3d785699a724 |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/content/browser/content_lofi_ui_service.cc |
| @@ -0,0 +1,54 @@ |
| +// 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) {} |
| + |
| +ContentLoFiUIService::~ContentLoFiUIService() {} |
| + |
| +void ContentLoFiUIService::NotifyLoFiReponseReceived( |
| + const net::URLRequest& request) const { |
| + 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) const { |
| + DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| + content::RenderFrameHost* frame = |
| + content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
| + if (frame) { |
| + DCHECK(!notify_lofi_response_received_callback_.is_null()); |
|
tbansal1
2016/01/05 03:10:59
Can you add this DCHECK to the constructor also?
megjablon
2016/01/05 20:13:03
Done.
|
| + content::WebContents* web_contents = |
| + content::WebContents::FromRenderFrameHost(frame); |
| + notify_lofi_response_received_callback_.Run(web_contents); |
| + } |
| +} |
| + |
| +} // namespace data_reduction_proxy |