| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/sdch/sdch_owner.h" | 5 #include "net/sdch/sdch_owner.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/alias.h" | 8 #include "base/debug/alias.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 dictionary_description->SetString(kDictionaryUrlKey, dictionary_url.spec()); | 477 dictionary_description->SetString(kDictionaryUrlKey, dictionary_url.spec()); |
| 478 dictionary_description->SetDouble(kDictionaryLastUsedKey, | 478 dictionary_description->SetDouble(kDictionaryLastUsedKey, |
| 479 last_used.ToDoubleT()); | 479 last_used.ToDoubleT()); |
| 480 dictionary_description->SetInteger(kDictionaryUseCountKey, use_count); | 480 dictionary_description->SetInteger(kDictionaryUseCountKey, use_count); |
| 481 dictionary_description->SetInteger(kDictionarySizeKey, | 481 dictionary_description->SetInteger(kDictionarySizeKey, |
| 482 dictionary_text.size()); | 482 dictionary_text.size()); |
| 483 pref_dictionary_map->Set(server_hash, dictionary_description.Pass()); | 483 pref_dictionary_map->Set(server_hash, dictionary_description.Pass()); |
| 484 load_times_[server_hash] = clock_->Now(); | 484 load_times_[server_hash] = clock_->Now(); |
| 485 } | 485 } |
| 486 | 486 |
| 487 void SdchOwner::OnDictionaryUsed(SdchManager* manager, | 487 void SdchOwner::OnDictionaryAdded(const GURL& dictionary_url, |
| 488 const std::string& server_hash) { | 488 const std::string& server_hash) { } |
| 489 |
| 490 void SdchOwner::OnDictionaryRemoved(const std::string& server_hash) { } |
| 491 |
| 492 void SdchOwner::OnDictionaryUsed(const std::string& server_hash) { |
| 489 base::Time now(clock_->Now()); | 493 base::Time now(clock_->Now()); |
| 490 base::DictionaryValue* pref_dictionary_map = | 494 base::DictionaryValue* pref_dictionary_map = |
| 491 GetPersistentStoreDictionaryMap(pref_store_); | 495 GetPersistentStoreDictionaryMap(pref_store_); |
| 492 ScopedPrefNotifier scoped_pref_notifier(pref_store_); | 496 ScopedPrefNotifier scoped_pref_notifier(pref_store_); |
| 493 | 497 |
| 494 base::Value* value = nullptr; | 498 base::Value* value = nullptr; |
| 495 bool success = pref_dictionary_map->Get(server_hash, &value); | 499 bool success = pref_dictionary_map->Get(server_hash, &value); |
| 496 if (!success) { | 500 if (!success) { |
| 497 // SdchManager::GetDictionarySet() pins the referenced dictionaries in | 501 // SdchManager::GetDictionarySet() pins the referenced dictionaries in |
| 498 // memory past a possible deletion. For this reason, OnDictionaryUsed() | 502 // memory past a possible deletion. For this reason, OnDictionaryUsed() |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 // touched for 48 hours". | 535 // touched for 48 hours". |
| 532 UMA_HISTOGRAM_CUSTOM_TIMES( | 536 UMA_HISTOGRAM_CUSTOM_TIMES( |
| 533 "Sdch3.UsageInterval", | 537 "Sdch3.UsageInterval", |
| 534 use_count ? time_since_last_used : base::TimeDelta::FromHours(48), | 538 use_count ? time_since_last_used : base::TimeDelta::FromHours(48), |
| 535 base::TimeDelta(), base::TimeDelta::FromHours(48), 50); | 539 base::TimeDelta(), base::TimeDelta::FromHours(48), 50); |
| 536 | 540 |
| 537 specific_dictionary_map->SetDouble(kDictionaryLastUsedKey, now.ToDoubleT()); | 541 specific_dictionary_map->SetDouble(kDictionaryLastUsedKey, now.ToDoubleT()); |
| 538 specific_dictionary_map->SetInteger(kDictionaryUseCountKey, use_count + 1); | 542 specific_dictionary_map->SetInteger(kDictionaryUseCountKey, use_count + 1); |
| 539 } | 543 } |
| 540 | 544 |
| 541 void SdchOwner::OnGetDictionary(SdchManager* manager, | 545 void SdchOwner::OnGetDictionary(const GURL& request_url, |
| 542 const GURL& request_url, | |
| 543 const GURL& dictionary_url) { | 546 const GURL& dictionary_url) { |
| 544 #if defined(OS_CHROMEOS) | 547 #if defined(OS_CHROMEOS) |
| 545 // For debugging http://crbug.com/454198; remove when resolved. | 548 // For debugging http://crbug.com/454198; remove when resolved. |
| 546 char url_buf[128]; | 549 char url_buf[128]; |
| 547 if (0u != destroyed_ || !clock_.get()) { | 550 if (0u != destroyed_ || !clock_.get()) { |
| 548 base::strlcpy(url_buf, request_url.spec().c_str(), arraysize(url_buf)); | 551 base::strlcpy(url_buf, request_url.spec().c_str(), arraysize(url_buf)); |
| 549 } | 552 } |
| 550 base::debug::Alias(url_buf); | 553 base::debug::Alias(url_buf); |
| 551 | 554 |
| 552 CHECK_EQ(0u, destroyed_); | 555 CHECK_EQ(0u, destroyed_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 574 // because SdchManager is layered underneath URLRequest. | 577 // because SdchManager is layered underneath URLRequest. |
| 575 return; | 578 return; |
| 576 } | 579 } |
| 577 | 580 |
| 578 fetcher_->Schedule(dictionary_url, | 581 fetcher_->Schedule(dictionary_url, |
| 579 base::Bind(&SdchOwner::OnDictionaryFetched, | 582 base::Bind(&SdchOwner::OnDictionaryFetched, |
| 580 // SdchOwner will outlive its member variables. | 583 // SdchOwner will outlive its member variables. |
| 581 base::Unretained(this), base::Time(), 0)); | 584 base::Unretained(this), base::Time(), 0)); |
| 582 } | 585 } |
| 583 | 586 |
| 584 void SdchOwner::OnClearDictionaries(SdchManager* manager) { | 587 void SdchOwner::OnClearDictionaries() { |
| 585 total_dictionary_bytes_ = 0; | 588 total_dictionary_bytes_ = 0; |
| 586 fetcher_->Cancel(); | 589 fetcher_->Cancel(); |
| 587 | 590 |
| 588 InitializePrefStore(pref_store_); | 591 InitializePrefStore(pref_store_); |
| 589 } | 592 } |
| 590 | 593 |
| 591 void SdchOwner::OnPrefValueChanged(const std::string& key) { | 594 void SdchOwner::OnPrefValueChanged(const std::string& key) { |
| 592 } | 595 } |
| 593 | 596 |
| 594 void SdchOwner::OnInitializationCompleted(bool succeeded) { | 597 void SdchOwner::OnInitializationCompleted(bool succeeded) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 } | 775 } |
| 773 | 776 |
| 774 return true; | 777 return true; |
| 775 } | 778 } |
| 776 | 779 |
| 777 bool SdchOwner::IsPersistingDictionaries() const { | 780 bool SdchOwner::IsPersistingDictionaries() const { |
| 778 return in_memory_pref_store_.get() != nullptr; | 781 return in_memory_pref_store_.get() != nullptr; |
| 779 } | 782 } |
| 780 | 783 |
| 781 } // namespace net | 784 } // namespace net |
| OLD | NEW |