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

Side by Side Diff: chrome/browser/importer/firefox_importer_unittest_utils_mac.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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 | Annotate | Revision Log
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/browser/importer/firefox_importer_unittest_utils.h" 5 #include "chrome/browser/importer/firefox_importer_unittest_utils.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 : got_result(false), sender_(NULL) {} 78 : got_result(false), sender_(NULL) {}
79 79
80 void SetSender(IPC::Sender* sender) { 80 void SetSender(IPC::Sender* sender) {
81 sender_ = sender; 81 sender_ = sender;
82 } 82 }
83 83
84 void OnInitDecryptorResponse(bool result) { 84 void OnInitDecryptorResponse(bool result) {
85 DCHECK(!got_result); 85 DCHECK(!got_result);
86 result_bool = result; 86 result_bool = result;
87 got_result = true; 87 got_result = true;
88 MessageLoop::current()->Quit(); 88 base::MessageLoop::current()->Quit();
89 } 89 }
90 90
91 void OnDecryptedTextResonse(const string16& decrypted_text) { 91 void OnDecryptedTextResonse(const string16& decrypted_text) {
92 DCHECK(!got_result); 92 DCHECK(!got_result);
93 result_string = decrypted_text; 93 result_string = decrypted_text;
94 got_result = true; 94 got_result = true;
95 MessageLoop::current()->Quit(); 95 base::MessageLoop::current()->Quit();
96 } 96 }
97 97
98 void QuitClient() { 98 void QuitClient() {
99 if (sender_) 99 if (sender_)
100 sender_->Send(new Msg_Decryptor_Quit()); 100 sender_->Send(new Msg_Decryptor_Quit());
101 } 101 }
102 102
103 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { 103 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE {
104 bool handled = true; 104 bool handled = true;
105 IPC_BEGIN_MESSAGE_MAP(FFDecryptorServerChannelListener, msg) 105 IPC_BEGIN_MESSAGE_MAP(FFDecryptorServerChannelListener, msg)
106 IPC_MESSAGE_HANDLER(Msg_Decryptor_InitReturnCode, OnInitDecryptorResponse) 106 IPC_MESSAGE_HANDLER(Msg_Decryptor_InitReturnCode, OnInitDecryptorResponse)
107 IPC_MESSAGE_HANDLER(Msg_Decryptor_Response, OnDecryptedTextResonse) 107 IPC_MESSAGE_HANDLER(Msg_Decryptor_Response, OnDecryptedTextResonse)
108 IPC_MESSAGE_UNHANDLED(handled = false) 108 IPC_MESSAGE_UNHANDLED(handled = false)
109 IPC_END_MESSAGE_MAP() 109 IPC_END_MESSAGE_MAP()
110 return handled; 110 return handled;
111 } 111 }
112 112
113 // If an error occured, just kill the message Loop. 113 // If an error occured, just kill the message Loop.
114 virtual void OnChannelError() OVERRIDE { 114 virtual void OnChannelError() OVERRIDE {
115 got_result = false; 115 got_result = false;
116 MessageLoop::current()->Quit(); 116 base::MessageLoop::current()->Quit();
117 } 117 }
118 118
119 // Results of IPC calls. 119 // Results of IPC calls.
120 string16 result_string; 120 string16 result_string;
121 bool result_bool; 121 bool result_bool;
122 // True if IPC call succeeded and data in above variables is valid. 122 // True if IPC call succeeded and data in above variables is valid.
123 bool got_result; 123 bool got_result;
124 124
125 private: 125 private:
126 IPC::Sender* sender_; // weak 126 IPC::Sender* sender_; // weak
127 }; 127 };
128 128
129 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() 129 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy()
130 : child_process_(0) { 130 : child_process_(0) {
131 } 131 }
132 132
133 bool FFUnitTestDecryptorProxy::Setup(const base::FilePath& nss_path) { 133 bool FFUnitTestDecryptorProxy::Setup(const base::FilePath& nss_path) {
134 // Create a new message loop and spawn the child process. 134 // Create a new message loop and spawn the child process.
135 message_loop_.reset(new MessageLoopForIO()); 135 message_loop_.reset(new base::MessageLoopForIO());
136 136
137 listener_.reset(new FFDecryptorServerChannelListener()); 137 listener_.reset(new FFDecryptorServerChannelListener());
138 channel_.reset(new IPC::Channel(kTestChannelID, 138 channel_.reset(new IPC::Channel(kTestChannelID,
139 IPC::Channel::MODE_SERVER, 139 IPC::Channel::MODE_SERVER,
140 listener_.get())); 140 listener_.get()));
141 CHECK(channel_->Connect()); 141 CHECK(channel_->Connect());
142 listener_->SetSender(channel_.get()); 142 listener_->SetSender(channel_.get());
143 143
144 // Spawn child and set up sync IPC connection. 144 // Spawn child and set up sync IPC connection.
145 bool ret = LaunchNSSDecrypterChildProcess(nss_path, 145 bool ret = LaunchNSSDecrypterChildProcess(nss_path,
(...skipping 12 matching lines...) Expand all
158 } 158 }
159 } 159 }
160 160
161 // A message_loop task that quits the message loop when invoked, setting cancel 161 // A message_loop task that quits the message loop when invoked, setting cancel
162 // causes the task to do nothing when invoked. 162 // causes the task to do nothing when invoked.
163 class CancellableQuitMsgLoop : public base::RefCounted<CancellableQuitMsgLoop> { 163 class CancellableQuitMsgLoop : public base::RefCounted<CancellableQuitMsgLoop> {
164 public: 164 public:
165 CancellableQuitMsgLoop() : cancelled_(false) {} 165 CancellableQuitMsgLoop() : cancelled_(false) {}
166 void QuitNow() { 166 void QuitNow() {
167 if (!cancelled_) 167 if (!cancelled_)
168 MessageLoop::current()->Quit(); 168 base::MessageLoop::current()->Quit();
169 } 169 }
170 bool cancelled_; 170 bool cancelled_;
171 171
172 private: 172 private:
173 friend class base::RefCounted<CancellableQuitMsgLoop>; 173 friend class base::RefCounted<CancellableQuitMsgLoop>;
174 ~CancellableQuitMsgLoop() {} 174 ~CancellableQuitMsgLoop() {}
175 }; 175 };
176 176
177 // Spin until either a client response arrives or a timeout occurs. 177 // Spin until either a client response arrives or a timeout occurs.
178 bool FFUnitTestDecryptorProxy::WaitForClientResponse() { 178 bool FFUnitTestDecryptorProxy::WaitForClientResponse() {
179 // What we're trying to do here is to wait for an RPC message to go over the 179 // What we're trying to do here is to wait for an RPC message to go over the
180 // wire and the client to reply. If the client does not reply by a given 180 // wire and the client to reply. If the client does not reply by a given
181 // timeout we kill the message loop. 181 // timeout we kill the message loop.
182 // The way we do this is to post a CancellableQuitMsgLoop for 3 seconds in 182 // The way we do this is to post a CancellableQuitMsgLoop for 3 seconds in
183 // the future and cancel it if an RPC message comes back earlier. 183 // the future and cancel it if an RPC message comes back earlier.
184 // This relies on the IPC listener class to quit the message loop itself when 184 // This relies on the IPC listener class to quit the message loop itself when
185 // a message comes in. 185 // a message comes in.
186 scoped_refptr<CancellableQuitMsgLoop> quit_task( 186 scoped_refptr<CancellableQuitMsgLoop> quit_task(
187 new CancellableQuitMsgLoop()); 187 new CancellableQuitMsgLoop());
188 MessageLoop::current()->PostDelayedTask( 188 base::MessageLoop::current()->PostDelayedTask(
189 FROM_HERE, 189 FROM_HERE,
190 base::Bind(&CancellableQuitMsgLoop::QuitNow, quit_task.get()), 190 base::Bind(&CancellableQuitMsgLoop::QuitNow, quit_task.get()),
191 TestTimeouts::action_max_timeout()); 191 TestTimeouts::action_max_timeout());
192 192
193 message_loop_->Run(); 193 message_loop_->Run();
194 bool ret = !quit_task->cancelled_; 194 bool ret = !quit_task->cancelled_;
195 quit_task->cancelled_ = false; 195 quit_task->cancelled_ = false;
196 return ret; 196 return ret;
197 } 197 }
198 198
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 bool ret = decryptor_.Init(dll_path, db_path); 234 bool ret = decryptor_.Init(dll_path, db_path);
235 sender_->Send(new Msg_Decryptor_InitReturnCode(ret)); 235 sender_->Send(new Msg_Decryptor_InitReturnCode(ret));
236 } 236 }
237 237
238 void OnDecrypt(std::string crypt) { 238 void OnDecrypt(std::string crypt) {
239 string16 unencrypted_str = decryptor_.Decrypt(crypt); 239 string16 unencrypted_str = decryptor_.Decrypt(crypt);
240 sender_->Send(new Msg_Decryptor_Response(unencrypted_str)); 240 sender_->Send(new Msg_Decryptor_Response(unencrypted_str));
241 } 241 }
242 242
243 void OnQuitRequest() { 243 void OnQuitRequest() {
244 MessageLoop::current()->Quit(); 244 base::MessageLoop::current()->Quit();
245 } 245 }
246 246
247 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { 247 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE {
248 bool handled = true; 248 bool handled = true;
249 IPC_BEGIN_MESSAGE_MAP(FFDecryptorClientChannelListener, msg) 249 IPC_BEGIN_MESSAGE_MAP(FFDecryptorClientChannelListener, msg)
250 IPC_MESSAGE_HANDLER(Msg_Decryptor_Init, OnDecryptor_Init) 250 IPC_MESSAGE_HANDLER(Msg_Decryptor_Init, OnDecryptor_Init)
251 IPC_MESSAGE_HANDLER(Msg_Decrypt, OnDecrypt) 251 IPC_MESSAGE_HANDLER(Msg_Decrypt, OnDecrypt)
252 IPC_MESSAGE_HANDLER(Msg_Decryptor_Quit, OnQuitRequest) 252 IPC_MESSAGE_HANDLER(Msg_Decryptor_Quit, OnQuitRequest)
253 IPC_MESSAGE_UNHANDLED(handled = false) 253 IPC_MESSAGE_UNHANDLED(handled = false)
254 IPC_END_MESSAGE_MAP() 254 IPC_END_MESSAGE_MAP()
255 return handled; 255 return handled;
256 } 256 }
257 257
258 virtual void OnChannelError() OVERRIDE { 258 virtual void OnChannelError() OVERRIDE {
259 MessageLoop::current()->Quit(); 259 base::MessageLoop::current()->Quit();
260 } 260 }
261 261
262 private: 262 private:
263 NSSDecryptor decryptor_; 263 NSSDecryptor decryptor_;
264 IPC::Sender* sender_; 264 IPC::Sender* sender_;
265 }; 265 };
266 266
267 // Entry function in child process. 267 // Entry function in child process.
268 MULTIPROCESS_IPC_TEST_MAIN(NSSDecrypterChildProcess) { 268 MULTIPROCESS_IPC_TEST_MAIN(NSSDecrypterChildProcess) {
269 MessageLoopForIO main_message_loop; 269 base::MessageLoopForIO main_message_loop;
270 FFDecryptorClientChannelListener listener; 270 FFDecryptorClientChannelListener listener;
271 271
272 IPC::Channel channel(kTestChannelID, IPC::Channel::MODE_CLIENT, &listener); 272 IPC::Channel channel(kTestChannelID, IPC::Channel::MODE_CLIENT, &listener);
273 CHECK(channel.Connect()); 273 CHECK(channel.Connect());
274 listener.SetSender(&channel); 274 listener.SetSender(&channel);
275 275
276 // run message loop 276 // run message loop
277 MessageLoop::current()->Run(); 277 base::MessageLoop::current()->Run();
278 278
279 return 0; 279 return 0;
280 } 280 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/firefox_importer_browsertest.cc ('k') | chrome/browser/importer/ie_importer_browsertest_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698