| 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> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 11 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/prefs/persistent_pref_store.h" | 14 #include "base/prefs/persistent_pref_store.h" |
| 13 #include "base/prefs/value_map_pref_store.h" | 15 #include "base/prefs/value_map_pref_store.h" |
| 14 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 15 #include "base/time/default_clock.h" | 17 #include "base/time/default_clock.h" |
| 16 #include "base/values.h" | 18 #include "base/values.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 98 } |
| 97 | 99 |
| 98 // This function initializes a pref store with an empty version of the | 100 // This function initializes a pref store with an empty version of the |
| 99 // above schema, removing anything previously in the store under | 101 // above schema, removing anything previously in the store under |
| 100 // kPreferenceName. | 102 // kPreferenceName. |
| 101 void InitializePrefStore(WriteablePrefStore* store) { | 103 void InitializePrefStore(WriteablePrefStore* store) { |
| 102 scoped_ptr<base::DictionaryValue> empty_store(new base::DictionaryValue); | 104 scoped_ptr<base::DictionaryValue> empty_store(new base::DictionaryValue); |
| 103 empty_store->SetInteger(kVersionKey, kVersion); | 105 empty_store->SetInteger(kVersionKey, kVersion); |
| 104 empty_store->Set(kDictionariesKey, | 106 empty_store->Set(kDictionariesKey, |
| 105 make_scoped_ptr(new base::DictionaryValue)); | 107 make_scoped_ptr(new base::DictionaryValue)); |
| 106 store->SetValue(kPreferenceName, empty_store.Pass(), | 108 store->SetValue(kPreferenceName, std::move(empty_store), |
| 107 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 109 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 108 } | 110 } |
| 109 | 111 |
| 110 // A class to allow iteration over all dictionaries in the pref store, and | 112 // A class to allow iteration over all dictionaries in the pref store, and |
| 111 // easy lookup of the information associated with those dictionaries. | 113 // easy lookup of the information associated with those dictionaries. |
| 112 // Note that this is an "Iterator" in the same sense (and for the same | 114 // Note that this is an "Iterator" in the same sense (and for the same |
| 113 // reasons) that base::Dictionary::Iterator is an iterator--it allows | 115 // reasons) that base::Dictionary::Iterator is an iterator--it allows |
| 114 // iterating over all the dictionaries in the preference store, but it | 116 // iterating over all the dictionaries in the preference store, but it |
| 115 // does not allow use as an STL iterator because the container it | 117 // does not allow use as an STL iterator because the container it |
| 116 // is iterating over does not export begin()/end() methods. This iterator can | 118 // is iterating over does not export begin()/end() methods. This iterator can |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 | 439 |
| 438 // Record the addition in the pref store. | 440 // Record the addition in the pref store. |
| 439 scoped_ptr<base::DictionaryValue> dictionary_description( | 441 scoped_ptr<base::DictionaryValue> dictionary_description( |
| 440 new base::DictionaryValue()); | 442 new base::DictionaryValue()); |
| 441 dictionary_description->SetString(kDictionaryUrlKey, dictionary_url.spec()); | 443 dictionary_description->SetString(kDictionaryUrlKey, dictionary_url.spec()); |
| 442 dictionary_description->SetDouble(kDictionaryLastUsedKey, | 444 dictionary_description->SetDouble(kDictionaryLastUsedKey, |
| 443 last_used.ToDoubleT()); | 445 last_used.ToDoubleT()); |
| 444 dictionary_description->SetInteger(kDictionaryUseCountKey, use_count); | 446 dictionary_description->SetInteger(kDictionaryUseCountKey, use_count); |
| 445 dictionary_description->SetInteger(kDictionarySizeKey, | 447 dictionary_description->SetInteger(kDictionarySizeKey, |
| 446 dictionary_text.size()); | 448 dictionary_text.size()); |
| 447 pref_dictionary_map->Set(server_hash, dictionary_description.Pass()); | 449 pref_dictionary_map->Set(server_hash, std::move(dictionary_description)); |
| 448 load_times_[server_hash] = clock_->Now(); | 450 load_times_[server_hash] = clock_->Now(); |
| 449 } | 451 } |
| 450 | 452 |
| 451 void SdchOwner::OnDictionaryAdded(const GURL& dictionary_url, | 453 void SdchOwner::OnDictionaryAdded(const GURL& dictionary_url, |
| 452 const std::string& server_hash) { } | 454 const std::string& server_hash) { } |
| 453 | 455 |
| 454 void SdchOwner::OnDictionaryRemoved(const std::string& server_hash) { } | 456 void SdchOwner::OnDictionaryRemoved(const std::string& server_hash) { } |
| 455 | 457 |
| 456 void SdchOwner::OnDictionaryUsed(const std::string& server_hash) { | 458 void SdchOwner::OnDictionaryUsed(const std::string& server_hash) { |
| 457 base::Time now(clock_->Now()); | 459 base::Time now(clock_->Now()); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 | 615 |
| 614 // This object can stop waiting on (i.e. observing) the external preference | 616 // This object can stop waiting on (i.e. observing) the external preference |
| 615 // store and switch over to using it as the primary preference store. | 617 // store and switch over to using it as the primary preference store. |
| 616 pref_store_ = external_pref_store_; | 618 pref_store_ = external_pref_store_; |
| 617 external_pref_store_->RemoveObserver(this); | 619 external_pref_store_->RemoveObserver(this); |
| 618 external_pref_store_ = nullptr; | 620 external_pref_store_ = nullptr; |
| 619 in_memory_pref_store_ = nullptr; | 621 in_memory_pref_store_ = nullptr; |
| 620 } | 622 } |
| 621 | 623 |
| 622 void SdchOwner::SetClockForTesting(scoped_ptr<base::Clock> clock) { | 624 void SdchOwner::SetClockForTesting(scoped_ptr<base::Clock> clock) { |
| 623 clock_ = clock.Pass(); | 625 clock_ = std::move(clock); |
| 624 } | 626 } |
| 625 | 627 |
| 626 int SdchOwner::GetDictionaryCountForTesting() const { | 628 int SdchOwner::GetDictionaryCountForTesting() const { |
| 627 int count = 0; | 629 int count = 0; |
| 628 for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd(); | 630 for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd(); |
| 629 it.Advance()) { | 631 it.Advance()) { |
| 630 count++; | 632 count++; |
| 631 } | 633 } |
| 632 return count; | 634 return count; |
| 633 } | 635 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 } | 713 } |
| 712 | 714 |
| 713 return true; | 715 return true; |
| 714 } | 716 } |
| 715 | 717 |
| 716 bool SdchOwner::IsPersistingDictionaries() const { | 718 bool SdchOwner::IsPersistingDictionaries() const { |
| 717 return in_memory_pref_store_.get() != nullptr; | 719 return in_memory_pref_store_.get() != nullptr; |
| 718 } | 720 } |
| 719 | 721 |
| 720 } // namespace net | 722 } // namespace net |
| OLD | NEW |