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

Side by Side Diff: chrome/browser/extensions/api/cookies/cookies_api.cc

Issue 216513002: Replace DCHECK(BrowserThread::CurrentlyOn) with DCHECK_CURRENTLY_ON in extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 // Implements the Chrome Extensions Cookies API. 5 // Implements the Chrome Extensions Cookies API.
6 6
7 #include "chrome/browser/extensions/api/cookies/cookies_api.h" 7 #include "chrome/browser/extensions/api/cookies/cookies_api.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 bool rv = BrowserThread::PostTask( 225 bool rv = BrowserThread::PostTask(
226 BrowserThread::IO, FROM_HERE, 226 BrowserThread::IO, FROM_HERE,
227 base::Bind(&CookiesGetFunction::GetCookieOnIOThread, this)); 227 base::Bind(&CookiesGetFunction::GetCookieOnIOThread, this));
228 DCHECK(rv); 228 DCHECK(rv);
229 229
230 // Will finish asynchronously. 230 // Will finish asynchronously.
231 return true; 231 return true;
232 } 232 }
233 233
234 void CookiesGetFunction::GetCookieOnIOThread() { 234 void CookiesGetFunction::GetCookieOnIOThread() {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 235 DCHECK_CURRENTLY_ON(BrowserThread::IO);
236 net::CookieStore* cookie_store = 236 net::CookieStore* cookie_store =
237 store_browser_context_->GetURLRequestContext()->cookie_store(); 237 store_browser_context_->GetURLRequestContext()->cookie_store();
238 cookies_helpers::GetCookieListFromStore( 238 cookies_helpers::GetCookieListFromStore(
239 cookie_store, url_, 239 cookie_store, url_,
240 base::Bind(&CookiesGetFunction::GetCookieCallback, this)); 240 base::Bind(&CookiesGetFunction::GetCookieCallback, this));
241 } 241 }
242 242
243 void CookiesGetFunction::GetCookieCallback(const net::CookieList& cookie_list) { 243 void CookiesGetFunction::GetCookieCallback(const net::CookieList& cookie_list) {
244 net::CookieList::const_iterator it; 244 net::CookieList::const_iterator it;
245 for (it = cookie_list.begin(); it != cookie_list.end(); ++it) { 245 for (it = cookie_list.begin(); it != cookie_list.end(); ++it) {
(...skipping 12 matching lines...) Expand all
258 if (it == cookie_list.end()) 258 if (it == cookie_list.end())
259 SetResult(base::Value::CreateNullValue()); 259 SetResult(base::Value::CreateNullValue());
260 260
261 bool rv = BrowserThread::PostTask( 261 bool rv = BrowserThread::PostTask(
262 BrowserThread::UI, FROM_HERE, 262 BrowserThread::UI, FROM_HERE,
263 base::Bind(&CookiesGetFunction::RespondOnUIThread, this)); 263 base::Bind(&CookiesGetFunction::RespondOnUIThread, this));
264 DCHECK(rv); 264 DCHECK(rv);
265 } 265 }
266 266
267 void CookiesGetFunction::RespondOnUIThread() { 267 void CookiesGetFunction::RespondOnUIThread() {
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 268 DCHECK_CURRENTLY_ON(BrowserThread::UI);
269 SendResponse(true); 269 SendResponse(true);
270 } 270 }
271 271
272 CookiesGetAllFunction::CookiesGetAllFunction() { 272 CookiesGetAllFunction::CookiesGetAllFunction() {
273 } 273 }
274 274
275 CookiesGetAllFunction::~CookiesGetAllFunction() { 275 CookiesGetAllFunction::~CookiesGetAllFunction() {
276 } 276 }
277 277
278 bool CookiesGetAllFunction::RunImpl() { 278 bool CookiesGetAllFunction::RunImpl() {
(...skipping 18 matching lines...) Expand all
297 bool rv = BrowserThread::PostTask( 297 bool rv = BrowserThread::PostTask(
298 BrowserThread::IO, FROM_HERE, 298 BrowserThread::IO, FROM_HERE,
299 base::Bind(&CookiesGetAllFunction::GetAllCookiesOnIOThread, this)); 299 base::Bind(&CookiesGetAllFunction::GetAllCookiesOnIOThread, this));
300 DCHECK(rv); 300 DCHECK(rv);
301 301
302 // Will finish asynchronously. 302 // Will finish asynchronously.
303 return true; 303 return true;
304 } 304 }
305 305
306 void CookiesGetAllFunction::GetAllCookiesOnIOThread() { 306 void CookiesGetAllFunction::GetAllCookiesOnIOThread() {
307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 307 DCHECK_CURRENTLY_ON(BrowserThread::IO);
308 net::CookieStore* cookie_store = 308 net::CookieStore* cookie_store =
309 store_browser_context_->GetURLRequestContext()->cookie_store(); 309 store_browser_context_->GetURLRequestContext()->cookie_store();
310 cookies_helpers::GetCookieListFromStore( 310 cookies_helpers::GetCookieListFromStore(
311 cookie_store, url_, 311 cookie_store, url_,
312 base::Bind(&CookiesGetAllFunction::GetAllCookiesCallback, this)); 312 base::Bind(&CookiesGetAllFunction::GetAllCookiesCallback, this));
313 } 313 }
314 314
315 void CookiesGetAllFunction::GetAllCookiesCallback( 315 void CookiesGetAllFunction::GetAllCookiesCallback(
316 const net::CookieList& cookie_list) { 316 const net::CookieList& cookie_list) {
317 const extensions::Extension* extension = GetExtension(); 317 const extensions::Extension* extension = GetExtension();
318 if (extension) { 318 if (extension) {
319 std::vector<linked_ptr<Cookie> > match_vector; 319 std::vector<linked_ptr<Cookie> > match_vector;
320 cookies_helpers::AppendMatchingCookiesToVector( 320 cookies_helpers::AppendMatchingCookiesToVector(
321 cookie_list, url_, &parsed_args_->details, 321 cookie_list, url_, &parsed_args_->details,
322 GetExtension(), &match_vector); 322 GetExtension(), &match_vector);
323 323
324 results_ = GetAll::Results::Create(match_vector); 324 results_ = GetAll::Results::Create(match_vector);
325 } 325 }
326 bool rv = BrowserThread::PostTask( 326 bool rv = BrowserThread::PostTask(
327 BrowserThread::UI, FROM_HERE, 327 BrowserThread::UI, FROM_HERE,
328 base::Bind(&CookiesGetAllFunction::RespondOnUIThread, this)); 328 base::Bind(&CookiesGetAllFunction::RespondOnUIThread, this));
329 DCHECK(rv); 329 DCHECK(rv);
330 } 330 }
331 331
332 void CookiesGetAllFunction::RespondOnUIThread() { 332 void CookiesGetAllFunction::RespondOnUIThread() {
333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 333 DCHECK_CURRENTLY_ON(BrowserThread::UI);
334 SendResponse(true); 334 SendResponse(true);
335 } 335 }
336 336
337 CookiesSetFunction::CookiesSetFunction() : success_(false) { 337 CookiesSetFunction::CookiesSetFunction() : success_(false) {
338 } 338 }
339 339
340 CookiesSetFunction::~CookiesSetFunction() { 340 CookiesSetFunction::~CookiesSetFunction() {
341 } 341 }
342 342
343 bool CookiesSetFunction::RunImpl() { 343 bool CookiesSetFunction::RunImpl() {
(...skipping 17 matching lines...) Expand all
361 bool rv = BrowserThread::PostTask( 361 bool rv = BrowserThread::PostTask(
362 BrowserThread::IO, FROM_HERE, 362 BrowserThread::IO, FROM_HERE,
363 base::Bind(&CookiesSetFunction::SetCookieOnIOThread, this)); 363 base::Bind(&CookiesSetFunction::SetCookieOnIOThread, this));
364 DCHECK(rv); 364 DCHECK(rv);
365 365
366 // Will finish asynchronously. 366 // Will finish asynchronously.
367 return true; 367 return true;
368 } 368 }
369 369
370 void CookiesSetFunction::SetCookieOnIOThread() { 370 void CookiesSetFunction::SetCookieOnIOThread() {
371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 371 DCHECK_CURRENTLY_ON(BrowserThread::IO);
372 net::CookieMonster* cookie_monster = 372 net::CookieMonster* cookie_monster =
373 store_browser_context_->GetURLRequestContext() 373 store_browser_context_->GetURLRequestContext()
374 ->cookie_store() 374 ->cookie_store()
375 ->GetCookieMonster(); 375 ->GetCookieMonster();
376 376
377 base::Time expiration_time; 377 base::Time expiration_time;
378 if (parsed_args_->details.expiration_date.get()) { 378 if (parsed_args_->details.expiration_date.get()) {
379 // Time::FromDoubleT converts double time 0 to empty Time object. So we need 379 // Time::FromDoubleT converts double time 0 to empty Time object. So we need
380 // to do special handling here. 380 // to do special handling here.
381 expiration_time = (*parsed_args_->details.expiration_date == 0) ? 381 expiration_time = (*parsed_args_->details.expiration_date == 0) ?
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 432 }
433 } 433 }
434 434
435 bool rv = BrowserThread::PostTask( 435 bool rv = BrowserThread::PostTask(
436 BrowserThread::UI, FROM_HERE, 436 BrowserThread::UI, FROM_HERE,
437 base::Bind(&CookiesSetFunction::RespondOnUIThread, this)); 437 base::Bind(&CookiesSetFunction::RespondOnUIThread, this));
438 DCHECK(rv); 438 DCHECK(rv);
439 } 439 }
440 440
441 void CookiesSetFunction::RespondOnUIThread() { 441 void CookiesSetFunction::RespondOnUIThread() {
442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 442 DCHECK_CURRENTLY_ON(BrowserThread::UI);
443 if (!success_) { 443 if (!success_) {
444 std::string name = 444 std::string name =
445 parsed_args_->details.name.get() ? *parsed_args_->details.name 445 parsed_args_->details.name.get() ? *parsed_args_->details.name
446 : std::string(); 446 : std::string();
447 error_ = ErrorUtils::FormatErrorMessage(keys::kCookieSetFailedError, name); 447 error_ = ErrorUtils::FormatErrorMessage(keys::kCookieSetFailedError, name);
448 } 448 }
449 SendResponse(success_); 449 SendResponse(success_);
450 } 450 }
451 451
452 CookiesRemoveFunction::CookiesRemoveFunction() { 452 CookiesRemoveFunction::CookiesRemoveFunction() {
(...skipping 24 matching lines...) Expand all
477 bool rv = BrowserThread::PostTask( 477 bool rv = BrowserThread::PostTask(
478 BrowserThread::IO, FROM_HERE, 478 BrowserThread::IO, FROM_HERE,
479 base::Bind(&CookiesRemoveFunction::RemoveCookieOnIOThread, this)); 479 base::Bind(&CookiesRemoveFunction::RemoveCookieOnIOThread, this));
480 DCHECK(rv); 480 DCHECK(rv);
481 481
482 // Will return asynchronously. 482 // Will return asynchronously.
483 return true; 483 return true;
484 } 484 }
485 485
486 void CookiesRemoveFunction::RemoveCookieOnIOThread() { 486 void CookiesRemoveFunction::RemoveCookieOnIOThread() {
487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 487 DCHECK_CURRENTLY_ON(BrowserThread::IO);
488 488
489 // Remove the cookie 489 // Remove the cookie
490 net::CookieStore* cookie_store = 490 net::CookieStore* cookie_store =
491 store_browser_context_->GetURLRequestContext()->cookie_store(); 491 store_browser_context_->GetURLRequestContext()->cookie_store();
492 cookie_store->DeleteCookieAsync( 492 cookie_store->DeleteCookieAsync(
493 url_, parsed_args_->details.name, 493 url_, parsed_args_->details.name,
494 base::Bind(&CookiesRemoveFunction::RemoveCookieCallback, this)); 494 base::Bind(&CookiesRemoveFunction::RemoveCookieCallback, this));
495 } 495 }
496 496
497 void CookiesRemoveFunction::RemoveCookieCallback() { 497 void CookiesRemoveFunction::RemoveCookieCallback() {
498 // Build the callback result 498 // Build the callback result
499 Remove::Results::Details details; 499 Remove::Results::Details details;
500 details.name = parsed_args_->details.name; 500 details.name = parsed_args_->details.name;
501 details.url = url_.spec(); 501 details.url = url_.spec();
502 details.store_id = *parsed_args_->details.store_id; 502 details.store_id = *parsed_args_->details.store_id;
503 results_ = Remove::Results::Create(details); 503 results_ = Remove::Results::Create(details);
504 504
505 // Return to UI thread 505 // Return to UI thread
506 bool rv = BrowserThread::PostTask( 506 bool rv = BrowserThread::PostTask(
507 BrowserThread::UI, FROM_HERE, 507 BrowserThread::UI, FROM_HERE,
508 base::Bind(&CookiesRemoveFunction::RespondOnUIThread, this)); 508 base::Bind(&CookiesRemoveFunction::RespondOnUIThread, this));
509 DCHECK(rv); 509 DCHECK(rv);
510 } 510 }
511 511
512 void CookiesRemoveFunction::RespondOnUIThread() { 512 void CookiesRemoveFunction::RespondOnUIThread() {
513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 513 DCHECK_CURRENTLY_ON(BrowserThread::UI);
514 SendResponse(true); 514 SendResponse(true);
515 } 515 }
516 516
517 bool CookiesGetAllCookieStoresFunction::RunImpl() { 517 bool CookiesGetAllCookieStoresFunction::RunImpl() {
518 Profile* original_profile = GetProfile(); 518 Profile* original_profile = GetProfile();
519 DCHECK(original_profile); 519 DCHECK(original_profile);
520 scoped_ptr<base::ListValue> original_tab_ids(new base::ListValue()); 520 scoped_ptr<base::ListValue> original_tab_ids(new base::ListValue());
521 Profile* incognito_profile = NULL; 521 Profile* incognito_profile = NULL;
522 scoped_ptr<base::ListValue> incognito_tab_ids; 522 scoped_ptr<base::ListValue> incognito_tab_ids;
523 if (include_incognito() && GetProfile()->HasOffTheRecordProfile()) { 523 if (include_incognito() && GetProfile()->HasOffTheRecordProfile()) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 } 583 }
584 584
585 void CookiesAPI::OnListenerAdded( 585 void CookiesAPI::OnListenerAdded(
586 const extensions::EventListenerInfo& details) { 586 const extensions::EventListenerInfo& details) {
587 cookies_event_router_.reset(new CookiesEventRouter(browser_context_)); 587 cookies_event_router_.reset(new CookiesEventRouter(browser_context_));
588 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( 588 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver(
589 this); 589 this);
590 } 590 }
591 591
592 } // namespace extensions 592 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698