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" |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 std::unique_ptr<SdchDictionaryFetcher> fetcher) { | 673 std::unique_ptr<SdchDictionaryFetcher> fetcher) { |
674 fetcher_ = std::move(fetcher); | 674 fetcher_ = std::move(fetcher); |
675 } | 675 } |
676 | 676 |
677 void SdchOwner::OnMemoryPressure( | 677 void SdchOwner::OnMemoryPressure( |
678 base::MemoryPressureListener::MemoryPressureLevel level) { | 678 base::MemoryPressureListener::MemoryPressureLevel level) { |
679 DCHECK_NE(base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, level); | 679 DCHECK_NE(base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, level); |
680 ClearData(); | 680 ClearData(); |
681 } | 681 } |
682 | 682 |
683 void SdchOwner::OnMemoryStateChange(base::MemoryState state) { | 683 void SdchOwner::OnPurgeMemory() { |
684 // TODO(hajimehoshi): When the state changes, adjust the sizes of the caches | 684 ClearData(); |
685 // to reduce the limits. SdchOwner doesn't have the ability to limit at | |
686 // present. | |
687 switch (state) { | |
688 case base::MemoryState::NORMAL: | |
689 break; | |
690 case base::MemoryState::THROTTLED: | |
691 ClearData(); | |
692 break; | |
693 case base::MemoryState::SUSPENDED: | |
694 // Note: Not supported at present. Fall through. | |
695 case base::MemoryState::UNKNOWN: | |
696 NOTREACHED(); | |
697 break; | |
698 } | |
699 } | 685 } |
700 | 686 |
701 void SdchOwner::ClearData() { | 687 void SdchOwner::ClearData() { |
702 for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd(); | 688 for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd(); |
703 it.Advance()) { | 689 it.Advance()) { |
704 int new_uses = it.use_count() - use_counts_at_load_[it.server_hash()]; | 690 int new_uses = it.use_count() - use_counts_at_load_[it.server_hash()]; |
705 RecordDictionaryEvictionOrUnload(it.server_hash(), | 691 RecordDictionaryEvictionOrUnload(it.server_hash(), |
706 it.size(), | 692 it.size(), |
707 new_uses, | 693 new_uses, |
708 DICTIONARY_FATE_EVICT_FOR_MEMORY); | 694 DICTIONARY_FATE_EVICT_FOR_MEMORY); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 } | 750 } |
765 | 751 |
766 return true; | 752 return true; |
767 } | 753 } |
768 | 754 |
769 bool SdchOwner::IsPersistingDictionaries() const { | 755 bool SdchOwner::IsPersistingDictionaries() const { |
770 return in_memory_pref_store_.get() != nullptr; | 756 return in_memory_pref_store_.get() != nullptr; |
771 } | 757 } |
772 | 758 |
773 } // namespace net | 759 } // namespace net |
OLD | NEW |