| 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 const size_t SdchOwner::kMaxTotalDictionarySize = 20 * 1000 * 1000; | 260 const size_t SdchOwner::kMaxTotalDictionarySize = 20 * 1000 * 1000; |
| 261 #endif | 261 #endif |
| 262 | 262 |
| 263 // Somewhat arbitrary, but we assume a dictionary smaller than | 263 // Somewhat arbitrary, but we assume a dictionary smaller than |
| 264 // 50K isn't going to do anyone any good. Note that this still doesn't | 264 // 50K isn't going to do anyone any good. Note that this still doesn't |
| 265 // prevent download and addition unless there is less than this | 265 // prevent download and addition unless there is less than this |
| 266 // amount of space available in storage. | 266 // amount of space available in storage. |
| 267 const size_t SdchOwner::kMinSpaceForDictionaryFetch = 50 * 1000; | 267 const size_t SdchOwner::kMinSpaceForDictionaryFetch = 50 * 1000; |
| 268 | 268 |
| 269 SdchOwner::SdchOwner(SdchManager* sdch_manager, URLRequestContext* context) | 269 SdchOwner::SdchOwner(SdchManager* sdch_manager, URLRequestContext* context) |
| 270 : manager_(sdch_manager), | 270 : manager_(sdch_manager->GetWeakPtr()), |
| 271 fetcher_(new SdchDictionaryFetcher(context)), | 271 fetcher_(new SdchDictionaryFetcher(context)), |
| 272 total_dictionary_bytes_(0), | 272 total_dictionary_bytes_(0), |
| 273 clock_(new base::DefaultClock), | 273 clock_(new base::DefaultClock), |
| 274 max_total_dictionary_size_(kMaxTotalDictionarySize), | 274 max_total_dictionary_size_(kMaxTotalDictionarySize), |
| 275 min_space_for_dictionary_fetch_(kMinSpaceForDictionaryFetch), | 275 min_space_for_dictionary_fetch_(kMinSpaceForDictionaryFetch), |
| 276 // TODO(rmcilroy) Add back memory_pressure_listener_ when | 276 // TODO(rmcilroy) Add back memory_pressure_listener_ when |
| 277 // http://crbug.com/447208 is fixed | 277 // http://crbug.com/447208 is fixed |
| 278 #if defined(OS_CHROMEOS) | 278 #if defined(OS_CHROMEOS) |
| 279 // For debugging http://crbug.com/454198; remove when resolved. | 279 // For debugging http://crbug.com/454198; remove when resolved. |
| 280 destroyed_(0), | 280 destroyed_(0), |
| 281 #endif | 281 #endif |
| 282 in_memory_pref_store_(new ValueMapPrefStore()), | 282 in_memory_pref_store_(new ValueMapPrefStore()), |
| 283 external_pref_store_(nullptr), | 283 external_pref_store_(nullptr), |
| 284 pref_store_(in_memory_pref_store_.get()) { | 284 pref_store_(in_memory_pref_store_.get()) { |
| 285 #if defined(OS_CHROMEOS) | 285 #if defined(OS_CHROMEOS) |
| 286 // For debugging http://crbug.com/454198; remove when resolved. | 286 // For debugging http://crbug.com/454198; remove when resolved. |
| 287 CHECK(clock_.get()); | 287 CHECK(clock_.get()); |
| 288 #endif | 288 #endif |
| 289 manager_->AddObserver(this); | 289 manager_->AddObserver(this); |
| 290 InitializePrefStore(pref_store_); | 290 InitializePrefStore(pref_store_); |
| 291 } | 291 } |
| 292 | 292 |
| 293 SdchOwner::~SdchOwner() { | 293 SdchOwner::~SdchOwner() { |
| 294 #if defined(OS_CHROMEOS) | 294 #if defined(OS_CHROMEOS) |
| 295 // For debugging http://crbug.com/454198; remove when resolved. | 295 // For debugging http://crbug.com/454198; remove when resolved. |
| 296 CHECK_EQ(0u, destroyed_); | 296 CHECK_EQ(0u, destroyed_); |
| 297 CHECK(clock_.get()); | 297 CHECK(clock_.get()); |
| 298 clock_.reset(); | 298 clock_.reset(); |
| 299 CHECK(manager_.get()); |
| 299 #endif | 300 #endif |
| 300 | 301 |
| 301 for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd(); | 302 for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd(); |
| 302 it.Advance()) { | 303 it.Advance()) { |
| 303 int new_uses = it.use_count() - use_counts_at_load_[it.server_hash()]; | 304 int new_uses = it.use_count() - use_counts_at_load_[it.server_hash()]; |
| 304 DictionaryFate fate = IsPersistingDictionaries() ? | 305 DictionaryFate fate = IsPersistingDictionaries() ? |
| 305 DICTIONARY_FATE_UNLOAD_FOR_DESTRUCTION : | 306 DICTIONARY_FATE_UNLOAD_FOR_DESTRUCTION : |
| 306 DICTIONARY_FATE_EVICT_FOR_DESTRUCTION; | 307 DICTIONARY_FATE_EVICT_FOR_DESTRUCTION; |
| 307 RecordDictionaryEvictionOrUnload(new_uses, fate); | 308 RecordDictionaryEvictionOrUnload(new_uses, fate); |
| 308 } | 309 } |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 } | 757 } |
| 757 | 758 |
| 758 return true; | 759 return true; |
| 759 } | 760 } |
| 760 | 761 |
| 761 bool SdchOwner::IsPersistingDictionaries() const { | 762 bool SdchOwner::IsPersistingDictionaries() const { |
| 762 return in_memory_pref_store_.get() != nullptr; | 763 return in_memory_pref_store_.get() != nullptr; |
| 763 } | 764 } |
| 764 | 765 |
| 765 } // namespace net | 766 } // namespace net |
| OLD | NEW |