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

Unified Diff: cc/output/report_time_swap_promise.cc

Issue 2835763002: Use swap-promise to improve first* paint times (Closed)
Patch Set: remove printfs Created 3 years, 8 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: cc/output/report_time_swap_promise.cc
diff --git a/cc/output/report_time_swap_promise.cc b/cc/output/report_time_swap_promise.cc
new file mode 100644
index 0000000000000000000000000000000000000000..344368ce90695d01816b12ac0e61508f1e3bd821
--- /dev/null
+++ b/cc/output/report_time_swap_promise.cc
@@ -0,0 +1,41 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/output/report_time_swap_promise.h"
+#include "base/bind.h"
+#include "base/single_thread_task_runner.h"
+
+namespace cc {
+
+namespace {
+double MonotonicallyIncreasingTime() {
+ return base::TimeTicks::Now().ToInternalValue() /
+ static_cast<double>(base::Time::kMicrosecondsPerSecond);
+}
+}
+
+ReportTimeSwapPromise::ReportTimeSwapPromise(
+ ReportTimeCallback callback,
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
+ : callback_(callback), task_runner_(task_runner) {}
+
+ReportTimeSwapPromise::~ReportTimeSwapPromise() {}
+
+void ReportTimeSwapPromise::DidSwap() {
+ task_runner_->PostTask(
+ FROM_HERE,
+ base::BindOnce(callback_, true, MonotonicallyIncreasingTime()));
+}
+
+SwapPromise::DidNotSwapAction ReportTimeSwapPromise::DidNotSwap(
+ SwapPromise::DidNotSwapReason reason) {
+ task_runner_->PostTask(FROM_HERE, base::BindOnce(callback_, false, 0));
+ return SwapPromise::DidNotSwapAction::BREAK_PROMISE;
+}
+
+int64_t ReportTimeSwapPromise::TraceId() const {
+ return 0;
+}
+
+} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698