Fixit: Remove uses of To/FromInternalValue() in ui/...
Replaces non-serialization uses of To/FromInternalValue() with
reasonable alternatives. No behavior changes intended. In order to
accomplish this, a number of less-than-trivial changes changes were made
to adapt existing code:
1. Fixed display_link_mac.cc to use Mach time conversion function in
base::TimeTicks and to perform safer math around the interval
calculation by using base::CheckNumeric<int64_t>.
2. Added warning comments and extra checks around code in
window_android.cc and ozone/.../drm_device.cc where external modules are
providing time values that are supposed to be from the same clock as
base::TimeTicks.
3. Added base::TimeDelta as a supported Aura ClassProperty to avoid
burdening client code with the TimeDelta memory storage details.
4. Update ui.mojom.Event interface to let Mojo handle the TimeTicks type
rather than manually convert to/from int64_t in struct traits.
5. Fixed time plumbing in ozone/platform/drm/gpu/... to use
base::TimeTicks in Chromium-side code instead of tv_sec + tv_usec values
everywhere.
Bug: 634507
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Ie93037c636b3c196344c91d3cc489fed9b50df1d
Reviewed-on: https://chromium-review.googlesource.com/583868
Reviewed-by: Michael Spang <[email protected]>
Reviewed-by: Bo Liu <[email protected]>
Reviewed-by: calamity <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Daniel Nicoara <[email protected]>
Reviewed-by: ccameron chromium <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Cr-Commit-Position: refs/heads/master@{#489820}
diff --git a/ui/accelerated_widget_mac/display_link_mac.cc b/ui/accelerated_widget_mac/display_link_mac.cc
index a1d5b73..f74c509 100644
--- a/ui/accelerated_widget_mac/display_link_mac.cc
+++ b/ui/accelerated_widget_mac/display_link_mac.cc
@@ -8,6 +8,7 @@
#include "base/location.h"
#include "base/logging.h"
+#include "base/numerics/safe_conversions.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
@@ -153,10 +154,18 @@
return;
}
- timebase_ = base::TimeTicks::FromInternalValue(
- cv_time.hostTime / 1000);
- interval_ = base::TimeDelta::FromMicroseconds(
- 1000000 * static_cast<int64_t>(numerator) / denominator);
+ base::CheckedNumeric<int64_t> interval_us(base::Time::kMicrosecondsPerSecond);
+ interval_us *= numerator;
+ interval_us /= denominator;
+ if (!interval_us.IsValid()) {
+ LOG(DFATAL) << "Bailing due to overflow: "
+ << base::Time::kMicrosecondsPerSecond << " * " << numerator
+ << " / " << denominator;
+ return;
+ }
+
+ timebase_ = base::TimeTicks::FromMachAbsoluteTime(cv_time.hostTime);
+ interval_ = base::TimeDelta::FromMicroseconds(interval_us.ValueOrDie());
timebase_and_interval_valid_ = true;
// Don't restart the display link for 10 seconds.
@@ -218,4 +227,3 @@
DisplayLinkMac::display_map_ = LAZY_INSTANCE_INITIALIZER;
} // ui
-