| 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) { |
| 43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 66 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 44 PreviewsInfoBarDelegate::Create( | 67 PreviewsInfoBarDelegate::Create( |
| 45 web_contents, PreviewsInfoBarDelegate::LOFI, | 68 web_contents, PreviewsInfoBarDelegate::LOFI, |
| 46 true /* is_data_saver_user */, | 69 true /* is_data_saver_user */, |
| 47 PreviewsInfoBarDelegate::OnDismissPreviewsInfobarCallback()); | 70 base::Bind(&AddPreviewNavigationToBlackListCallback, |
| 71 web_contents->GetBrowserContext(), |
| 72 web_contents->GetController() |
| 73 .GetLastCommittedEntry() |
| 74 ->GetRedirectChain()[0], |
| 75 previews::PreviewsType::LOFI)); |
| 48 } | 76 } |
| 49 | 77 |
| 50 } // namespace | 78 } // namespace |
| 51 | 79 |
| 52 std::unique_ptr<data_reduction_proxy::DataReductionProxyIOData> | 80 std::unique_ptr<data_reduction_proxy::DataReductionProxyIOData> |
| 53 CreateDataReductionProxyChromeIOData( | 81 CreateDataReductionProxyChromeIOData( |
| 54 net::NetLog* net_log, | 82 net::NetLog* net_log, |
| 55 PrefService* prefs, | 83 PrefService* prefs, |
| 56 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 84 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 57 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) { | 85 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( | 113 data_reduction_proxy_io_data->set_resource_type_provider( |
| 86 base::MakeUnique<data_reduction_proxy::ContentResourceTypeProvider>()); | 114 base::MakeUnique<data_reduction_proxy::ContentResourceTypeProvider>()); |
| 87 data_reduction_proxy_io_data->set_lofi_ui_service( | 115 data_reduction_proxy_io_data->set_lofi_ui_service( |
| 88 base::MakeUnique<data_reduction_proxy::ContentLoFiUIService>( | 116 base::MakeUnique<data_reduction_proxy::ContentLoFiUIService>( |
| 89 ui_task_runner, base::Bind(&OnLoFiResponseReceivedOnUI))); | 117 ui_task_runner, base::Bind(&OnLoFiResponseReceivedOnUI))); |
| 90 data_reduction_proxy_io_data->set_data_usage_source_provider( | 118 data_reduction_proxy_io_data->set_data_usage_source_provider( |
| 91 base::MakeUnique<ChromeDataUseGroupProvider>()); | 119 base::MakeUnique<ChromeDataUseGroupProvider>()); |
| 92 | 120 |
| 93 return data_reduction_proxy_io_data; | 121 return data_reduction_proxy_io_data; |
| 94 } | 122 } |
| OLD | NEW |