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

Side by Side Diff: net/cookies/cookie_monster.cc

Issue 962423002: Update instrumentation for many different bugs based on new UMA data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « content/browser/webui/url_data_manager_backend.cc ('k') | net/proxy/proxy_script_decider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Portions of this code based on Mozilla: 5 // Portions of this code based on Mozilla:
6 // (netwerk/cookie/src/nsCookieService.cpp) 6 // (netwerk/cookie/src/nsCookieService.cpp)
7 /* ***** BEGIN LICENSE BLOCK ***** 7 /* ***** BEGIN LICENSE BLOCK *****
8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
9 * 9 *
10 * The contents of this file are subject to the Mozilla Public License Version 10 * The contents of this file are subject to the Mozilla Public License Version
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 bool secure_; 446 bool secure_;
447 bool http_only_; 447 bool http_only_;
448 bool first_party_only_; 448 bool first_party_only_;
449 CookiePriority priority_; 449 CookiePriority priority_;
450 SetCookiesCallback callback_; 450 SetCookiesCallback callback_;
451 451
452 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); 452 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask);
453 }; 453 };
454 454
455 void CookieMonster::SetCookieWithDetailsTask::Run() { 455 void CookieMonster::SetCookieWithDetailsTask::Run() {
456 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456373 is fixed.
457 tracked_objects::ScopedTracker tracking_profile(
458 FROM_HERE_WITH_EXPLICIT_FUNCTION(
459 "456373 CookieMonster::SetCookieWithDetailsTask::Run"));
460 bool success = this->cookie_monster()->SetCookieWithDetails( 456 bool success = this->cookie_monster()->SetCookieWithDetails(
461 url_, name_, value_, domain_, path_, expiration_time_, secure_, 457 url_, name_, value_, domain_, path_, expiration_time_, secure_,
462 http_only_, first_party_only_, priority_); 458 http_only_, first_party_only_, priority_);
463 if (!callback_.is_null()) { 459 if (!callback_.is_null()) {
464 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, 460 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run,
465 base::Unretained(&callback_), success)); 461 base::Unretained(&callback_), success));
466 } 462 }
467 } 463 }
468 464
469 // Task class for GetAllCookies call. 465 // Task class for GetAllCookies call.
470 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { 466 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask {
471 public: 467 public:
472 GetAllCookiesTask(CookieMonster* cookie_monster, 468 GetAllCookiesTask(CookieMonster* cookie_monster,
473 const GetCookieListCallback& callback) 469 const GetCookieListCallback& callback)
474 : CookieMonsterTask(cookie_monster), callback_(callback) {} 470 : CookieMonsterTask(cookie_monster), callback_(callback) {}
475 471
476 // CookieMonsterTask 472 // CookieMonsterTask
477 void Run() override; 473 void Run() override;
478 474
479 protected: 475 protected:
480 ~GetAllCookiesTask() override {} 476 ~GetAllCookiesTask() override {}
481 477
482 private: 478 private:
483 GetCookieListCallback callback_; 479 GetCookieListCallback callback_;
484 480
485 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesTask); 481 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesTask);
486 }; 482 };
487 483
488 void CookieMonster::GetAllCookiesTask::Run() { 484 void CookieMonster::GetAllCookiesTask::Run() {
489 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456373 is fixed.
490 tracked_objects::ScopedTracker tracking_profile(
491 FROM_HERE_WITH_EXPLICIT_FUNCTION(
492 "456373 CookieMonster::GetAllCookiesTask::Run"));
493 if (!callback_.is_null()) { 485 if (!callback_.is_null()) {
494 CookieList cookies = this->cookie_monster()->GetAllCookies(); 486 CookieList cookies = this->cookie_monster()->GetAllCookies();
495 this->InvokeCallback(base::Bind(&GetCookieListCallback::Run, 487 this->InvokeCallback(base::Bind(&GetCookieListCallback::Run,
496 base::Unretained(&callback_), cookies)); 488 base::Unretained(&callback_), cookies));
497 } 489 }
498 } 490 }
499 491
500 // Task class for GetAllCookiesForURLWithOptions call. 492 // Task class for GetAllCookiesForURLWithOptions call.
501 class CookieMonster::GetAllCookiesForURLWithOptionsTask 493 class CookieMonster::GetAllCookiesForURLWithOptionsTask
502 : public CookieMonsterTask { 494 : public CookieMonsterTask {
(...skipping 15 matching lines...) Expand all
518 510
519 private: 511 private:
520 GURL url_; 512 GURL url_;
521 CookieOptions options_; 513 CookieOptions options_;
522 GetCookieListCallback callback_; 514 GetCookieListCallback callback_;
523 515
524 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesForURLWithOptionsTask); 516 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesForURLWithOptionsTask);
525 }; 517 };
526 518
527 void CookieMonster::GetAllCookiesForURLWithOptionsTask::Run() { 519 void CookieMonster::GetAllCookiesForURLWithOptionsTask::Run() {
528 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456373 is fixed.
529 tracked_objects::ScopedTracker tracking_profile(
530 FROM_HERE_WITH_EXPLICIT_FUNCTION(
531 "456373 CookieMonster::GetAllCookiesForURLWithOptionsTask::Run"));
532 if (!callback_.is_null()) { 520 if (!callback_.is_null()) {
533 CookieList cookies = 521 CookieList cookies =
534 this->cookie_monster()->GetAllCookiesForURLWithOptions(url_, options_); 522 this->cookie_monster()->GetAllCookiesForURLWithOptions(url_, options_);
535 this->InvokeCallback(base::Bind(&GetCookieListCallback::Run, 523 this->InvokeCallback(base::Bind(&GetCookieListCallback::Run,
536 base::Unretained(&callback_), cookies)); 524 base::Unretained(&callback_), cookies));
537 } 525 }
538 } 526 }
539 527
540 template <typename Result> 528 template <typename Result>
541 struct CallbackType { 529 struct CallbackType {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 574 }
587 575
588 template <> 576 template <>
589 base::Closure CookieMonster::DeleteTask<void>::RunDeleteTaskAndBindCallback() { 577 base::Closure CookieMonster::DeleteTask<void>::RunDeleteTaskAndBindCallback() {
590 RunDeleteTask(); 578 RunDeleteTask();
591 return callback_; 579 return callback_;
592 } 580 }
593 581
594 template <typename Result> 582 template <typename Result>
595 void CookieMonster::DeleteTask<Result>::Run() { 583 void CookieMonster::DeleteTask<Result>::Run() {
596 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456373 is fixed.
597 tracked_objects::ScopedTracker tracking_profile(
598 FROM_HERE_WITH_EXPLICIT_FUNCTION(
599 "456373 CookieMonster::DeleteTask::Run"));
600 this->cookie_monster()->FlushStore(base::Bind( 584 this->cookie_monster()->FlushStore(base::Bind(
601 &DeleteTask<Result>::FlushDone, this, RunDeleteTaskAndBindCallback())); 585 &DeleteTask<Result>::FlushDone, this, RunDeleteTaskAndBindCallback()));
602 } 586 }
603 587
604 template <typename Result> 588 template <typename Result>
605 void CookieMonster::DeleteTask<Result>::FlushDone( 589 void CookieMonster::DeleteTask<Result>::FlushDone(
606 const base::Closure& callback) { 590 const base::Closure& callback) {
607 if (!callback.is_null()) { 591 if (!callback.is_null()) {
608 this->InvokeCallback(callback); 592 this->InvokeCallback(callback);
609 } 593 }
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 ~HasCookiesForETLDP1Task() override {} 870 ~HasCookiesForETLDP1Task() override {}
887 871
888 private: 872 private:
889 std::string etldp1_; 873 std::string etldp1_;
890 HasCookiesForETLDP1Callback callback_; 874 HasCookiesForETLDP1Callback callback_;
891 875
892 DISALLOW_COPY_AND_ASSIGN(HasCookiesForETLDP1Task); 876 DISALLOW_COPY_AND_ASSIGN(HasCookiesForETLDP1Task);
893 }; 877 };
894 878
895 void CookieMonster::HasCookiesForETLDP1Task::Run() { 879 void CookieMonster::HasCookiesForETLDP1Task::Run() {
896 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456373 is fixed.
897 tracked_objects::ScopedTracker tracking_profile(
898 FROM_HERE_WITH_EXPLICIT_FUNCTION(
899 "456373 CookieMonster::HasCookiesForETLDP1Task::Run"));
900 bool result = this->cookie_monster()->HasCookiesForETLDP1(etldp1_); 880 bool result = this->cookie_monster()->HasCookiesForETLDP1(etldp1_);
901 if (!callback_.is_null()) { 881 if (!callback_.is_null()) {
902 this->InvokeCallback(base::Bind(&HasCookiesForETLDP1Callback::Run, 882 this->InvokeCallback(base::Bind(&HasCookiesForETLDP1Callback::Run,
903 base::Unretained(&callback_), result)); 883 base::Unretained(&callback_), result));
904 } 884 }
905 } 885 }
906 886
907 // Asynchronous CookieMonster API 887 // Asynchronous CookieMonster API
908 888
909 void CookieMonster::SetCookieWithDetailsAsync( 889 void CookieMonster::SetCookieWithDetailsAsync(
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 while (!tasks_pending_for_key.empty()) { 1477 while (!tasks_pending_for_key.empty()) {
1498 scoped_refptr<CookieMonsterTask> task = tasks_pending_for_key.front(); 1478 scoped_refptr<CookieMonsterTask> task = tasks_pending_for_key.front();
1499 task->Run(); 1479 task->Run();
1500 tasks_pending_for_key.pop_front(); 1480 tasks_pending_for_key.pop_front();
1501 } 1481 }
1502 } 1482 }
1503 } 1483 }
1504 1484
1505 void CookieMonster::StoreLoadedCookies( 1485 void CookieMonster::StoreLoadedCookies(
1506 const std::vector<CanonicalCookie*>& cookies) { 1486 const std::vector<CanonicalCookie*>& cookies) {
1507 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456373 is fixed.
1508 tracked_objects::ScopedTracker tracking_profile(
1509 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1510 "456373 CookieMonster::StoreLoadedCookies"));
1511 // Initialize the store and sync in any saved persistent cookies. We don't 1487 // Initialize the store and sync in any saved persistent cookies. We don't
1512 // care if it's expired, insert it so it can be garbage collected, removed, 1488 // care if it's expired, insert it so it can be garbage collected, removed,
1513 // and sync'd. 1489 // and sync'd.
1514 base::AutoLock autolock(lock_); 1490 base::AutoLock autolock(lock_);
1515 1491
1516 CookieItVector cookies_with_control_chars; 1492 CookieItVector cookies_with_control_chars;
1517 1493
1518 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); 1494 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin();
1519 it != cookies.end(); ++it) { 1495 it != cookies.end(); ++it) {
1520 int64 cookie_creation_time = (*it)->CreationDate().ToInternalValue(); 1496 int64 cookie_creation_time = (*it)->CreationDate().ToInternalValue();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 break; 1552 break;
1577 } 1553 }
1578 request_task = tasks_pending_.front(); 1554 request_task = tasks_pending_.front();
1579 tasks_pending_.pop(); 1555 tasks_pending_.pop();
1580 } 1556 }
1581 request_task->Run(); 1557 request_task->Run();
1582 } 1558 }
1583 } 1559 }
1584 1560
1585 void CookieMonster::EnsureCookiesMapIsValid() { 1561 void CookieMonster::EnsureCookiesMapIsValid() {
1586 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456373 is fixed.
1587 tracked_objects::ScopedTracker tracking_profile(
1588 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1589 "456373 CookieMonster::EnsureCookiesMapIsValid"));
1590 lock_.AssertAcquired(); 1562 lock_.AssertAcquired();
1591 1563
1592 int num_duplicates_trimmed = 0; 1564 int num_duplicates_trimmed = 0;
1593 1565
1594 // Iterate through all the of the cookies, grouped by host. 1566 // Iterate through all the of the cookies, grouped by host.
1595 CookieMap::iterator prev_range_end = cookies_.begin(); 1567 CookieMap::iterator prev_range_end = cookies_.begin();
1596 while (prev_range_end != cookies_.end()) { 1568 while (prev_range_end != cookies_.end()) {
1597 CookieMap::iterator cur_range_begin = prev_range_end; 1569 CookieMap::iterator cur_range_begin = prev_range_end;
1598 const std::string key = cur_range_begin->first; // Keep a copy. 1570 const std::string key = cur_range_begin->first; // Keep a copy.
1599 CookieMap::iterator cur_range_end = cookies_.upper_bound(key); 1571 CookieMap::iterator cur_range_end = cookies_.upper_bound(key);
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 cc->SetLastAccessDate(current); 1869 cc->SetLastAccessDate(current);
1898 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get()) 1870 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get())
1899 store_->UpdateCookieAccessTime(*cc); 1871 store_->UpdateCookieAccessTime(*cc);
1900 } 1872 }
1901 1873
1902 // InternalDeleteCookies must not invalidate iterators other than the one being 1874 // InternalDeleteCookies must not invalidate iterators other than the one being
1903 // deleted. 1875 // deleted.
1904 void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, 1876 void CookieMonster::InternalDeleteCookie(CookieMap::iterator it,
1905 bool sync_to_store, 1877 bool sync_to_store,
1906 DeletionCause deletion_cause) { 1878 DeletionCause deletion_cause) {
1907 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456373 is fixed.
1908 tracked_objects::ScopedTracker tracking_profile(
1909 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1910 "456373 CookieMonster::InternalDeleteCookie"));
1911 lock_.AssertAcquired(); 1879 lock_.AssertAcquired();
1912 1880
1913 // Ideally, this would be asserted up where we define ChangeCauseMapping, 1881 // Ideally, this would be asserted up where we define ChangeCauseMapping,
1914 // but DeletionCause's visibility (or lack thereof) forces us to make 1882 // but DeletionCause's visibility (or lack thereof) forces us to make
1915 // this check here. 1883 // this check here.
1916 static_assert(arraysize(ChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1, 1884 static_assert(arraysize(ChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1,
1917 "ChangeCauseMapping size should match DeletionCause size"); 1885 "ChangeCauseMapping size should match DeletionCause size");
1918 1886
1919 // See InitializeHistograms() for details. 1887 // See InitializeHistograms() for details.
1920 if (deletion_cause != DELETE_COOKIE_DONT_RECORD) 1888 if (deletion_cause != DELETE_COOKIE_DONT_RECORD)
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
2341 it != hook_map_.end(); ++it) { 2309 it != hook_map_.end(); ++it) {
2342 std::pair<GURL, std::string> key = it->first; 2310 std::pair<GURL, std::string> key = it->first;
2343 if (cookie.IncludeForRequestURL(key.first, opts) && 2311 if (cookie.IncludeForRequestURL(key.first, opts) &&
2344 cookie.Name() == key.second) { 2312 cookie.Name() == key.second) {
2345 it->second->Notify(cookie, removed); 2313 it->second->Notify(cookie, removed);
2346 } 2314 }
2347 } 2315 }
2348 } 2316 }
2349 2317
2350 } // namespace net 2318 } // namespace net
OLDNEW
« no previous file with comments | « content/browser/webui/url_data_manager_backend.cc ('k') | net/proxy/proxy_script_decider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698