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

Side by Side Diff: chrome/test/chromedriver/net/sync_websocket_impl.cc

Issue 23542005: [chromedriver] Improve timeout behavior. Prompted by user who executes script on busy page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 7 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/chromedriver/net/sync_websocket_impl.h" 5 #include "chrome/test/chromedriver/net/sync_websocket_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 bool success = false; 65 bool success = false;
66 base::WaitableEvent event(false, false); 66 base::WaitableEvent event(false, false);
67 context_getter_->GetNetworkTaskRunner()->PostTask( 67 context_getter_->GetNetworkTaskRunner()->PostTask(
68 FROM_HERE, 68 FROM_HERE,
69 base::Bind(&SyncWebSocketImpl::Core::SendOnIO, 69 base::Bind(&SyncWebSocketImpl::Core::SendOnIO,
70 this, message, &success, &event)); 70 this, message, &success, &event));
71 event.Wait(); 71 event.Wait();
72 return success; 72 return success;
73 } 73 }
74 74
75 SyncWebSocket::StatusCode 75 SyncWebSocket::StatusCode SyncWebSocketImpl::Core::ReceiveNextMessage(
76 SyncWebSocketImpl::Core::ReceiveNextMessage(
77 std::string* message, 76 std::string* message,
78 const base::TimeDelta& timeout) { 77 const base::TimeDelta& timeout) {
79 base::AutoLock lock(lock_); 78 base::AutoLock lock(lock_);
80 base::TimeTicks deadline = base::TimeTicks::Now() + timeout; 79 base::TimeTicks deadline = base::TimeTicks::Now() + timeout;
80 base::TimeDelta next_wait = timeout;
81 while (received_queue_.empty() && is_connected_) { 81 while (received_queue_.empty() && is_connected_) {
82 base::TimeDelta delta = deadline - base::TimeTicks::Now(); 82 if (next_wait <= base::TimeDelta())
83 if (delta <= base::TimeDelta())
84 return SyncWebSocket::kTimeout; 83 return SyncWebSocket::kTimeout;
85 on_update_event_.TimedWait(delta); 84 on_update_event_.TimedWait(next_wait);
85 next_wait = deadline - base::TimeTicks::Now();
86 } 86 }
87 if (!is_connected_) 87 if (!is_connected_)
88 return SyncWebSocket::kDisconnected; 88 return SyncWebSocket::kDisconnected;
89 *message = received_queue_.front(); 89 *message = received_queue_.front();
90 received_queue_.pop_front(); 90 received_queue_.pop_front();
91 return SyncWebSocket::kOk; 91 return SyncWebSocket::kOk;
92 } 92 }
93 93
94 bool SyncWebSocketImpl::Core::HasNextMessage() { 94 bool SyncWebSocketImpl::Core::HasNextMessage() {
95 base::AutoLock lock(lock_); 95 base::AutoLock lock(lock_);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 145 }
146 146
147 void SyncWebSocketImpl::Core::OnDestruct() const { 147 void SyncWebSocketImpl::Core::OnDestruct() const {
148 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner = 148 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner =
149 context_getter_->GetNetworkTaskRunner(); 149 context_getter_->GetNetworkTaskRunner();
150 if (network_task_runner->BelongsToCurrentThread()) 150 if (network_task_runner->BelongsToCurrentThread())
151 delete this; 151 delete this;
152 else 152 else
153 network_task_runner->DeleteSoon(FROM_HERE, this); 153 network_task_runner->DeleteSoon(FROM_HERE, this);
154 } 154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698