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

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: 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"
16 #include "components/offline_pages/core/background/offliner_policy.h" 17 #include "components/offline_pages/core/background/offliner_policy.h"
17 #include "components/offline_pages/core/background/save_page_request.h" 18 #include "components/offline_pages/core/background/save_page_request.h"
18 #include "components/offline_pages/core/client_namespace_constants.h" 19 #include "components/offline_pages/core/client_namespace_constants.h"
19 #include "components/offline_pages/core/offline_page_feature.h" 20 #include "components/offline_pages/core/offline_page_feature.h"
20 #include "components/offline_pages/core/offline_page_model.h" 21 #include "components/offline_pages/core/offline_page_model.h"
21 #include "content/public/browser/browser_context.h" 22 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/mhtml_extra_parts.h" 23 #include "content/public/browser/mhtml_extra_parts.h"
23 #include "content/public/browser/navigation_handle.h" 24 #include "content/public/browser/navigation_handle.h"
24 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
26 #include "content/public/browser/web_contents_user_data.h" 27 #include "content/public/browser/web_contents_user_data.h"
28 #include "content/public/common/previews_state.h"
27 29
28 namespace offline_pages { 30 namespace offline_pages {
29 31
30 namespace { 32 namespace {
31 const char kContentType[] = "text/plain"; 33 const char kContentType[] = "text/plain";
32 const char kContentTransferEncodingBinary[] = 34 const char kContentTransferEncodingBinary[] =
33 "Content-Transfer-Encoding: binary"; 35 "Content-Transfer-Encoding: binary";
34 const char kXHeaderForSignals[] = "X-Chrome-Loading-Metrics-Data: 1"; 36 const char kXHeaderForSignals[] = "X-Chrome-Loading-Metrics-Data: 1";
35 37
36 class OfflinerData : public content::WebContentsUserData<OfflinerData> { 38 class OfflinerData : public content::WebContentsUserData<OfflinerData> {
(...skipping 29 matching lines...) Expand all
66 return adjusted_histogram_name; 68 return adjusted_histogram_name;
67 } 69 }
68 70
69 void RecordErrorCauseUMA(const ClientId& client_id, net::Error error_code) { 71 void RecordErrorCauseUMA(const ClientId& client_id, net::Error error_code) {
70 UMA_HISTOGRAM_SPARSE_SLOWLY( 72 UMA_HISTOGRAM_SPARSE_SLOWLY(
71 AddHistogramSuffix(client_id, 73 AddHistogramSuffix(client_id,
72 "OfflinePages.Background.BackgroundLoadingFailedCode"), 74 "OfflinePages.Background.BackgroundLoadingFailedCode"),
73 std::abs(error_code)); 75 std::abs(error_code));
74 } 76 }
75 77
78 void RecordOffliningPreviewsUMA(const ClientId& client_id,
79 content::PreviewsState previews_state) {
80 int previews_enabling = 0;
chili 2017/06/02 01:38:07 alternate names: preview_state_numeration? preview
Pete Williamson 2017/06/02 21:40:32 picked "is_previews_enabled"
81 if (previews_state != content::PreviewsTypes::PREVIEWS_OFF)
82 previews_enabling = 1;
83
84 UMA_HISTOGRAM_ENUMERATION(
85 AddHistogramSuffix(client_id,
86 "OfflinePages.Background.OffliningPreviewStatus"),
RyanSturm 2017/06/02 20:50:33 As a note, if you care about offline previews (whi
Pete Williamson 2017/06/02 21:40:32 Noted. I don't think we care about it.
87 previews_enabling, 2);
88 }
89
76 void HandleLoadTerminationCancel( 90 void HandleLoadTerminationCancel(
77 const Offliner::CompletionCallback& completion_callback, 91 const Offliner::CompletionCallback& completion_callback,
78 const SavePageRequest& canceled_request) { 92 const SavePageRequest& canceled_request) {
79 completion_callback.Run(canceled_request, 93 completion_callback.Run(canceled_request,
80 Offliner::RequestStatus::FOREGROUND_CANCELED); 94 Offliner::RequestStatus::FOREGROUND_CANCELED);
81 } 95 }
82 96
83 } // namespace 97 } // namespace
84 98
85 BackgroundLoaderOffliner::BackgroundLoaderOffliner( 99 BackgroundLoaderOffliner::BackgroundLoaderOffliner(
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 RecordErrorCauseUMA(pending_request_->client_id(), 318 RecordErrorCauseUMA(pending_request_->client_id(),
305 navigation_handle->GetNetErrorCode()); 319 navigation_handle->GetNetErrorCode());
306 switch (navigation_handle->GetNetErrorCode()) { 320 switch (navigation_handle->GetNetErrorCode()) {
307 case net::ERR_INTERNET_DISCONNECTED: 321 case net::ERR_INTERNET_DISCONNECTED:
308 page_load_state_ = DELAY_RETRY; 322 page_load_state_ = DELAY_RETRY;
309 break; 323 break;
310 default: 324 default:
311 page_load_state_ = RETRIABLE; 325 page_load_state_ = RETRIABLE;
312 } 326 }
313 } 327 }
328
329 // Record UMA if we are offlining a previvew instead of an unmodified page.
330 // TODO(petewil): Today ChromeNavigationData is the only subclass of
331 // NavigationData. What can I do to make sure new subclasses don't break
332 // this cast someday? Move previews_state() to the NavigationData interface?
333 // Use some form of RTTI to know what I have before I cast it?
Pete Williamson 2017/06/02 00:47:37 Reviewers: What is your preference here? I'm thi
chili 2017/06/02 01:38:07 I would make a function called IsAnyPreviewsEnable
RyanSturm 2017/06/02 20:50:33 So the basic idea is that Chrome will only ever im
RyanSturm 2017/06/02 20:56:29 Also, if you like, I would not be opposed to addin
RyanSturm 2017/06/02 20:57:56 Ooops: typo above: s/"ChromeNavigationData* Chrom
Pete Williamson 2017/06/02 21:40:32 Changed to static cast. Decided not to move the c
334 ChromeNavigationData* navigation_data =
335 reinterpret_cast<ChromeNavigationData*>(
336 navigation_handle->GetNavigationData());
337
338 content::PreviewsState previews_state = content::PreviewsTypes::PREVIEWS_OFF;
339 if (navigation_data)
340 previews_state = navigation_data->previews_state();
341
342 RecordOffliningPreviewsUMA(pending_request_->client_id(), previews_state);
314 } 343 }
315 344
316 void BackgroundLoaderOffliner::SetSnapshotControllerForTest( 345 void BackgroundLoaderOffliner::SetSnapshotControllerForTest(
317 std::unique_ptr<SnapshotController> controller) { 346 std::unique_ptr<SnapshotController> controller) {
318 snapshot_controller_ = std::move(controller); 347 snapshot_controller_ = std::move(controller);
319 } 348 }
320 349
321 void BackgroundLoaderOffliner::OnNetworkBytesChanged(int64_t bytes) { 350 void BackgroundLoaderOffliner::OnNetworkBytesChanged(int64_t bytes) {
322 if (pending_request_ && save_state_ != SAVING) { 351 if (pending_request_ && save_state_ != SAVING) {
323 network_bytes_ += bytes; 352 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 509 // 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 510 // 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). 511 // milliseconds than we can with a 2 bit int, 53 bits vs 32).
483 double delay = delay_so_far.InMilliseconds(); 512 double delay = delay_so_far.InMilliseconds();
484 signal_data_.SetDouble(signal_name, delay); 513 signal_data_.SetDouble(signal_name, delay);
485 } 514 }
486 515
487 } // namespace offline_pages 516 } // namespace offline_pages
488 517
489 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData); 518 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698