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/common/page_load_metrics/page_load_timing.h" | 9 #include "chrome/common/page_load_metrics/page_load_timing.h" |
10 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | |
11 #include "url/gurl.h" | |
12 | 10 |
13 namespace page_load_metrics { | 11 namespace page_load_metrics { |
14 | 12 |
15 namespace { | 13 namespace { |
16 | 14 |
17 bool IsBackgroundAbort(const PageLoadExtraInfo& info) { | 15 bool IsBackgroundAbort(const PageLoadExtraInfo& info) { |
18 if (!info.started_in_foreground || !info.first_background_time) | 16 if (!info.started_in_foreground || !info.first_background_time) |
19 return false; | 17 return false; |
20 | 18 |
21 if (!info.page_end_time) | 19 if (!info.page_end_time) |
(...skipping 16 matching lines...) Expand all Loading... |
38 return ABORT_CLOSE; | 36 return ABORT_CLOSE; |
39 case END_OTHER: | 37 case END_OTHER: |
40 return ABORT_OTHER; | 38 return ABORT_OTHER; |
41 default: | 39 default: |
42 return ABORT_NONE; | 40 return ABORT_NONE; |
43 } | 41 } |
44 } | 42 } |
45 | 43 |
46 } // namespace | 44 } // namespace |
47 | 45 |
48 base::Optional<std::string> GetGoogleHostnamePrefix(const GURL& url) { | |
49 const size_t registry_length = | |
50 net::registry_controlled_domains::GetRegistryLength( | |
51 url, | |
52 | |
53 // Do not include unknown registries (registries that don't have any | |
54 // matches in effective TLD names). | |
55 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | |
56 | |
57 // Do not include private registries, such as appspot.com. We don't | |
58 // want to match URLs like www.google.appspot.com. | |
59 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | |
60 | |
61 const base::StringPiece hostname = url.host_piece(); | |
62 if (registry_length == 0 || registry_length == std::string::npos || | |
63 registry_length >= hostname.length()) { | |
64 return base::Optional<std::string>(); | |
65 } | |
66 | |
67 // Removes the tld and the preceding dot. | |
68 const base::StringPiece hostname_minus_registry = | |
69 hostname.substr(0, hostname.length() - (registry_length + 1)); | |
70 | |
71 if (hostname_minus_registry == "google") | |
72 return std::string(""); | |
73 | |
74 if (!base::EndsWith(hostname_minus_registry, ".google", | |
75 base::CompareCase::INSENSITIVE_ASCII)) { | |
76 return base::Optional<std::string>(); | |
77 } | |
78 | |
79 return std::string(hostname_minus_registry.substr( | |
80 0, hostname_minus_registry.length() - strlen(".google"))); | |
81 } | |
82 | |
83 bool IsGoogleHostname(const GURL& url) { | |
84 return GetGoogleHostnamePrefix(url).has_value(); | |
85 } | |
86 | |
87 bool WasStartedInForegroundOptionalEventInForeground( | 46 bool WasStartedInForegroundOptionalEventInForeground( |
88 const base::Optional<base::TimeDelta>& event, | 47 const base::Optional<base::TimeDelta>& event, |
89 const PageLoadExtraInfo& info) { | 48 const PageLoadExtraInfo& info) { |
90 return info.started_in_foreground && event && | 49 return info.started_in_foreground && event && |
91 (!info.first_background_time || | 50 (!info.first_background_time || |
92 event.value() <= info.first_background_time.value()); | 51 event.value() <= info.first_background_time.value()); |
93 } | 52 } |
94 | 53 |
95 PageAbortInfo GetPageAbortInfo(const PageLoadExtraInfo& info) { | 54 PageAbortInfo GetPageAbortInfo(const PageLoadExtraInfo& info) { |
96 if (IsBackgroundAbort(info)) { | 55 if (IsBackgroundAbort(info)) { |
(...skipping 28 matching lines...) Expand all Loading... |
125 // where the Chrome app is backgrounded before the page load is complete, on | 84 // where the Chrome app is backgrounded before the page load is complete, on |
126 // platforms where Chrome may be killed once it goes into the background | 85 // platforms where Chrome may be killed once it goes into the background |
127 // (Android). In these cases, we use the app background time as the 'end | 86 // (Android). In these cases, we use the app background time as the 'end |
128 // time'. | 87 // time'. |
129 if (!time_on_page && !app_background_time.is_null()) { | 88 if (!time_on_page && !app_background_time.is_null()) { |
130 time_on_page = app_background_time - info.navigation_start; | 89 time_on_page = app_background_time - info.navigation_start; |
131 } | 90 } |
132 return time_on_page; | 91 return time_on_page; |
133 } | 92 } |
134 | 93 |
135 base::Optional<base::TimeDelta> OptionalMin( | |
136 const base::Optional<base::TimeDelta>& a, | |
137 const base::Optional<base::TimeDelta>& b) { | |
138 if (a && !b) | |
139 return a; | |
140 if (b && !a) | |
141 return b; | |
142 if (!a && !b) | |
143 return a; // doesn't matter which | |
144 return base::Optional<base::TimeDelta>(std::min(a.value(), b.value())); | |
145 } | |
146 | |
147 bool DidObserveLoadingBehaviorInAnyFrame( | 94 bool DidObserveLoadingBehaviorInAnyFrame( |
148 const page_load_metrics::PageLoadExtraInfo& info, | 95 const page_load_metrics::PageLoadExtraInfo& info, |
149 blink::WebLoadingBehaviorFlag behavior) { | 96 blink::WebLoadingBehaviorFlag behavior) { |
150 const int all_frame_loading_behavior_flags = | 97 const int all_frame_loading_behavior_flags = |
151 info.main_frame_metadata.behavior_flags | | 98 info.main_frame_metadata.behavior_flags | |
152 info.subframe_metadata.behavior_flags; | 99 info.subframe_metadata.behavior_flags; |
153 | 100 |
154 return (all_frame_loading_behavior_flags & behavior) != 0; | 101 return (all_frame_loading_behavior_flags & behavior) != 0; |
155 } | 102 } |
156 | 103 |
157 } // namespace page_load_metrics | 104 } // namespace page_load_metrics |
OLD | NEW |