Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(796)

Side by Side Diff: chrome/browser/offline_pages/background_loader_offliner.cc

Issue 2916253002: Add UMA to determine how often we offline a page with previews. (Closed)
Patch Set: CR fixes per RyanSturm Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 = content::PreviewsTypes::PREVIEWS_OFF;
82 if (navigation_data)
83 previews_state = navigation_data->previews_state();
84
85 int is_previews_enabled = 0;
86 bool lite_page_received = false;
87 data_reduction_proxy::DataReductionProxyData* data_reduction_proxy_data =
88 nullptr;
89 if (navigation_data)
90 data_reduction_proxy_data = navigation_data->GetDataReductionProxyData();
91 if (data_reduction_proxy_data)
92 lite_page_received = data_reduction_proxy_data->lite_page_received();
93
94 if ((previews_state != content::PreviewsTypes::PREVIEWS_OFF &&
95 previews_state != content::PreviewsTypes::PREVIEWS_NO_TRANSFORM) ||
96 lite_page_received)
97 is_previews_enabled = 1;
98
99 UMA_HISTOGRAM_BOOLEAN(
Steven Holte 2017/06/07 22:24:46 Actually, you probably need to change this to not
Pete Williamson 2017/06/08 00:11:09 Done. Thanks for catching this!
100 AddHistogramSuffix(client_id,
101 "OfflinePages.Background.OffliningPreviewStatus"),
102 is_previews_enabled);
103 }
104
76 void HandleLoadTerminationCancel( 105 void HandleLoadTerminationCancel(
77 const Offliner::CompletionCallback& completion_callback, 106 const Offliner::CompletionCallback& completion_callback,
78 const SavePageRequest& canceled_request) { 107 const SavePageRequest& canceled_request) {
79 completion_callback.Run(canceled_request, 108 completion_callback.Run(canceled_request,
80 Offliner::RequestStatus::FOREGROUND_CANCELED); 109 Offliner::RequestStatus::FOREGROUND_CANCELED);
81 } 110 }
82 111
83 } // namespace 112 } // namespace
84 113
85 BackgroundLoaderOffliner::BackgroundLoaderOffliner( 114 BackgroundLoaderOffliner::BackgroundLoaderOffliner(
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 RecordErrorCauseUMA(pending_request_->client_id(), 333 RecordErrorCauseUMA(pending_request_->client_id(),
305 navigation_handle->GetNetErrorCode()); 334 navigation_handle->GetNetErrorCode());
306 switch (navigation_handle->GetNetErrorCode()) { 335 switch (navigation_handle->GetNetErrorCode()) {
307 case net::ERR_INTERNET_DISCONNECTED: 336 case net::ERR_INTERNET_DISCONNECTED:
308 page_load_state_ = DELAY_RETRY; 337 page_load_state_ = DELAY_RETRY;
309 break; 338 break;
310 default: 339 default:
311 page_load_state_ = RETRIABLE; 340 page_load_state_ = RETRIABLE;
312 } 341 }
313 } 342 }
343
344 // Record UMA if we are offlining a previvew instead of an unmodified page.
345 // As documented in content/public/browser/navigation_handle.h, this
346 // NavigationData is a clone of the NavigationData instance returned from
347 // ResourceDispatcherHostDelegate::GetNavigationData during commit.
348 // Because ChromeResourceDispatcherHostDelegate always returns a
349 // ChromeNavigationData, it is safe to static_cast here.
350 ChromeNavigationData* navigation_data = static_cast<ChromeNavigationData*>(
351 navigation_handle->GetNavigationData());
352
353 RecordOffliningPreviewsUMA(pending_request_->client_id(), navigation_data);
314 } 354 }
315 355
316 void BackgroundLoaderOffliner::SetSnapshotControllerForTest( 356 void BackgroundLoaderOffliner::SetSnapshotControllerForTest(
317 std::unique_ptr<SnapshotController> controller) { 357 std::unique_ptr<SnapshotController> controller) {
318 snapshot_controller_ = std::move(controller); 358 snapshot_controller_ = std::move(controller);
319 } 359 }
320 360
321 void BackgroundLoaderOffliner::OnNetworkBytesChanged(int64_t bytes) { 361 void BackgroundLoaderOffliner::OnNetworkBytesChanged(int64_t bytes) {
322 if (pending_request_ && save_state_ != SAVING) { 362 if (pending_request_ && save_state_ != SAVING) {
323 network_bytes_ += bytes; 363 network_bytes_ += bytes;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 // Given the choice between int and double, we choose to implicitly convert to 520 // 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 521 // 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). 522 // milliseconds than we can with a 2 bit int, 53 bits vs 32).
483 double delay = delay_so_far.InMilliseconds(); 523 double delay = delay_so_far.InMilliseconds();
484 signal_data_.SetDouble(signal_name, delay); 524 signal_data_.SetDouble(signal_name, delay);
485 } 525 }
486 526
487 } // namespace offline_pages 527 } // namespace offline_pages
488 528
489 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData); 529 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698