| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/offline_pages/background_loader_offliner.h" | 5 #include "chrome/browser/offline_pages/background_loader_offliner.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/metrics/histogram_functions.h" |
| 9 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" | 14 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" |
| 14 #include "chrome/browser/android/offline_pages/offliner_helper.h" | 15 #include "chrome/browser/android/offline_pages/offliner_helper.h" |
| 16 #include "chrome/browser/loader/chrome_navigation_data.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data
.h" |
| 16 #include "components/offline_pages/core/background/offliner_policy.h" | 19 #include "components/offline_pages/core/background/offliner_policy.h" |
| 17 #include "components/offline_pages/core/background/save_page_request.h" | 20 #include "components/offline_pages/core/background/save_page_request.h" |
| 18 #include "components/offline_pages/core/client_namespace_constants.h" | 21 #include "components/offline_pages/core/client_namespace_constants.h" |
| 19 #include "components/offline_pages/core/offline_page_feature.h" | 22 #include "components/offline_pages/core/offline_page_feature.h" |
| 20 #include "components/offline_pages/core/offline_page_model.h" | 23 #include "components/offline_pages/core/offline_page_model.h" |
| 21 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
| 22 #include "content/public/browser/mhtml_extra_parts.h" | 25 #include "content/public/browser/mhtml_extra_parts.h" |
| 23 #include "content/public/browser/navigation_handle.h" | 26 #include "content/public/browser/navigation_handle.h" |
| 24 #include "content/public/browser/render_frame_host.h" | 27 #include "content/public/browser/render_frame_host.h" |
| 25 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/browser/web_contents_user_data.h" | 29 #include "content/public/browser/web_contents_user_data.h" |
| 30 #include "content/public/common/previews_state.h" |
| 27 | 31 |
| 28 namespace offline_pages { | 32 namespace offline_pages { |
| 29 | 33 |
| 30 namespace { | 34 namespace { |
| 31 const char kContentType[] = "text/plain"; | 35 const char kContentType[] = "text/plain"; |
| 32 const char kContentTransferEncodingBinary[] = | 36 const char kContentTransferEncodingBinary[] = |
| 33 "Content-Transfer-Encoding: binary"; | 37 "Content-Transfer-Encoding: binary"; |
| 34 const char kXHeaderForSignals[] = "X-Chrome-Loading-Metrics-Data: 1"; | 38 const char kXHeaderForSignals[] = "X-Chrome-Loading-Metrics-Data: 1"; |
| 35 | 39 |
| 36 class OfflinerData : public content::WebContentsUserData<OfflinerData> { | 40 class OfflinerData : public content::WebContentsUserData<OfflinerData> { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 66 return adjusted_histogram_name; | 70 return adjusted_histogram_name; |
| 67 } | 71 } |
| 68 | 72 |
| 69 void RecordErrorCauseUMA(const ClientId& client_id, net::Error error_code) { | 73 void RecordErrorCauseUMA(const ClientId& client_id, net::Error error_code) { |
| 70 UMA_HISTOGRAM_SPARSE_SLOWLY( | 74 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 71 AddHistogramSuffix(client_id, | 75 AddHistogramSuffix(client_id, |
| 72 "OfflinePages.Background.BackgroundLoadingFailedCode"), | 76 "OfflinePages.Background.BackgroundLoadingFailedCode"), |
| 73 std::abs(error_code)); | 77 std::abs(error_code)); |
| 74 } | 78 } |
| 75 | 79 |
| 80 void RecordOffliningPreviewsUMA(const ClientId& client_id, |
| 81 ChromeNavigationData* navigation_data) { |
| 82 content::PreviewsState previews_state = content::PreviewsTypes::PREVIEWS_OFF; |
| 83 if (navigation_data) |
| 84 previews_state = navigation_data->previews_state(); |
| 85 |
| 86 int is_previews_enabled = 0; |
| 87 bool lite_page_received = false; |
| 88 data_reduction_proxy::DataReductionProxyData* data_reduction_proxy_data = |
| 89 nullptr; |
| 90 if (navigation_data) |
| 91 data_reduction_proxy_data = navigation_data->GetDataReductionProxyData(); |
| 92 if (data_reduction_proxy_data) |
| 93 lite_page_received = data_reduction_proxy_data->lite_page_received(); |
| 94 |
| 95 if ((previews_state != content::PreviewsTypes::PREVIEWS_OFF && |
| 96 previews_state != content::PreviewsTypes::PREVIEWS_NO_TRANSFORM) || |
| 97 lite_page_received) |
| 98 is_previews_enabled = 1; |
| 99 |
| 100 base::UmaHistogramBoolean( |
| 101 AddHistogramSuffix(client_id, |
| 102 "OfflinePages.Background.OffliningPreviewStatus"), |
| 103 is_previews_enabled); |
| 104 } |
| 105 |
| 76 void HandleLoadTerminationCancel( | 106 void HandleLoadTerminationCancel( |
| 77 const Offliner::CompletionCallback& completion_callback, | 107 const Offliner::CompletionCallback& completion_callback, |
| 78 const SavePageRequest& canceled_request) { | 108 const SavePageRequest& canceled_request) { |
| 79 completion_callback.Run(canceled_request, | 109 completion_callback.Run(canceled_request, |
| 80 Offliner::RequestStatus::FOREGROUND_CANCELED); | 110 Offliner::RequestStatus::FOREGROUND_CANCELED); |
| 81 } | 111 } |
| 82 | 112 |
| 83 } // namespace | 113 } // namespace |
| 84 | 114 |
| 85 BackgroundLoaderOffliner::BackgroundLoaderOffliner( | 115 BackgroundLoaderOffliner::BackgroundLoaderOffliner( |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 RecordErrorCauseUMA(pending_request_->client_id(), | 334 RecordErrorCauseUMA(pending_request_->client_id(), |
| 305 navigation_handle->GetNetErrorCode()); | 335 navigation_handle->GetNetErrorCode()); |
| 306 switch (navigation_handle->GetNetErrorCode()) { | 336 switch (navigation_handle->GetNetErrorCode()) { |
| 307 case net::ERR_INTERNET_DISCONNECTED: | 337 case net::ERR_INTERNET_DISCONNECTED: |
| 308 page_load_state_ = DELAY_RETRY; | 338 page_load_state_ = DELAY_RETRY; |
| 309 break; | 339 break; |
| 310 default: | 340 default: |
| 311 page_load_state_ = RETRIABLE; | 341 page_load_state_ = RETRIABLE; |
| 312 } | 342 } |
| 313 } | 343 } |
| 344 |
| 345 // Record UMA if we are offlining a previvew instead of an unmodified page. |
| 346 // As documented in content/public/browser/navigation_handle.h, this |
| 347 // NavigationData is a clone of the NavigationData instance returned from |
| 348 // ResourceDispatcherHostDelegate::GetNavigationData during commit. |
| 349 // Because ChromeResourceDispatcherHostDelegate always returns a |
| 350 // ChromeNavigationData, it is safe to static_cast here. |
| 351 ChromeNavigationData* navigation_data = static_cast<ChromeNavigationData*>( |
| 352 navigation_handle->GetNavigationData()); |
| 353 |
| 354 RecordOffliningPreviewsUMA(pending_request_->client_id(), navigation_data); |
| 314 } | 355 } |
| 315 | 356 |
| 316 void BackgroundLoaderOffliner::SetSnapshotControllerForTest( | 357 void BackgroundLoaderOffliner::SetSnapshotControllerForTest( |
| 317 std::unique_ptr<SnapshotController> controller) { | 358 std::unique_ptr<SnapshotController> controller) { |
| 318 snapshot_controller_ = std::move(controller); | 359 snapshot_controller_ = std::move(controller); |
| 319 } | 360 } |
| 320 | 361 |
| 321 void BackgroundLoaderOffliner::OnNetworkBytesChanged(int64_t bytes) { | 362 void BackgroundLoaderOffliner::OnNetworkBytesChanged(int64_t bytes) { |
| 322 if (pending_request_ && save_state_ != SAVING) { | 363 if (pending_request_ && save_state_ != SAVING) { |
| 323 network_bytes_ += bytes; | 364 network_bytes_ += bytes; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 // Given the choice between int and double, we choose to implicitly convert to | 521 // Given the choice between int and double, we choose to implicitly convert to |
| 481 // a double since it maintains more precision (we can get a longer time in | 522 // a double since it maintains more precision (we can get a longer time in |
| 482 // milliseconds than we can with a 2 bit int, 53 bits vs 32). | 523 // milliseconds than we can with a 2 bit int, 53 bits vs 32). |
| 483 double delay = delay_so_far.InMilliseconds(); | 524 double delay = delay_so_far.InMilliseconds(); |
| 484 signal_data_.SetDouble(signal_name, delay); | 525 signal_data_.SetDouble(signal_name, delay); |
| 485 } | 526 } |
| 486 | 527 |
| 487 } // namespace offline_pages | 528 } // namespace offline_pages |
| 488 | 529 |
| 489 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData); | 530 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData); |
| OLD | NEW |