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

Side by Side Diff: chrome/browser/page_load_metrics/metrics_web_contents_observer.cc

Issue 2189543002: Notify page load metrics when the app enters the background. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@clankbackgroundcallback
Patch Set: fix histogram description Created 4 years, 4 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 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/page_load_metrics/metrics_web_contents_observer.h" 5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <ostream> 8 #include <ostream>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 const char kAbortChainSizeSameURL[] = 46 const char kAbortChainSizeSameURL[] =
47 "PageLoad.Internal.ProvisionalAbortChainSize.SameURL"; 47 "PageLoad.Internal.ProvisionalAbortChainSize.SameURL";
48 const char kAbortChainSizeNoCommit[] = 48 const char kAbortChainSizeNoCommit[] =
49 "PageLoad.Internal.ProvisionalAbortChainSize.NoCommit"; 49 "PageLoad.Internal.ProvisionalAbortChainSize.NoCommit";
50 const char kClientRedirectFirstPaintToNavigation[] = 50 const char kClientRedirectFirstPaintToNavigation[] =
51 "PageLoad.Internal.ClientRedirect.FirstPaintToNavigation"; 51 "PageLoad.Internal.ClientRedirect.FirstPaintToNavigation";
52 const char kClientRedirectWithoutPaint[] = 52 const char kClientRedirectWithoutPaint[] =
53 "PageLoad.Internal.ClientRedirect.NavigationWithoutPaint"; 53 "PageLoad.Internal.ClientRedirect.NavigationWithoutPaint";
54 const char kCommitToCompleteNoTimingIPCs[] = 54 const char kCommitToCompleteNoTimingIPCs[] =
55 "PageLoad.Internal.CommitToComplete.NoTimingIPCs"; 55 "PageLoad.Internal.CommitToComplete.NoTimingIPCs";
56 const char kPageLoadCompletedAfterAppBackground[] =
57 "PageLoad.Internal.PageLoadCompleted.AfterAppBackground";
56 58
57 } // namespace internal 59 } // namespace internal
58 60
59 namespace { 61 namespace {
60 62
61 // Helper to allow use of Optional<> values in LOG() messages. 63 // Helper to allow use of Optional<> values in LOG() messages.
62 std::ostream& operator<<(std::ostream& os, 64 std::ostream& operator<<(std::ostream& os,
63 const base::Optional<base::TimeDelta>& opt) { 65 const base::Optional<base::TimeDelta>& opt) {
64 if (opt) 66 if (opt)
65 os << opt.value(); 67 os << opt.value();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 return false; 182 return false;
181 } 183 }
182 184
183 return true; 185 return true;
184 } 186 }
185 187
186 void RecordInternalError(InternalErrorLoadEvent event) { 188 void RecordInternalError(InternalErrorLoadEvent event) {
187 UMA_HISTOGRAM_ENUMERATION(internal::kErrorEvents, event, ERR_LAST_ENTRY); 189 UMA_HISTOGRAM_ENUMERATION(internal::kErrorEvents, event, ERR_LAST_ENTRY);
188 } 190 }
189 191
192 void RecordAppBackgroundPageLoadCompleted(bool completed_after_background) {
193 UMA_HISTOGRAM_BOOLEAN(internal::kPageLoadCompletedAfterAppBackground,
194 completed_after_background);
195 }
196
190 UserAbortType AbortTypeForPageTransition(ui::PageTransition transition) { 197 UserAbortType AbortTypeForPageTransition(ui::PageTransition transition) {
191 if (ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD)) 198 if (ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD))
192 return ABORT_RELOAD; 199 return ABORT_RELOAD;
193 if (transition & ui::PAGE_TRANSITION_FORWARD_BACK) 200 if (transition & ui::PAGE_TRANSITION_FORWARD_BACK)
194 return ABORT_FORWARD_BACK; 201 return ABORT_FORWARD_BACK;
195 if (ui::PageTransitionIsNewNavigation(transition)) 202 if (ui::PageTransitionIsNewNavigation(transition))
196 return ABORT_NEW_NAVIGATION; 203 return ABORT_NEW_NAVIGATION;
197 NOTREACHED() 204 NOTREACHED()
198 << "AbortTypeForPageTransition received unexpected ui::PageTransition: " 205 << "AbortTypeForPageTransition received unexpected ui::PageTransition: "
199 << transition; 206 << transition;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } // namespace 247 } // namespace
241 248
242 PageLoadTracker::PageLoadTracker( 249 PageLoadTracker::PageLoadTracker(
243 bool in_foreground, 250 bool in_foreground,
244 PageLoadMetricsEmbedderInterface* embedder_interface, 251 PageLoadMetricsEmbedderInterface* embedder_interface,
245 const GURL& currently_committed_url, 252 const GURL& currently_committed_url,
246 content::NavigationHandle* navigation_handle, 253 content::NavigationHandle* navigation_handle,
247 int aborted_chain_size, 254 int aborted_chain_size,
248 int aborted_chain_size_same_url) 255 int aborted_chain_size_same_url)
249 : did_stop_tracking_(false), 256 : did_stop_tracking_(false),
257 app_entered_background_(false),
250 navigation_start_(navigation_handle->NavigationStart()), 258 navigation_start_(navigation_handle->NavigationStart()),
251 url_(navigation_handle->GetURL()), 259 url_(navigation_handle->GetURL()),
252 abort_type_(ABORT_NONE), 260 abort_type_(ABORT_NONE),
253 started_in_foreground_(in_foreground), 261 started_in_foreground_(in_foreground),
254 aborted_chain_size_(aborted_chain_size), 262 aborted_chain_size_(aborted_chain_size),
255 aborted_chain_size_same_url_(aborted_chain_size_same_url), 263 aborted_chain_size_same_url_(aborted_chain_size_same_url),
256 embedder_interface_(embedder_interface) { 264 embedder_interface_(embedder_interface) {
257 DCHECK(!navigation_handle->HasCommitted()); 265 DCHECK(!navigation_handle->HasCommitted());
258 embedder_interface_->RegisterObservers(this); 266 embedder_interface_->RegisterObservers(this);
259 for (const auto& observer : observers_) { 267 for (const auto& observer : observers_) {
260 observer->OnStart(navigation_handle, currently_committed_url, 268 observer->OnStart(navigation_handle, currently_committed_url,
261 started_in_foreground_); 269 started_in_foreground_);
262 } 270 }
263 } 271 }
264 272
265 PageLoadTracker::~PageLoadTracker() { 273 PageLoadTracker::~PageLoadTracker() {
274 if (app_entered_background_) {
275 RecordAppBackgroundPageLoadCompleted(true);
276 }
277
266 if (did_stop_tracking_) 278 if (did_stop_tracking_)
267 return; 279 return;
268 280
269 if (commit_time_.is_null()) { 281 if (commit_time_.is_null()) {
270 if (!failed_provisional_load_info_) 282 if (!failed_provisional_load_info_)
271 RecordInternalError(ERR_NO_COMMIT_OR_FAILED_PROVISIONAL_LOAD); 283 RecordInternalError(ERR_NO_COMMIT_OR_FAILED_PROVISIONAL_LOAD);
272 284
273 // Recall that trackers that are given ABORT_UNKNOWN_NAVIGATION have their 285 // Recall that trackers that are given ABORT_UNKNOWN_NAVIGATION have their
274 // chain length added to the next navigation. Take care not to double count 286 // chain length added to the next navigation. Take care not to double count
275 // them. Also do not double count committed loads, which call this already. 287 // them. Also do not double count committed loads, which call this already.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 observer->OnRedirect(navigation_handle); 403 observer->OnRedirect(navigation_handle);
392 } 404 }
393 } 405 }
394 406
395 void PageLoadTracker::OnInputEvent(const blink::WebInputEvent& event) { 407 void PageLoadTracker::OnInputEvent(const blink::WebInputEvent& event) {
396 for (const auto& observer : observers_) { 408 for (const auto& observer : observers_) {
397 observer->OnUserInput(event); 409 observer->OnUserInput(event);
398 } 410 }
399 } 411 }
400 412
413 void PageLoadTracker::FlushMetricsOnAppEnterBackground() {
414 if (!app_entered_background_) {
415 RecordAppBackgroundPageLoadCompleted(false);
416 app_entered_background_ = true;
417 }
418 }
419
401 void PageLoadTracker::NotifyClientRedirectTo( 420 void PageLoadTracker::NotifyClientRedirectTo(
402 const PageLoadTracker& destination) { 421 const PageLoadTracker& destination) {
403 if (timing_.first_paint) { 422 if (timing_.first_paint) {
404 base::TimeTicks first_paint_time = 423 base::TimeTicks first_paint_time =
405 navigation_start() + timing_.first_paint.value(); 424 navigation_start() + timing_.first_paint.value();
406 base::TimeDelta first_paint_to_navigation; 425 base::TimeDelta first_paint_to_navigation;
407 if (destination.navigation_start() > first_paint_time) 426 if (destination.navigation_start() > first_paint_time)
408 first_paint_to_navigation = 427 first_paint_to_navigation =
409 destination.navigation_start() - first_paint_time; 428 destination.navigation_start() - first_paint_time;
410 PAGE_LOAD_HISTOGRAM(internal::kClientRedirectFirstPaintToNavigation, 429 PAGE_LOAD_HISTOGRAM(internal::kClientRedirectFirstPaintToNavigation,
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 void MetricsWebContentsObserver::OnInputEvent( 817 void MetricsWebContentsObserver::OnInputEvent(
799 const blink::WebInputEvent& event) { 818 const blink::WebInputEvent& event) {
800 // Ignore browser navigation or reload which comes with type Undefined. 819 // Ignore browser navigation or reload which comes with type Undefined.
801 if (event.type == blink::WebInputEvent::Type::Undefined) 820 if (event.type == blink::WebInputEvent::Type::Undefined)
802 return; 821 return;
803 822
804 if (committed_load_) 823 if (committed_load_)
805 committed_load_->OnInputEvent(event); 824 committed_load_->OnInputEvent(event);
806 } 825 }
807 826
827 void MetricsWebContentsObserver::FlushMetricsOnAppEnterBackground() {
828 if (committed_load_)
829 committed_load_->FlushMetricsOnAppEnterBackground();
830 for (const auto& kv : provisional_loads_) {
831 kv.second->FlushMetricsOnAppEnterBackground();
832 }
833 for (const auto& tracker : aborted_provisional_loads_) {
834 tracker->FlushMetricsOnAppEnterBackground();
835 }
836 }
837
808 void MetricsWebContentsObserver::DidRedirectNavigation( 838 void MetricsWebContentsObserver::DidRedirectNavigation(
809 content::NavigationHandle* navigation_handle) { 839 content::NavigationHandle* navigation_handle) {
810 if (!navigation_handle->IsInMainFrame()) 840 if (!navigation_handle->IsInMainFrame())
811 return; 841 return;
812 auto it = provisional_loads_.find(navigation_handle); 842 auto it = provisional_loads_.find(navigation_handle);
813 if (it == provisional_loads_.end()) 843 if (it == provisional_loads_.end())
814 return; 844 return;
815 it->second->Redirect(navigation_handle); 845 it->second->Redirect(navigation_handle);
816 } 846 }
817 847
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) 982 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage())
953 return false; 983 return false;
954 const std::string& mime_type = web_contents()->GetContentsMimeType(); 984 const std::string& mime_type = web_contents()->GetContentsMimeType();
955 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") 985 if (mime_type != "text/html" && mime_type != "application/xhtml+xml")
956 return false; 986 return false;
957 } 987 }
958 return true; 988 return true;
959 } 989 }
960 990
961 } // namespace page_load_metrics 991 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698