OLD | NEW |
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/browser/importer/firefox_importer_unittest_utils.h" | 5 #include "chrome/browser/importer/firefox_importer_unittest_utils.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 // A message_loop task that quits the message loop when invoked, setting cancel | 159 // A message_loop task that quits the message loop when invoked, setting cancel |
160 // causes the task to do nothing when invoked. | 160 // causes the task to do nothing when invoked. |
161 class CancellableQuitMsgLoop : public base::RefCounted<CancellableQuitMsgLoop> { | 161 class CancellableQuitMsgLoop : public base::RefCounted<CancellableQuitMsgLoop> { |
162 public: | 162 public: |
163 CancellableQuitMsgLoop() : cancelled_(false) {} | 163 CancellableQuitMsgLoop() : cancelled_(false) {} |
164 void QuitNow() { | 164 void QuitNow() { |
165 if (!cancelled_) | 165 if (!cancelled_) |
166 MessageLoop::current()->Quit(); | 166 MessageLoop::current()->Quit(); |
167 } | 167 } |
168 bool cancelled_; | 168 bool cancelled_; |
| 169 |
| 170 private: |
| 171 friend class base::RefCounted<CancellableQuitMsgLoop>; |
| 172 ~CancellableQuitMsgLoop() {} |
169 }; | 173 }; |
170 | 174 |
171 // Spin until either a client response arrives or a timeout occurs. | 175 // Spin until either a client response arrives or a timeout occurs. |
172 bool FFUnitTestDecryptorProxy::WaitForClientResponse() { | 176 bool FFUnitTestDecryptorProxy::WaitForClientResponse() { |
173 // What we're trying to do here is to wait for an RPC message to go over the | 177 // What we're trying to do here is to wait for an RPC message to go over the |
174 // wire and the client to reply. If the client does not reply by a given | 178 // wire and the client to reply. If the client does not reply by a given |
175 // timeout we kill the message loop. | 179 // timeout we kill the message loop. |
176 // The way we do this is to post a CancellableQuitMsgLoop for 3 seconds in | 180 // The way we do this is to post a CancellableQuitMsgLoop for 3 seconds in |
177 // the future and cancel it if an RPC message comes back earlier. | 181 // the future and cancel it if an RPC message comes back earlier. |
178 // This relies on the IPC listener class to quit the message loop itself when | 182 // This relies on the IPC listener class to quit the message loop itself when |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 269 |
266 IPC::Channel channel(kTestChannelID, IPC::Channel::MODE_CLIENT, &listener); | 270 IPC::Channel channel(kTestChannelID, IPC::Channel::MODE_CLIENT, &listener); |
267 CHECK(channel.Connect()); | 271 CHECK(channel.Connect()); |
268 listener.SetSender(&channel); | 272 listener.SetSender(&channel); |
269 | 273 |
270 // run message loop | 274 // run message loop |
271 MessageLoop::current()->Run(); | 275 MessageLoop::current()->Run(); |
272 | 276 |
273 return 0; | 277 return 0; |
274 } | 278 } |
OLD | NEW |