Commit 904a58d3 authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Move NavigationScheduler and WebSocketHandle timers to be per-frame

Bug: 
Change-Id: I92558b0137e7fc1159f5f7ed3648312645c283f5
Reviewed-on: https://chromium-review.googlesource.com/677493Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#503611}
parent 5b00f678
...@@ -6,8 +6,8 @@ frame "<!--framePath //<!--frame0-->-->" - didHandleOnloadEventsForFrame ...@@ -6,8 +6,8 @@ frame "<!--framePath //<!--frame0-->-->" - didHandleOnloadEventsForFrame
frame "<!--framePath //<!--frame0-->-->" - didFinishLoadForFrame frame "<!--framePath //<!--frame0-->-->" - didFinishLoadForFrame
main frame - didHandleOnloadEventsForFrame main frame - didHandleOnloadEventsForFrame
main frame - didFinishLoadForFrame main frame - didFinishLoadForFrame
ALERT: PASS: scheduled postMessage() before hashchange triggered.
frame "<!--framePath //<!--frame0-->-->" - didCommitLoadForFrame frame "<!--framePath //<!--frame0-->-->" - didCommitLoadForFrame
ALERT: PASS: scheduled postMessage() before hashchange triggered.
ALERT: PASS: hashchange triggered after postMessage(). ALERT: PASS: hashchange triggered after postMessage().
This tests that cross-origin fragment navigations are asynchronous. It does so by scheduling a postMessage before scheduling the navigation. If the navigation is synchronous, the frame load callback for the load's commit will happen before the message is handled. This isn't as flaky as it sounds, though it does rely on this postMessage behavior (which seems reasonable to do). This tests that cross-origin fragment navigations are asynchronous. It does so by scheduling a postMessage before scheduling the navigation. If the navigation is synchronous, the frame load callback for the load's commit will happen before the message is handled. This isn't as flaky as it sounds, though it does rely on this postMessage behavior (which seems reasonable to do).
......
...@@ -534,7 +534,7 @@ void NavigationScheduler::StartTimer() { ...@@ -534,7 +534,7 @@ void NavigationScheduler::StartTimer() {
// wrapWeakPersistent(this) is safe because a posted task is canceled when the // wrapWeakPersistent(this) is safe because a posted task is canceled when the
// task handle is destroyed on the dtor of this NavigationScheduler. // task handle is destroyed on the dtor of this NavigationScheduler.
navigate_task_handle_ = navigate_task_handle_ =
scheduler->LoadingTaskRunner()->PostDelayedCancellableTask( frame_->FrameScheduler()->LoadingTaskRunner()->PostDelayedCancellableTask(
BLINK_FROM_HERE, BLINK_FROM_HERE,
WTF::Bind(&NavigationScheduler::NavigateTask, WTF::Bind(&NavigationScheduler::NavigateTask,
WrapWeakPersistent(this)), WrapWeakPersistent(this)),
......
...@@ -246,10 +246,13 @@ bool DocumentWebSocketChannel::Connect(const KURL& url, ...@@ -246,10 +246,13 @@ bool DocumentWebSocketChannel::Connect(const KURL& url,
} }
handle_->Initialize(std::move(socket_ptr)); handle_->Initialize(std::move(socket_ptr));
handle_->Connect(url, protocols, handle_->Connect(
loading_context_->GetFetchContext()->GetSecurityOrigin(), url, protocols, loading_context_->GetFetchContext()->GetSecurityOrigin(),
loading_context_->GetFetchContext()->GetSiteForCookies(), loading_context_->GetFetchContext()->GetSiteForCookies(),
loading_context_->GetExecutionContext()->UserAgent(), this); loading_context_->GetExecutionContext()->UserAgent(), this,
TaskRunnerHelper::Get(TaskType::kNetworking,
loading_context_->GetExecutionContext())
.Get());
// TODO(ricea): Maybe lookup GetDocument()->GetFrame() less often? // TODO(ricea): Maybe lookup GetDocument()->GetFrame() less often?
if (handshake_throttle_ && GetDocument() && GetDocument()->GetFrame() && if (handshake_throttle_ && GetDocument() && GetDocument()->GetFrame() &&
......
...@@ -84,13 +84,14 @@ class MockWebSocketHandle : public WebSocketHandle { ...@@ -84,13 +84,14 @@ class MockWebSocketHandle : public WebSocketHandle {
DoInitialize(&websocket); DoInitialize(&websocket);
} }
MOCK_METHOD6(Connect, MOCK_METHOD7(Connect,
void(const KURL&, void(const KURL&,
const Vector<String>&, const Vector<String>&,
SecurityOrigin*, SecurityOrigin*,
const KURL&, const KURL&,
const String&, const String&,
WebSocketHandleClient*)); WebSocketHandleClient*,
WebTaskRunner*));
MOCK_METHOD4(Send, MOCK_METHOD4(Send,
void(bool, WebSocketHandle::MessageType, const char*, size_t)); void(bool, WebSocketHandle::MessageType, const char*, size_t));
MOCK_METHOD1(FlowControl, void(int64_t)); MOCK_METHOD1(FlowControl, void(int64_t));
...@@ -162,7 +163,7 @@ class DocumentWebSocketChannelTest : public ::testing::Test { ...@@ -162,7 +163,7 @@ class DocumentWebSocketChannelTest : public ::testing::Test {
InSequence s; InSequence s;
EXPECT_CALL(*Handle(), DoInitialize(_)); EXPECT_CALL(*Handle(), DoInitialize(_));
EXPECT_CALL(*Handle(), Connect(KURL(NullURL(), "ws://localhost/"), _, _, EXPECT_CALL(*Handle(), Connect(KURL(NullURL(), "ws://localhost/"), _, _,
_, _, HandleClient())); _, _, HandleClient(), _));
EXPECT_CALL(*Handle(), FlowControl(65536)); EXPECT_CALL(*Handle(), FlowControl(65536));
EXPECT_CALL(*ChannelClient(), DidConnect(String("a"), String("b"))); EXPECT_CALL(*ChannelClient(), DidConnect(String("a"), String("b")));
} }
...@@ -213,7 +214,7 @@ TEST_F(DocumentWebSocketChannelTest, connectSuccess) { ...@@ -213,7 +214,7 @@ TEST_F(DocumentWebSocketChannelTest, connectSuccess) {
EXPECT_CALL(*Handle(), DoInitialize(_)); EXPECT_CALL(*Handle(), DoInitialize(_));
EXPECT_CALL(*Handle(), EXPECT_CALL(*Handle(),
Connect(KURLEq("ws://localhost/"), _, _, Connect(KURLEq("ws://localhost/"), _, _,
KURLEq("http://example.com/"), _, HandleClient())) KURLEq("http://example.com/"), _, HandleClient(), _))
.WillOnce(DoAll(SaveArg<1>(&protocols), SaveArg<2>(&origin))); .WillOnce(DoAll(SaveArg<1>(&protocols), SaveArg<2>(&origin)));
EXPECT_CALL(*Handle(), FlowControl(65536)); EXPECT_CALL(*Handle(), FlowControl(65536));
EXPECT_CALL(checkpoint, Call(1)); EXPECT_CALL(checkpoint, Call(1));
...@@ -822,7 +823,7 @@ class DocumentWebSocketChannelHandshakeThrottleTest ...@@ -822,7 +823,7 @@ class DocumentWebSocketChannelHandshakeThrottleTest
// non-null throttle. // non-null throttle.
void NormalHandshakeExpectations() { void NormalHandshakeExpectations() {
EXPECT_CALL(*Handle(), DoInitialize(_)); EXPECT_CALL(*Handle(), DoInitialize(_));
EXPECT_CALL(*Handle(), Connect(_, _, _, _, _, _)); EXPECT_CALL(*Handle(), Connect(_, _, _, _, _, _, _));
EXPECT_CALL(*Handle(), FlowControl(_)); EXPECT_CALL(*Handle(), FlowControl(_));
EXPECT_CALL(*handshake_throttle_, ThrottleHandshake(_, _, _)); EXPECT_CALL(*handshake_throttle_, ThrottleHandshake(_, _, _));
} }
...@@ -832,7 +833,7 @@ class DocumentWebSocketChannelHandshakeThrottleTest ...@@ -832,7 +833,7 @@ class DocumentWebSocketChannelHandshakeThrottleTest
TEST_F(DocumentWebSocketChannelHandshakeThrottleTest, ThrottleArguments) { TEST_F(DocumentWebSocketChannelHandshakeThrottleTest, ThrottleArguments) {
EXPECT_CALL(*Handle(), DoInitialize(_)); EXPECT_CALL(*Handle(), DoInitialize(_));
EXPECT_CALL(*Handle(), Connect(_, _, _, _, _, _)); EXPECT_CALL(*Handle(), Connect(_, _, _, _, _, _, _));
EXPECT_CALL(*Handle(), FlowControl(_)); EXPECT_CALL(*Handle(), FlowControl(_));
EXPECT_CALL(*handshake_throttle_, EXPECT_CALL(*handshake_throttle_,
ThrottleHandshake(WebURL(url()), _, WebCallbacks())); ThrottleHandshake(WebURL(url()), _, WebCallbacks()));
......
...@@ -41,6 +41,7 @@ namespace blink { ...@@ -41,6 +41,7 @@ namespace blink {
class KURL; class KURL;
class SecurityOrigin; class SecurityOrigin;
class WebSocketHandleClient; class WebSocketHandleClient;
class WebTaskRunner;
// WebSocketHandle is an interface class designed to be a handle of WebSocket // WebSocketHandle is an interface class designed to be a handle of WebSocket
// connection. WebSocketHandle will be used together with // connection. WebSocketHandle will be used together with
...@@ -66,7 +67,8 @@ class WebSocketHandle { ...@@ -66,7 +67,8 @@ class WebSocketHandle {
SecurityOrigin*, SecurityOrigin*,
const KURL& site_for_cookies, const KURL& site_for_cookies,
const String& user_agent_override, const String& user_agent_override,
WebSocketHandleClient*) = 0; WebSocketHandleClient*,
WebTaskRunner*) = 0;
virtual void Send(bool fin, MessageType, const char* data, size_t) = 0; virtual void Send(bool fin, MessageType, const char* data, size_t) = 0;
virtual void FlowControl(int64_t quota) = 0; virtual void FlowControl(int64_t quota) = 0;
virtual void Close(unsigned short code, const String& reason) = 0; virtual void Close(unsigned short code, const String& reason) = 0;
......
...@@ -50,7 +50,8 @@ void WebSocketHandleImpl::Connect(const KURL& url, ...@@ -50,7 +50,8 @@ void WebSocketHandleImpl::Connect(const KURL& url,
SecurityOrigin* origin, SecurityOrigin* origin,
const KURL& site_for_cookies, const KURL& site_for_cookies,
const String& user_agent_override, const String& user_agent_override,
WebSocketHandleClient* client) { WebSocketHandleClient* client,
WebTaskRunner* task_runner) {
DCHECK(websocket_); DCHECK(websocket_);
NETWORK_DVLOG(1) << this << " connect(" << url.GetString() << ", " NETWORK_DVLOG(1) << this << " connect(" << url.GetString() << ", "
...@@ -61,12 +62,8 @@ void WebSocketHandleImpl::Connect(const KURL& url, ...@@ -61,12 +62,8 @@ void WebSocketHandleImpl::Connect(const KURL& url,
client_ = client; client_ = client;
mojom::blink::WebSocketClientPtr client_proxy; mojom::blink::WebSocketClientPtr client_proxy;
client_binding_.Bind( client_binding_.Bind(mojo::MakeRequest(
mojo::MakeRequest(&client_proxy, Platform::Current() &client_proxy, task_runner->ToSingleThreadTaskRunner()));
->CurrentThread()
->Scheduler()
->LoadingTaskRunner()
->ToSingleThreadTaskRunner()));
websocket_->AddChannelRequest( websocket_->AddChannelRequest(
url, protocols, origin, site_for_cookies, url, protocols, origin, site_for_cookies,
user_agent_override.IsNull() ? g_empty_string : user_agent_override, user_agent_override.IsNull() ? g_empty_string : user_agent_override,
......
...@@ -49,7 +49,8 @@ class WebSocketHandleImpl : public WebSocketHandle, ...@@ -49,7 +49,8 @@ class WebSocketHandleImpl : public WebSocketHandle,
SecurityOrigin*, SecurityOrigin*,
const KURL& site_for_cookies, const KURL& site_for_cookies,
const String& user_agent_override, const String& user_agent_override,
WebSocketHandleClient*) override; WebSocketHandleClient*,
WebTaskRunner*) override;
void Send(bool fin, MessageType, const char* data, size_t) override; void Send(bool fin, MessageType, const char* data, size_t) override;
void FlowControl(int64_t quota) override; void FlowControl(int64_t quota) override;
void Close(unsigned short code, const String& reason) override; void Close(unsigned short code, const String& reason) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment