Update from https://crrev.com/327068
This rolls in //base, //build and //sandbox/linux and updates other
things to match, in particular:
*) Update build_v8.patch
*) Add junit, mockito and roboelectric to DEPS for android test rules
*) Update DEPS for grit
*) Fix up various GN files for os->target_os rename
*) Fix up a few places that were using //base/float_util to use std::isnan
*) Fix up a few places using ApiCompatibilityUtil to use Android SDK directly
as well as a few miscellaneous fixes.
Many portions based on ncbray's work in
https://codereview.chromium.org/1108173002/
R=ncbray@chromium.org
TBR=ncbray@chromium.org
Review URL: https://codereview.chromium.org/1124763003
diff --git a/base/synchronization/cancellation_flag.cc b/base/synchronization/cancellation_flag.cc
index ad3b551..ca5c0a8 100644
--- a/base/synchronization/cancellation_flag.cc
+++ b/base/synchronization/cancellation_flag.cc
@@ -19,4 +19,8 @@
return base::subtle::Acquire_Load(&flag_) != 0;
}
+void CancellationFlag::UnsafeResetForTesting() {
+ base::subtle::Release_Store(&flag_, 0);
+}
+
} // namespace base
diff --git a/base/synchronization/cancellation_flag.h b/base/synchronization/cancellation_flag.h
index 51a4def..0f0f08e 100644
--- a/base/synchronization/cancellation_flag.h
+++ b/base/synchronization/cancellation_flag.h
@@ -29,6 +29,11 @@
void Set();
bool IsSet() const; // Returns true iff the flag was set.
+ // For subtle reasons that may be different on different architectures,
+ // a different thread testing IsSet() may erroneously read 'true' after
+ // this method has been called.
+ void UnsafeResetForTesting();
+
private:
base::subtle::Atomic32 flag_;
#if !defined(NDEBUG)
diff --git a/base/synchronization/condition_variable_win.cc b/base/synchronization/condition_variable_win.cc
index 6dc4831..5f165c8 100644
--- a/base/synchronization/condition_variable_win.cc
+++ b/base/synchronization/condition_variable_win.cc
@@ -72,12 +72,12 @@
class WinVistaCondVar: public ConditionVarImpl {
public:
WinVistaCondVar(Lock* user_lock);
- ~WinVistaCondVar() {};
+ ~WinVistaCondVar() override {}
// Overridden from ConditionVarImpl.
- virtual void Wait() override;
- virtual void TimedWait(const TimeDelta& max_time) override;
- virtual void Broadcast() override;
- virtual void Signal() override;
+ void Wait() override;
+ void TimedWait(const TimeDelta& max_time) override;
+ void Broadcast() override;
+ void Signal() override;
private:
base::Lock& user_lock_;
@@ -127,12 +127,12 @@
class WinXPCondVar : public ConditionVarImpl {
public:
WinXPCondVar(Lock* user_lock);
- ~WinXPCondVar();
+ ~WinXPCondVar() override;
// Overridden from ConditionVarImpl.
- virtual void Wait() override;
- virtual void TimedWait(const TimeDelta& max_time) override;
- virtual void Broadcast() override;
- virtual void Signal() override;
+ void Wait() override;
+ void TimedWait(const TimeDelta& max_time) override;
+ void Broadcast() override;
+ void Signal() override;
// Define Event class that is used to form circularly linked lists.
// The list container is an element with NULL as its handle_ value.
diff --git a/base/synchronization/waitable_event_unittest.cc b/base/synchronization/waitable_event_unittest.cc
index abba935..be56cf1 100644
--- a/base/synchronization/waitable_event_unittest.cc
+++ b/base/synchronization/waitable_event_unittest.cc
@@ -73,29 +73,27 @@
class WaitableEventSignaler : public PlatformThread::Delegate {
public:
- WaitableEventSignaler(double seconds, WaitableEvent* ev)
- : seconds_(seconds),
- ev_(ev) {
+ WaitableEventSignaler(TimeDelta delay, WaitableEvent* event)
+ : delay_(delay),
+ event_(event) {
}
void ThreadMain() override {
- PlatformThread::Sleep(TimeDelta::FromSecondsD(seconds_));
- ev_->Signal();
+ PlatformThread::Sleep(delay_);
+ event_->Signal();
}
private:
- const double seconds_;
- WaitableEvent *const ev_;
+ const TimeDelta delay_;
+ WaitableEvent* event_;
};
+// Tests that a WaitableEvent can be safely deleted when |Wait| is done without
+// additional synchronization.
TEST(WaitableEventTest, WaitAndDelete) {
- // This test tests that if a WaitableEvent can be safely deleted
- // when |Wait| is done without additional synchrnization.
- // If this test crashes, it is a bug.
-
WaitableEvent* ev = new WaitableEvent(false, false);
- WaitableEventSignaler signaler(0.01, ev);
+ WaitableEventSignaler signaler(TimeDelta::FromMilliseconds(10), ev);
PlatformThreadHandle thread;
PlatformThread::Create(0, &signaler, &thread);
@@ -105,16 +103,14 @@
PlatformThread::Join(thread);
}
+// Tests that a WaitableEvent can be safely deleted when |WaitMany| is done
+// without additional synchronization.
TEST(WaitableEventTest, WaitMany) {
- // This test tests that if a WaitableEvent can be safely deleted
- // when |WaitMany| is done without additional synchrnization.
- // If this test crashes, it is a bug.
-
WaitableEvent* ev[5];
for (unsigned i = 0; i < 5; ++i)
ev[i] = new WaitableEvent(false, false);
- WaitableEventSignaler signaler(0.01, ev[2]);
+ WaitableEventSignaler signaler(TimeDelta::FromMilliseconds(10), ev[2]);
PlatformThreadHandle thread;
PlatformThread::Create(0, &signaler, &thread);
@@ -127,4 +123,28 @@
EXPECT_EQ(2u, index);
}
+// Tests that using TimeDelta::Max() on TimedWait() is not the same as passing
+// a timeout of 0. (crbug.com/465948)
+#if defined(OS_POSIX)
+// crbug.com/465948 not fixed yet.
+#define MAYBE_TimedWait DISABLED_TimedWait
+#else
+#define MAYBE_TimedWait TimedWait
+#endif
+TEST(WaitableEventTest, MAYBE_TimedWait) {
+ WaitableEvent* ev = new WaitableEvent(false, false);
+
+ TimeDelta thread_delay = TimeDelta::FromMilliseconds(10);
+ WaitableEventSignaler signaler(thread_delay, ev);
+ PlatformThreadHandle thread;
+ TimeTicks start = TimeTicks::Now();
+ PlatformThread::Create(0, &signaler, &thread);
+
+ ev->TimedWait(TimeDelta::Max());
+ EXPECT_GE(TimeTicks::Now() - start, thread_delay);
+ delete ev;
+
+ PlatformThread::Join(thread);
+}
+
} // namespace base
diff --git a/base/synchronization/waitable_event_watcher.h b/base/synchronization/waitable_event_watcher.h
index d4d8e77..eb51eff 100644
--- a/base/synchronization/waitable_event_watcher.h
+++ b/base/synchronization/waitable_event_watcher.h
@@ -92,7 +92,7 @@
private:
#if defined(OS_WIN)
- virtual void OnObjectSignaled(HANDLE h) override;
+ void OnObjectSignaled(HANDLE h) override;
win::ObjectWatcher watcher_;
#else
// Implementation of MessageLoop::DestructionObserver
diff --git a/base/synchronization/waitable_event_win.cc b/base/synchronization/waitable_event_win.cc
index 770c582..4db5627 100644
--- a/base/synchronization/waitable_event_win.cc
+++ b/base/synchronization/waitable_event_win.cc
@@ -4,10 +4,10 @@
#include "base/synchronization/waitable_event.h"
-#include <math.h>
#include <windows.h>
#include "base/logging.h"
+#include "base/numerics/safe_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
@@ -37,7 +37,7 @@
}
bool WaitableEvent::IsSignaled() {
- return TimedWait(TimeDelta::FromMilliseconds(0));
+ return TimedWait(TimeDelta());
}
void WaitableEvent::Wait() {
@@ -50,13 +50,13 @@
bool WaitableEvent::TimedWait(const TimeDelta& max_time) {
base::ThreadRestrictions::AssertWaitAllowed();
- DCHECK(max_time >= TimeDelta::FromMicroseconds(0));
- // Be careful here. TimeDelta has a precision of microseconds, but this API
- // is in milliseconds. If there are 5.5ms left, should the delay be 5 or 6?
- // It should be 6 to avoid returning too early.
- double timeout = ceil(max_time.InMillisecondsF());
- DWORD result = WaitForSingleObject(handle_.Get(),
- static_cast<DWORD>(timeout));
+ DCHECK_GE(max_time, TimeDelta());
+ // Truncate the timeout to milliseconds. The API specifies that this method
+ // can return in less than |max_time| (when returning false), as the argument
+ // is the maximum time that a caller is willing to wait.
+ DWORD timeout = saturated_cast<DWORD>(max_time.InMilliseconds());
+
+ DWORD result = WaitForSingleObject(handle_.Get(), timeout);
switch (result) {
case WAIT_OBJECT_0:
return true;