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

Unified Diff: components/page_load_metrics/browser/page_load_metrics_util.cc

Issue 1837233002: Optional <TimeDelta> since they may be non existent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased, Fixed non-deterministic tests and Bryan's review comments. Created 4 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 side-by-side diff with in-line comments
Download patch
Index: components/page_load_metrics/browser/page_load_metrics_util.cc
diff --git a/components/page_load_metrics/browser/page_load_metrics_util.cc b/components/page_load_metrics/browser/page_load_metrics_util.cc
index a9ead770ea308b064e88f1d5c375dadb6f5d5e95..127aca0c507245e85bf4f8a8578b8f9d3a44da86 100644
--- a/components/page_load_metrics/browser/page_load_metrics_util.cc
+++ b/components/page_load_metrics/browser/page_load_metrics_util.cc
@@ -14,8 +14,22 @@ namespace page_load_metrics {
bool WasStartedInForegroundEventInForeground(base::TimeDelta event,
const PageLoadExtraInfo& info) {
return info.started_in_foreground && !event.is_zero() &&
- (info.first_background_time.is_zero() ||
- event < info.first_background_time);
+ (!info.first_background_time ||
+ event <= info.first_background_time.value());
+}
+
+// TODO (@shivanisha) Since the above function is called for
Charlie Harrison 2016/05/19 18:20:49 "TODO(shivanisha):" Is the preferred syntax.
+// TimeDelta coming over IPC (PageLoadTiming) and since Optional is not
Charlie Harrison 2016/05/19 18:20:49 This sentence is a little awkward. What about: "T
shivanisha 2016/05/23 15:06:44 sounds good. done
+// currently supported in IPC, thus creating another function.
+// They should ideally converge to one function in the future
+// when either the serialization framework supports Optional or we send
+// actual timestamps over IPC and compute deltas in browser process.
+bool WasStartedInForegroundOptionalEventInForeground(
+ const base::Optional<base::TimeDelta>& event,
+ const PageLoadExtraInfo& info) {
+ return info.started_in_foreground && event &&
+ (!info.first_background_time ||
+ event.value() <= info.first_background_time.value());
}
bool WasParseInForeground(base::TimeDelta parse_start,
@@ -24,9 +38,9 @@ bool WasParseInForeground(base::TimeDelta parse_start,
if (parse_start.is_zero()) {
return false;
}
- const bool incomplete_parse_in_foreground =
- parse_stop.is_zero() && info.started_in_foreground &&
- info.first_background_time.is_zero();
+ const bool incomplete_parse_in_foreground = parse_stop.is_zero() &&
+ info.started_in_foreground &&
+ !info.first_background_time;
return incomplete_parse_in_foreground ||
WasStartedInForegroundEventInForeground(parse_stop, info);

Powered by Google App Engine
This is Rietveld 408576698