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" | |
10 | 12 |
11 namespace page_load_metrics { | 13 namespace page_load_metrics { |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 bool IsBackgroundAbort(const PageLoadExtraInfo& info) { | 17 bool IsBackgroundAbort(const PageLoadExtraInfo& info) { |
16 if (!info.started_in_foreground || !info.first_background_time) | 18 if (!info.started_in_foreground || !info.first_background_time) |
17 return false; | 19 return false; |
18 | 20 |
19 if (!info.page_end_time) | 21 if (!info.page_end_time) |
(...skipping 16 matching lines...) Expand all Loading... | |
36 return ABORT_CLOSE; | 38 return ABORT_CLOSE; |
37 case END_OTHER: | 39 case END_OTHER: |
38 return ABORT_OTHER; | 40 return ABORT_OTHER; |
39 default: | 41 default: |
40 return ABORT_NONE; | 42 return ABORT_NONE; |
41 } | 43 } |
42 } | 44 } |
43 | 45 |
44 } // namespace | 46 } // namespace |
45 | 47 |
48 bool IsGoogleHostnameAndGetPrefix(const GURL& url, | |
RyanSturm
2017/05/15 20:42:06
nit: Thoughts on getting rid of the out param and
Bryan McQuade
2017/05/16 03:59:15
This is a great idea. I needed to change to option
| |
49 base::StringPiece* out_google_host_prefix) { | |
50 const size_t registry_length = | |
51 net::registry_controlled_domains::GetRegistryLength( | |
52 url, | |
53 | |
54 // Do not include unknown registries (registries that don't have any | |
55 // matches in effective TLD names). | |
56 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | |
57 | |
58 // Do not include private registries, such as appspot.com. We don't | |
59 // want to match URLs like www.google.appspot.com. | |
60 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | |
61 | |
62 const base::StringPiece hostname = url.host_piece(); | |
63 if (registry_length == 0 || registry_length == std::string::npos || | |
64 registry_length >= hostname.length()) | |
65 return false; | |
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 if (out_google_host_prefix) | |
73 *out_google_host_prefix = ""; | |
74 return true; | |
75 } | |
76 | |
77 if (!base::EndsWith(hostname_minus_registry, ".google", | |
78 base::CompareCase::INSENSITIVE_ASCII)) { | |
79 return false; | |
80 } | |
81 | |
82 if (out_google_host_prefix) { | |
83 *out_google_host_prefix = hostname_minus_registry.substr( | |
84 0, hostname_minus_registry.length() - strlen(".google")); | |
85 } | |
86 return true; | |
87 } | |
88 | |
89 bool IsGoogleHostname(const GURL& url) { | |
90 return IsGoogleHostnameAndGetPrefix(url, nullptr); | |
91 } | |
92 | |
46 bool WasStartedInForegroundOptionalEventInForeground( | 93 bool WasStartedInForegroundOptionalEventInForeground( |
47 const base::Optional<base::TimeDelta>& event, | 94 const base::Optional<base::TimeDelta>& event, |
48 const PageLoadExtraInfo& info) { | 95 const PageLoadExtraInfo& info) { |
49 return info.started_in_foreground && event && | 96 return info.started_in_foreground && event && |
50 (!info.first_background_time || | 97 (!info.first_background_time || |
51 event.value() <= info.first_background_time.value()); | 98 event.value() <= info.first_background_time.value()); |
52 } | 99 } |
53 | 100 |
54 PageAbortInfo GetPageAbortInfo(const PageLoadExtraInfo& info) { | 101 PageAbortInfo GetPageAbortInfo(const PageLoadExtraInfo& info) { |
55 if (IsBackgroundAbort(info)) { | 102 if (IsBackgroundAbort(info)) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 const page_load_metrics::PageLoadExtraInfo& info, | 154 const page_load_metrics::PageLoadExtraInfo& info, |
108 blink::WebLoadingBehaviorFlag behavior) { | 155 blink::WebLoadingBehaviorFlag behavior) { |
109 const int all_frame_loading_behavior_flags = | 156 const int all_frame_loading_behavior_flags = |
110 info.main_frame_metadata.behavior_flags | | 157 info.main_frame_metadata.behavior_flags | |
111 info.subframe_metadata.behavior_flags; | 158 info.subframe_metadata.behavior_flags; |
112 | 159 |
113 return (all_frame_loading_behavior_flags & behavior) != 0; | 160 return (all_frame_loading_behavior_flags & behavior) != 0; |
114 } | 161 } |
115 | 162 |
116 } // namespace page_load_metrics | 163 } // namespace page_load_metrics |
OLD | NEW |