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

Side by Side Diff: chrome/browser/automation/automation_util.cc

Issue 8212006: base::Bind: Cleanup in automation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mac build fix. Created 9 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/automation/automation_util.h" 5 #include "chrome/browser/automation/automation_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 TabContents* contents, 145 TabContents* contents,
146 int* value_size, 146 int* value_size,
147 std::string* value) { 147 std::string* value) {
148 *value_size = -1; 148 *value_size = -1;
149 if (url.is_valid() && contents) { 149 if (url.is_valid() && contents) {
150 scoped_refptr<net::URLRequestContextGetter> context_getter = 150 scoped_refptr<net::URLRequestContextGetter> context_getter =
151 GetRequestContext(contents); 151 GetRequestContext(contents);
152 base::WaitableEvent event(true /* manual reset */, 152 base::WaitableEvent event(true /* manual reset */,
153 false /* not initially signaled */); 153 false /* not initially signaled */);
154 CHECK(BrowserThread::PostTask( 154 CHECK(BrowserThread::PostTask(
155 BrowserThread::IO, FROM_HERE, 155 BrowserThread::IO, FROM_HERE,
156 NewRunnableFunction(&GetCookiesOnIOThread, 156 base::Bind(&GetCookiesOnIOThread, url, context_getter, &event, value)));
157 url, context_getter, &event, value)));
158 event.Wait(); 157 event.Wait();
159 158
160 *value_size = static_cast<int>(value->size()); 159 *value_size = static_cast<int>(value->size());
161 } 160 }
162 } 161 }
163 162
164 void SetCookie(const GURL& url, 163 void SetCookie(const GURL& url,
165 const std::string& value, 164 const std::string& value,
166 TabContents* contents, 165 TabContents* contents,
167 int* response_value) { 166 int* response_value) {
168 *response_value = -1; 167 *response_value = -1;
169 168
170 if (url.is_valid() && contents) { 169 if (url.is_valid() && contents) {
171 scoped_refptr<net::URLRequestContextGetter> context_getter = 170 scoped_refptr<net::URLRequestContextGetter> context_getter =
172 GetRequestContext(contents); 171 GetRequestContext(contents);
173 base::WaitableEvent event(true /* manual reset */, 172 base::WaitableEvent event(true /* manual reset */,
174 false /* not initially signaled */); 173 false /* not initially signaled */);
175 bool success = false; 174 bool success = false;
176 CHECK(BrowserThread::PostTask( 175 CHECK(BrowserThread::PostTask(
177 BrowserThread::IO, FROM_HERE, 176 BrowserThread::IO, FROM_HERE,
178 NewRunnableFunction(&SetCookieOnIOThread, 177 base::Bind(&SetCookieOnIOThread, url, value, context_getter, &event,
179 url, value, context_getter, &event, 178 &success)));
180 &success)));
181 event.Wait(); 179 event.Wait();
182 if (success) 180 if (success)
183 *response_value = 1; 181 *response_value = 1;
184 } 182 }
185 } 183 }
186 184
187 void DeleteCookie(const GURL& url, 185 void DeleteCookie(const GURL& url,
188 const std::string& cookie_name, 186 const std::string& cookie_name,
189 TabContents* contents, 187 TabContents* contents,
190 bool* success) { 188 bool* success) {
191 *success = false; 189 *success = false;
192 if (url.is_valid() && contents) { 190 if (url.is_valid() && contents) {
193 scoped_refptr<net::URLRequestContextGetter> context_getter = 191 scoped_refptr<net::URLRequestContextGetter> context_getter =
194 GetRequestContext(contents); 192 GetRequestContext(contents);
195 base::WaitableEvent event(true /* manual reset */, 193 base::WaitableEvent event(true /* manual reset */,
196 false /* not initially signaled */); 194 false /* not initially signaled */);
197 CHECK(BrowserThread::PostTask( 195 CHECK(BrowserThread::PostTask(
198 BrowserThread::IO, FROM_HERE, 196 BrowserThread::IO, FROM_HERE,
199 NewRunnableFunction(&DeleteCookieOnIOThread, 197 base::Bind(&DeleteCookieOnIOThread, url, cookie_name, context_getter,
200 url, cookie_name, context_getter, &event))); 198 &event)));
201 event.Wait(); 199 event.Wait();
202 *success = true; 200 *success = true;
203 } 201 }
204 } 202 }
205 203
206 void GetCookiesJSON(AutomationProvider* provider, 204 void GetCookiesJSON(AutomationProvider* provider,
207 DictionaryValue* args, 205 DictionaryValue* args,
208 IPC::Message* reply_message) { 206 IPC::Message* reply_message) {
209 AutomationJSONReply reply(provider, reply_message); 207 AutomationJSONReply reply(provider, reply_message);
210 std::string url; 208 std::string url;
211 if (!args->GetString("url", &url)) { 209 if (!args->GetString("url", &url)) {
212 reply.SendError("'url' missing or invalid"); 210 reply.SendError("'url' missing or invalid");
213 return; 211 return;
214 } 212 }
215 213
216 // Since we may be on the UI thread don't call GetURLRequestContext(). 214 // Since we may be on the UI thread don't call GetURLRequestContext().
217 scoped_refptr<net::URLRequestContextGetter> context_getter = 215 scoped_refptr<net::URLRequestContextGetter> context_getter =
218 provider->profile()->GetRequestContext(); 216 provider->profile()->GetRequestContext();
219 217
220 net::CookieList cookie_list; 218 net::CookieList cookie_list;
221 base::WaitableEvent event(true /* manual reset */, 219 base::WaitableEvent event(true /* manual reset */,
222 false /* not initially signaled */); 220 false /* not initially signaled */);
223 Task* task = NewRunnableFunction( 221 base::Closure task = base::Bind(&GetCanonicalCookiesOnIOThread, GURL(url),
224 &GetCanonicalCookiesOnIOThread, 222 context_getter, &event, &cookie_list);
225 GURL(url), context_getter, &event, &cookie_list);
226 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { 223 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) {
227 reply.SendError("Couldn't post task to get the cookies"); 224 reply.SendError("Couldn't post task to get the cookies");
228 return; 225 return;
229 } 226 }
230 event.Wait(); 227 event.Wait();
231 228
232 ListValue* list = new ListValue(); 229 ListValue* list = new ListValue();
233 for (size_t i = 0; i < cookie_list.size(); ++i) { 230 for (size_t i = 0; i < cookie_list.size(); ++i) {
234 const net::CookieMonster::CanonicalCookie& cookie = cookie_list[i]; 231 const net::CookieMonster::CanonicalCookie& cookie = cookie_list[i];
235 DictionaryValue* cookie_dict = new DictionaryValue(); 232 DictionaryValue* cookie_dict = new DictionaryValue();
(...skipping 25 matching lines...) Expand all
261 reply.SendError("'name' missing or invalid"); 258 reply.SendError("'name' missing or invalid");
262 return; 259 return;
263 } 260 }
264 261
265 // Since we may be on the UI thread don't call GetURLRequestContext(). 262 // Since we may be on the UI thread don't call GetURLRequestContext().
266 scoped_refptr<net::URLRequestContextGetter> context_getter = 263 scoped_refptr<net::URLRequestContextGetter> context_getter =
267 provider->profile()->GetRequestContext(); 264 provider->profile()->GetRequestContext();
268 265
269 base::WaitableEvent event(true /* manual reset */, 266 base::WaitableEvent event(true /* manual reset */,
270 false /* not initially signaled */); 267 false /* not initially signaled */);
271 Task* task = NewRunnableFunction( 268 base::Closure task = base::Bind(&DeleteCookieOnIOThread, GURL(url), name,
272 &DeleteCookieOnIOThread, 269 context_getter, &event);
273 GURL(url), name, context_getter, &event);
274 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { 270 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) {
275 reply.SendError("Couldn't post task to delete the cookie"); 271 reply.SendError("Couldn't post task to delete the cookie");
276 return; 272 return;
277 } 273 }
278 event.Wait(); 274 event.Wait();
279 reply.SendSuccess(NULL); 275 reply.SendSuccess(NULL);
280 } 276 }
281 277
282 void SetCookieJSON(AutomationProvider* provider, 278 void SetCookieJSON(AutomationProvider* provider,
283 DictionaryValue* args, 279 DictionaryValue* args,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 return; 347 return;
352 } 348 }
353 349
354 // Since we may be on the UI thread don't call GetURLRequestContext(). 350 // Since we may be on the UI thread don't call GetURLRequestContext().
355 scoped_refptr<net::URLRequestContextGetter> context_getter = 351 scoped_refptr<net::URLRequestContextGetter> context_getter =
356 provider->profile()->GetRequestContext(); 352 provider->profile()->GetRequestContext();
357 353
358 base::WaitableEvent event(true /* manual reset */, 354 base::WaitableEvent event(true /* manual reset */,
359 false /* not initially signaled */); 355 false /* not initially signaled */);
360 bool success = false; 356 bool success = false;
361 Task* task = NewRunnableFunction( 357 base::Closure task = base::Bind(
362 &SetCookieWithDetailsOnIOThread, 358 &SetCookieWithDetailsOnIOThread, GURL(url), *cookie.get(), domain,
363 GURL(url), *cookie.get(), domain, context_getter, &event, &success); 359 context_getter, &event, &success);
364 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { 360 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) {
365 reply.SendError("Couldn't post task to set the cookie"); 361 reply.SendError("Couldn't post task to set the cookie");
366 return; 362 return;
367 } 363 }
368 event.Wait(); 364 event.Wait();
369 365
370 if (!success) { 366 if (!success) {
371 reply.SendError("Could not set the cookie"); 367 reply.SendError("Could not set the cookie");
372 return; 368 return;
373 } 369 }
374 reply.SendSuccess(NULL); 370 reply.SendSuccess(NULL);
375 } 371 }
376 372
377 bool SendErrorIfModalDialogActive(AutomationProvider* provider, 373 bool SendErrorIfModalDialogActive(AutomationProvider* provider,
378 IPC::Message* message) { 374 IPC::Message* message) {
379 bool active = AppModalDialogQueue::GetInstance()->HasActiveDialog(); 375 bool active = AppModalDialogQueue::GetInstance()->HasActiveDialog();
380 if (active) { 376 if (active) {
381 AutomationJSONReply(provider, message).SendError( 377 AutomationJSONReply(provider, message).SendError(
382 "Command cannot be performed because a modal dialog is active"); 378 "Command cannot be performed because a modal dialog is active");
383 } 379 }
384 return active; 380 return active;
385 } 381 }
386 382
387 } // namespace automation_util 383 } // namespace automation_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698