OLD | NEW |
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/page_load_metrics_util.h" | 5 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" | |
10 #include "chrome/common/page_load_metrics/page_load_timing.h" | 9 #include "chrome/common/page_load_metrics/page_load_timing.h" |
11 | 10 |
12 namespace page_load_metrics { | 11 namespace page_load_metrics { |
13 | 12 |
| 13 namespace { |
| 14 |
| 15 bool IsBackgroundAbort(const PageLoadExtraInfo& info) { |
| 16 if (!info.started_in_foreground || !info.first_background_time) |
| 17 return false; |
| 18 |
| 19 if (!info.page_end_time) |
| 20 return true; |
| 21 |
| 22 return info.first_background_time <= info.page_end_time; |
| 23 } |
| 24 |
| 25 PageAbortReason GetAbortReasonForEndReason(PageEndReason end_reason) { |
| 26 switch (end_reason) { |
| 27 case END_RELOAD: |
| 28 return ABORT_RELOAD; |
| 29 case END_FORWARD_BACK: |
| 30 return ABORT_FORWARD_BACK; |
| 31 case END_NEW_NAVIGATION: |
| 32 return ABORT_NEW_NAVIGATION; |
| 33 case END_STOP: |
| 34 return ABORT_STOP; |
| 35 case END_CLOSE: |
| 36 return ABORT_CLOSE; |
| 37 case END_OTHER: |
| 38 return ABORT_OTHER; |
| 39 default: |
| 40 return ABORT_NONE; |
| 41 } |
| 42 } |
| 43 |
| 44 } // namespace |
| 45 |
14 bool WasStartedInForegroundOptionalEventInForeground( | 46 bool WasStartedInForegroundOptionalEventInForeground( |
15 const base::Optional<base::TimeDelta>& event, | 47 const base::Optional<base::TimeDelta>& event, |
16 const PageLoadExtraInfo& info) { | 48 const PageLoadExtraInfo& info) { |
17 return info.started_in_foreground && event && | 49 return info.started_in_foreground && event && |
18 (!info.first_background_time || | 50 (!info.first_background_time || |
19 event.value() <= info.first_background_time.value()); | 51 event.value() <= info.first_background_time.value()); |
20 } | 52 } |
21 | 53 |
| 54 PageAbortInfo GetPageAbortInfo(const PageLoadExtraInfo& info) { |
| 55 if (IsBackgroundAbort(info)) { |
| 56 // Though most cases where a tab is backgrounded are user initiated, we |
| 57 // can't be certain that we were backgrounded due to a user action. For |
| 58 // example, on Android, the screen times out after a period of inactivity, |
| 59 // resulting in a non-user-initiated backgrounding. |
| 60 return {ABORT_BACKGROUND, UserInitiatedInfo::NotUserInitiated(), |
| 61 info.first_background_time.value()}; |
| 62 } |
| 63 |
| 64 PageAbortReason abort_reason = |
| 65 GetAbortReasonForEndReason(info.page_end_reason); |
| 66 if (abort_reason == ABORT_NONE) |
| 67 return PageAbortInfo(); |
| 68 |
| 69 return {abort_reason, info.page_end_user_initiated_info, |
| 70 info.page_end_time.value()}; |
| 71 } |
| 72 |
22 } // namespace page_load_metrics | 73 } // namespace page_load_metrics |
OLD | NEW |