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 // 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 #include "base/basictypes.h" | 51 #include "base/basictypes.h" |
52 #include "base/bind.h" | 52 #include "base/bind.h" |
53 #include "base/callback.h" | 53 #include "base/callback.h" |
54 #include "base/logging.h" | 54 #include "base/logging.h" |
55 #include "base/memory/scoped_ptr.h" | 55 #include "base/memory/scoped_ptr.h" |
56 #include "base/memory/scoped_vector.h" | 56 #include "base/memory/scoped_vector.h" |
57 #include "base/message_loop/message_loop.h" | 57 #include "base/message_loop/message_loop.h" |
58 #include "base/message_loop/message_loop_proxy.h" | 58 #include "base/message_loop/message_loop_proxy.h" |
59 #include "base/metrics/histogram.h" | 59 #include "base/metrics/histogram.h" |
| 60 #include "base/profiler/scoped_tracker.h" |
60 #include "base/strings/string_util.h" | 61 #include "base/strings/string_util.h" |
61 #include "base/strings/stringprintf.h" | 62 #include "base/strings/stringprintf.h" |
62 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 63 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
63 #include "net/cookies/canonical_cookie.h" | 64 #include "net/cookies/canonical_cookie.h" |
64 #include "net/cookies/cookie_util.h" | 65 #include "net/cookies/cookie_util.h" |
65 #include "net/cookies/parsed_cookie.h" | 66 #include "net/cookies/parsed_cookie.h" |
66 | 67 |
67 using base::Time; | 68 using base::Time; |
68 using base::TimeDelta; | 69 using base::TimeDelta; |
69 using base::TimeTicks; | 70 using base::TimeTicks; |
(...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 | 1437 |
1437 void CookieMonster::InitStore() { | 1438 void CookieMonster::InitStore() { |
1438 DCHECK(store_.get()) << "Store must exist to initialize"; | 1439 DCHECK(store_.get()) << "Store must exist to initialize"; |
1439 | 1440 |
1440 // We bind in the current time so that we can report the wall-clock time for | 1441 // We bind in the current time so that we can report the wall-clock time for |
1441 // loading cookies. | 1442 // loading cookies. |
1442 store_->Load(base::Bind(&CookieMonster::OnLoaded, this, TimeTicks::Now())); | 1443 store_->Load(base::Bind(&CookieMonster::OnLoaded, this, TimeTicks::Now())); |
1443 } | 1444 } |
1444 | 1445 |
1445 void CookieMonster::ReportLoaded() { | 1446 void CookieMonster::ReportLoaded() { |
| 1447 // TODO(pkasting): Remove ScopedTracker below once crbug.com/457528 is fixed. |
| 1448 tracked_objects::ScopedTracker tracking_profile( |
| 1449 FROM_HERE_WITH_EXPLICIT_FUNCTION("457528 CookieMonster::ReportLoaded")); |
1446 if (delegate_.get()) | 1450 if (delegate_.get()) |
1447 delegate_->OnLoaded(); | 1451 delegate_->OnLoaded(); |
1448 } | 1452 } |
1449 | 1453 |
1450 void CookieMonster::OnLoaded(TimeTicks beginning_time, | 1454 void CookieMonster::OnLoaded(TimeTicks beginning_time, |
1451 const std::vector<CanonicalCookie*>& cookies) { | 1455 const std::vector<CanonicalCookie*>& cookies) { |
1452 StoreLoadedCookies(cookies); | 1456 StoreLoadedCookies(cookies); |
1453 histogram_time_blocked_on_load_->AddTime(TimeTicks::Now() - beginning_time); | 1457 histogram_time_blocked_on_load_->AddTime(TimeTicks::Now() - beginning_time); |
1454 | 1458 |
1455 // Invoke the task queue of cookie request. | 1459 // Invoke the task queue of cookie request. |
1456 InvokeQueue(); | 1460 InvokeQueue(); |
1457 | 1461 |
1458 ReportLoaded(); | 1462 ReportLoaded(); |
1459 } | 1463 } |
1460 | 1464 |
1461 void CookieMonster::OnKeyLoaded(const std::string& key, | 1465 void CookieMonster::OnKeyLoaded(const std::string& key, |
1462 const std::vector<CanonicalCookie*>& cookies) { | 1466 const std::vector<CanonicalCookie*>& cookies) { |
1463 // This function does its own separate locking. | 1467 // This function does its own separate locking. |
1464 StoreLoadedCookies(cookies); | 1468 StoreLoadedCookies(cookies); |
1465 | 1469 |
1466 std::deque<scoped_refptr<CookieMonsterTask> > tasks_pending_for_key; | 1470 std::deque<scoped_refptr<CookieMonsterTask> > tasks_pending_for_key; |
1467 | 1471 |
1468 // We need to do this repeatedly until no more tasks were added to the queue | 1472 // We need to do this repeatedly until no more tasks were added to the queue |
1469 // during the period where we release the lock. | 1473 // during the period where we release the lock. |
1470 while (true) { | 1474 while (true) { |
| 1475 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456373 is |
| 1476 // fixed. |
| 1477 tracked_objects::ScopedTracker tracking_profile1( |
| 1478 FROM_HERE_WITH_EXPLICIT_FUNCTION("456373 CookieMonster::OnKeyLoaded1")); |
1471 { | 1479 { |
1472 base::AutoLock autolock(lock_); | 1480 base::AutoLock autolock(lock_); |
1473 std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask> > > | 1481 std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask> > > |
1474 ::iterator it = tasks_pending_for_key_.find(key); | 1482 ::iterator it = tasks_pending_for_key_.find(key); |
1475 if (it == tasks_pending_for_key_.end()) { | 1483 if (it == tasks_pending_for_key_.end()) { |
1476 keys_loaded_.insert(key); | 1484 keys_loaded_.insert(key); |
1477 return; | 1485 return; |
1478 } | 1486 } |
1479 if (it->second.empty()) { | 1487 if (it->second.empty()) { |
1480 keys_loaded_.insert(key); | 1488 keys_loaded_.insert(key); |
1481 tasks_pending_for_key_.erase(it); | 1489 tasks_pending_for_key_.erase(it); |
1482 return; | 1490 return; |
1483 } | 1491 } |
1484 it->second.swap(tasks_pending_for_key); | 1492 it->second.swap(tasks_pending_for_key); |
1485 } | 1493 } |
1486 | 1494 |
| 1495 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456373 is |
| 1496 // fixed. |
| 1497 tracked_objects::ScopedTracker tracking_profile2( |
| 1498 FROM_HERE_WITH_EXPLICIT_FUNCTION("456373 CookieMonster::OnKeyLoaded2")); |
1487 while (!tasks_pending_for_key.empty()) { | 1499 while (!tasks_pending_for_key.empty()) { |
1488 scoped_refptr<CookieMonsterTask> task = tasks_pending_for_key.front(); | 1500 scoped_refptr<CookieMonsterTask> task = tasks_pending_for_key.front(); |
1489 task->Run(); | 1501 task->Run(); |
1490 tasks_pending_for_key.pop_front(); | 1502 tasks_pending_for_key.pop_front(); |
1491 } | 1503 } |
1492 } | 1504 } |
1493 } | 1505 } |
1494 | 1506 |
1495 void CookieMonster::StoreLoadedCookies( | 1507 void CookieMonster::StoreLoadedCookies( |
1496 const std::vector<CanonicalCookie*>& cookies) { | 1508 const std::vector<CanonicalCookie*>& cookies) { |
| 1509 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456373 is fixed. |
| 1510 tracked_objects::ScopedTracker tracking_profile( |
| 1511 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1512 "456373 CookieMonster::StoreLoadedCookies")); |
1497 // Initialize the store and sync in any saved persistent cookies. We don't | 1513 // Initialize the store and sync in any saved persistent cookies. We don't |
1498 // care if it's expired, insert it so it can be garbage collected, removed, | 1514 // care if it's expired, insert it so it can be garbage collected, removed, |
1499 // and sync'd. | 1515 // and sync'd. |
1500 base::AutoLock autolock(lock_); | 1516 base::AutoLock autolock(lock_); |
1501 | 1517 |
1502 CookieItVector cookies_with_control_chars; | 1518 CookieItVector cookies_with_control_chars; |
1503 | 1519 |
1504 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); | 1520 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); |
1505 it != cookies.end(); ++it) { | 1521 it != cookies.end(); ++it) { |
1506 int64 cookie_creation_time = (*it)->CreationDate().ToInternalValue(); | 1522 int64 cookie_creation_time = (*it)->CreationDate().ToInternalValue(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 // none of our other constraints are violated. | 1560 // none of our other constraints are violated. |
1545 // In particular, the backing store might have given us duplicate cookies. | 1561 // In particular, the backing store might have given us duplicate cookies. |
1546 | 1562 |
1547 // This method could be called multiple times due to priority loading, thus | 1563 // This method could be called multiple times due to priority loading, thus |
1548 // cookies loaded in previous runs will be validated again, but this is OK | 1564 // cookies loaded in previous runs will be validated again, but this is OK |
1549 // since they are expected to be much fewer than total DB. | 1565 // since they are expected to be much fewer than total DB. |
1550 EnsureCookiesMapIsValid(); | 1566 EnsureCookiesMapIsValid(); |
1551 } | 1567 } |
1552 | 1568 |
1553 void CookieMonster::InvokeQueue() { | 1569 void CookieMonster::InvokeQueue() { |
| 1570 // TODO(pkasting): Remove ScopedTracker below once crbug.com/457528 is fixed. |
| 1571 tracked_objects::ScopedTracker tracking_profile( |
| 1572 FROM_HERE_WITH_EXPLICIT_FUNCTION("457528 CookieMonster::InvokeQueue")); |
1554 while (true) { | 1573 while (true) { |
1555 scoped_refptr<CookieMonsterTask> request_task; | 1574 scoped_refptr<CookieMonsterTask> request_task; |
1556 { | 1575 { |
1557 base::AutoLock autolock(lock_); | 1576 base::AutoLock autolock(lock_); |
1558 if (tasks_pending_.empty()) { | 1577 if (tasks_pending_.empty()) { |
1559 loaded_ = true; | 1578 loaded_ = true; |
1560 creation_times_.clear(); | 1579 creation_times_.clear(); |
1561 keys_loaded_.clear(); | 1580 keys_loaded_.clear(); |
1562 break; | 1581 break; |
1563 } | 1582 } |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2341 it != hook_map_.end(); ++it) { | 2360 it != hook_map_.end(); ++it) { |
2342 std::pair<GURL, std::string> key = it->first; | 2361 std::pair<GURL, std::string> key = it->first; |
2343 if (cookie.IncludeForRequestURL(key.first, opts) && | 2362 if (cookie.IncludeForRequestURL(key.first, opts) && |
2344 cookie.Name() == key.second) { | 2363 cookie.Name() == key.second) { |
2345 it->second->Notify(cookie, removed); | 2364 it->second->Notify(cookie, removed); |
2346 } | 2365 } |
2347 } | 2366 } |
2348 } | 2367 } |
2349 | 2368 |
2350 } // namespace net | 2369 } // namespace net |
OLD | NEW |