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

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

Issue 2880323003: Various cleaups for AMP page load metrics. (Closed)
Patch Set: address comment Created 3 years, 7 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/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
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 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
46 bool WasStartedInForegroundOptionalEventInForeground( 87 bool WasStartedInForegroundOptionalEventInForeground(
47 const base::Optional<base::TimeDelta>& event, 88 const base::Optional<base::TimeDelta>& event,
48 const PageLoadExtraInfo& info) { 89 const PageLoadExtraInfo& info) {
49 return info.started_in_foreground && event && 90 return info.started_in_foreground && event &&
50 (!info.first_background_time || 91 (!info.first_background_time ||
51 event.value() <= info.first_background_time.value()); 92 event.value() <= info.first_background_time.value());
52 } 93 }
53 94
54 PageAbortInfo GetPageAbortInfo(const PageLoadExtraInfo& info) { 95 PageAbortInfo GetPageAbortInfo(const PageLoadExtraInfo& info) {
55 if (IsBackgroundAbort(info)) { 96 if (IsBackgroundAbort(info)) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 const page_load_metrics::PageLoadExtraInfo& info, 148 const page_load_metrics::PageLoadExtraInfo& info,
108 blink::WebLoadingBehaviorFlag behavior) { 149 blink::WebLoadingBehaviorFlag behavior) {
109 const int all_frame_loading_behavior_flags = 150 const int all_frame_loading_behavior_flags =
110 info.main_frame_metadata.behavior_flags | 151 info.main_frame_metadata.behavior_flags |
111 info.subframe_metadata.behavior_flags; 152 info.subframe_metadata.behavior_flags;
112 153
113 return (all_frame_loading_behavior_flags & behavior) != 0; 154 return (all_frame_loading_behavior_flags & behavior) != 0;
114 } 155 }
115 156
116 } // namespace page_load_metrics 157 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698