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