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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/time/default_clock.h" | 16 #include "base/time/default_clock.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "net/base/sdch_manager.h" | 18 #include "net/base/sdch_manager.h" |
19 #include "net/base/sdch_net_log_params.h" | 19 #include "net/base/sdch_net_log_params.h" |
| 20 #include "net/log/net_log_event_type.h" |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // Dictionaries that haven't been touched in 24 hours may be evicted | 26 // Dictionaries that haven't been touched in 24 hours may be evicted |
26 // to make room for new dictionaries. | 27 // to make room for new dictionaries. |
27 const int kFreshnessLifetimeHours = 24; | 28 const int kFreshnessLifetimeHours = 24; |
28 | 29 |
29 // Dictionaries that have never been used only stay fresh for one hour. | 30 // Dictionaries that have never been used only stay fresh for one hour. |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 stale_dictionary_list.push_back(DictionaryItem( | 413 stale_dictionary_list.push_back(DictionaryItem( |
413 it.last_used(), it.server_hash(), it.use_count(), it.size())); | 414 it.last_used(), it.server_hash(), it.use_count(), it.size())); |
414 recoverable_bytes += it.size(); | 415 recoverable_bytes += it.size(); |
415 } | 416 } |
416 } | 417 } |
417 | 418 |
418 if (total_dictionary_bytes_ + dictionary_text.size() - recoverable_bytes > | 419 if (total_dictionary_bytes_ + dictionary_text.size() - recoverable_bytes > |
419 max_total_dictionary_size_) { | 420 max_total_dictionary_size_) { |
420 RecordDictionaryFate(DICTIONARY_FATE_FETCH_IGNORED_NO_SPACE); | 421 RecordDictionaryFate(DICTIONARY_FATE_FETCH_IGNORED_NO_SPACE); |
421 SdchManager::SdchErrorRecovery(SDCH_DICTIONARY_NO_ROOM); | 422 SdchManager::SdchErrorRecovery(SDCH_DICTIONARY_NO_ROOM); |
422 net_log.AddEvent(NetLog::TYPE_SDCH_DICTIONARY_ERROR, | 423 net_log.AddEvent(NetLogEventType::SDCH_DICTIONARY_ERROR, |
423 base::Bind(&NetLogSdchDictionaryFetchProblemCallback, | 424 base::Bind(&NetLogSdchDictionaryFetchProblemCallback, |
424 SDCH_DICTIONARY_NO_ROOM, dictionary_url, true)); | 425 SDCH_DICTIONARY_NO_ROOM, dictionary_url, true)); |
425 return; | 426 return; |
426 } | 427 } |
427 | 428 |
428 // Add the new dictionary. This is done before removing the stale | 429 // Add the new dictionary. This is done before removing the stale |
429 // dictionaries so that no state change will occur if dictionary addition | 430 // dictionaries so that no state change will occur if dictionary addition |
430 // fails. | 431 // fails. |
431 std::string server_hash; | 432 std::string server_hash; |
432 SdchProblemCode rv = manager_->AddSdchDictionary( | 433 SdchProblemCode rv = manager_->AddSdchDictionary( |
433 dictionary_text, dictionary_url, &server_hash); | 434 dictionary_text, dictionary_url, &server_hash); |
434 if (rv != SDCH_OK) { | 435 if (rv != SDCH_OK) { |
435 RecordDictionaryFate(DICTIONARY_FATE_FETCH_MANAGER_REFUSED); | 436 RecordDictionaryFate(DICTIONARY_FATE_FETCH_MANAGER_REFUSED); |
436 SdchManager::SdchErrorRecovery(rv); | 437 SdchManager::SdchErrorRecovery(rv); |
437 net_log.AddEvent(NetLog::TYPE_SDCH_DICTIONARY_ERROR, | 438 net_log.AddEvent(NetLogEventType::SDCH_DICTIONARY_ERROR, |
438 base::Bind(&NetLogSdchDictionaryFetchProblemCallback, rv, | 439 base::Bind(&NetLogSdchDictionaryFetchProblemCallback, rv, |
439 dictionary_url, true)); | 440 dictionary_url, true)); |
440 return; | 441 return; |
441 } | 442 } |
442 | 443 |
443 base::DictionaryValue* pref_dictionary_map = | 444 base::DictionaryValue* pref_dictionary_map = |
444 GetPersistentStoreDictionaryMap(pref_store_); | 445 GetPersistentStoreDictionaryMap(pref_store_); |
445 ScopedPrefNotifier scoped_pref_notifier(pref_store_); | 446 ScopedPrefNotifier scoped_pref_notifier(pref_store_); |
446 | 447 |
447 // Remove the old dictionaries. | 448 // Remove the old dictionaries. |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 } | 739 } |
739 | 740 |
740 return true; | 741 return true; |
741 } | 742 } |
742 | 743 |
743 bool SdchOwner::IsPersistingDictionaries() const { | 744 bool SdchOwner::IsPersistingDictionaries() const { |
744 return in_memory_pref_store_.get() != nullptr; | 745 return in_memory_pref_store_.get() != nullptr; |
745 } | 746 } |
746 | 747 |
747 } // namespace net | 748 } // namespace net |
OLD | NEW |