Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.h" | 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/net/spdyproxy/chrome_data_use_group_provider.h" | 12 #include "chrome/browser/net/spdyproxy/chrome_data_use_group_provider.h" |
| 13 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 13 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
| 14 #include "chrome/browser/previews/previews_infobar_delegate.h" | 14 #include "chrome/browser/previews/previews_infobar_delegate.h" |
| 15 #include "chrome/browser/previews/previews_service.h" | |
| 16 #include "chrome/browser/previews/previews_service_factory.h" | |
| 17 #include "chrome/browser/profiles/profile.h" | |
| 15 #include "chrome/common/channel_info.h" | 18 #include "chrome/common/channel_info.h" |
| 16 #include "chrome/common/chrome_content_client.h" | 19 #include "chrome/common/chrome_content_client.h" |
| 17 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 18 #include "components/data_reduction_proxy/content/browser/content_lofi_decider.h " | 21 #include "components/data_reduction_proxy/content/browser/content_lofi_decider.h " |
| 19 #include "components/data_reduction_proxy/content/browser/content_lofi_ui_servic e.h" | 22 #include "components/data_reduction_proxy/content/browser/content_lofi_ui_servic e.h" |
| 20 #include "components/data_reduction_proxy/content/browser/content_resource_type_ provider.h" | 23 #include "components/data_reduction_proxy/content/browser/content_resource_type_ provider.h" |
| 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h" | 24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h" |
| 22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | 25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" |
| 23 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
| 27 #include "components/previews/core/previews_experiments.h" | |
| 28 #include "components/previews/core/previews_ui_service.h" | |
| 24 #include "components/version_info/version_info.h" | 29 #include "components/version_info/version_info.h" |
| 30 #include "content/public/browser/browser_context.h" | |
| 25 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/navigation_controller.h" | |
| 33 #include "content/public/browser/navigation_entry.h" | |
| 26 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 35 #include "url/gurl.h" | |
| 27 | 36 |
| 28 #if defined(OS_ANDROID) | 37 #if defined(OS_ANDROID) |
| 29 #include "base/android/build_info.h" | 38 #include "base/android/build_info.h" |
| 30 #endif | 39 #endif |
| 31 | 40 |
| 32 namespace content { | 41 namespace content { |
| 33 class BrowserContext; | 42 class BrowserContext; |
| 34 } | 43 } |
| 35 | 44 |
| 36 using data_reduction_proxy::DataReductionProxyParams; | 45 using data_reduction_proxy::DataReductionProxyParams; |
| 37 | 46 |
| 38 namespace { | 47 namespace { |
| 39 | 48 |
| 49 // Adds the preview navigation to the black list. | |
| 50 void AddPreviewNavigationToBlackListCallback( | |
| 51 content::BrowserContext* browser_context, | |
| 52 const GURL& url, | |
| 53 previews::PreviewsType type, | |
| 54 bool opt_out) { | |
| 55 PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile( | |
| 56 Profile::FromBrowserContext(browser_context)); | |
| 57 if (previews_service && previews_service->previews_ui_service()) { | |
| 58 previews_service->previews_ui_service()->AddPreviewNavigation(url, type, | |
| 59 opt_out); | |
| 60 } | |
| 61 } | |
| 62 | |
| 40 // If this is the first Lo-Fi response for a page load, a | 63 // If this is the first Lo-Fi response for a page load, a |
| 41 // PreviewsInfoBarDelegate is created, which handles showing Lo-Fi UI. | 64 // PreviewsInfoBarDelegate is created, which handles showing Lo-Fi UI. |
| 42 void OnLoFiResponseReceivedOnUI(content::WebContents* web_contents) { | 65 void OnLoFiResponseReceivedOnUI(content::WebContents* web_contents, |
| 66 bool is_server_lofi) { | |
| 43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 44 PreviewsInfoBarDelegate::Create( | 68 if (is_server_lofi) { |
|
sclittle
2017/05/03 22:51:29
If both Server and Client LoFi are used on a page,
RyanSturm
2017/05/03 23:20:29
Good Point. I was trying to land these CLs side-by
| |
| 45 web_contents, PreviewsInfoBarDelegate::LOFI, | 69 PreviewsInfoBarDelegate::Create( |
| 46 true /* is_data_saver_user */, | 70 web_contents, PreviewsInfoBarDelegate::LOFI, |
| 47 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); | 71 true /* is_data_saver_user */, |
| 72 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); | |
| 73 } else { | |
| 74 PreviewsInfoBarDelegate::Create( | |
| 75 web_contents, PreviewsInfoBarDelegate::LOFI, | |
| 76 true /* is_data_saver_user */, | |
| 77 base::Bind(&AddPreviewNavigationToBlackListCallback, | |
| 78 web_contents->GetBrowserContext(), | |
| 79 web_contents->GetController() | |
| 80 .GetLastCommittedEntry() | |
| 81 ->GetRedirectChain()[0], | |
| 82 previews::PreviewsType::CLIENT_LOFI)); | |
| 83 } | |
| 48 } | 84 } |
| 49 | 85 |
| 50 } // namespace | 86 } // namespace |
| 51 | 87 |
| 52 std::unique_ptr<data_reduction_proxy::DataReductionProxyIOData> | 88 std::unique_ptr<data_reduction_proxy::DataReductionProxyIOData> |
| 53 CreateDataReductionProxyChromeIOData( | 89 CreateDataReductionProxyChromeIOData( |
| 54 net::NetLog* net_log, | 90 net::NetLog* net_log, |
| 55 PrefService* prefs, | 91 PrefService* prefs, |
| 56 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 92 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 57 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) { | 93 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 85 data_reduction_proxy_io_data->set_resource_type_provider( | 121 data_reduction_proxy_io_data->set_resource_type_provider( |
| 86 base::MakeUnique<data_reduction_proxy::ContentResourceTypeProvider>()); | 122 base::MakeUnique<data_reduction_proxy::ContentResourceTypeProvider>()); |
| 87 data_reduction_proxy_io_data->set_lofi_ui_service( | 123 data_reduction_proxy_io_data->set_lofi_ui_service( |
| 88 base::MakeUnique<data_reduction_proxy::ContentLoFiUIService>( | 124 base::MakeUnique<data_reduction_proxy::ContentLoFiUIService>( |
| 89 ui_task_runner, base::Bind(&OnLoFiResponseReceivedOnUI))); | 125 ui_task_runner, base::Bind(&OnLoFiResponseReceivedOnUI))); |
| 90 data_reduction_proxy_io_data->set_data_usage_source_provider( | 126 data_reduction_proxy_io_data->set_data_usage_source_provider( |
| 91 base::MakeUnique<ChromeDataUseGroupProvider>()); | 127 base::MakeUnique<ChromeDataUseGroupProvider>()); |
| 92 | 128 |
| 93 return data_reduction_proxy_io_data; | 129 return data_reduction_proxy_io_data; |
| 94 } | 130 } |
| OLD | NEW |