Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: net/sdch/sdch_owner.cc

Issue 1893083002: Change scoped_ptr to std::unique_ptr in //net. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-net-all: iwyu Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/sdch/sdch_owner.h ('k') | net/sdch/sdch_owner_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
15 #include "base/time/default_clock.h" 16 #include "base/time/default_clock.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "net/base/sdch_manager.h" 18 #include "net/base/sdch_manager.h"
18 #include "net/base/sdch_net_log_params.h" 19 #include "net/base/sdch_net_log_params.h"
19 20
20 namespace net { 21 namespace net {
21 22
22 namespace { 23 namespace {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 ReadError GetReadError() const override { return PERSISTENCE_FAILURE_NONE; } 73 ReadError GetReadError() const override { return PERSISTENCE_FAILURE_NONE; }
73 74
74 bool GetValue(const base::DictionaryValue** result) const override { 75 bool GetValue(const base::DictionaryValue** result) const override {
75 *result = &storage_; 76 *result = &storage_;
76 return true; 77 return true;
77 } 78 }
78 bool GetMutableValue(base::DictionaryValue** result) override { 79 bool GetMutableValue(base::DictionaryValue** result) override {
79 *result = &storage_; 80 *result = &storage_;
80 return true; 81 return true;
81 } 82 }
82 void SetValue(scoped_ptr<base::DictionaryValue> value) override { 83 void SetValue(std::unique_ptr<base::DictionaryValue> value) override {
83 storage_.Clear(); 84 storage_.Clear();
84 storage_.MergeDictionary(value.get()); 85 storage_.MergeDictionary(value.get());
85 } 86 }
86 87
87 void ReportValueChanged() override {} 88 void ReportValueChanged() override {}
88 89
89 // This storage class requires no special initialization. 90 // This storage class requires no special initialization.
90 bool IsInitializationComplete() override { return true; } 91 bool IsInitializationComplete() override { return true; }
91 void StartObservingInit(SdchOwner* observer) override {} 92 void StartObservingInit(SdchOwner* observer) override {}
92 void StopObservingInit() override {} 93 void StopObservingInit() override {}
(...skipping 19 matching lines...) Expand all
112 DCHECK(success); 113 DCHECK(success);
113 DCHECK(dictionary_list_dictionary); 114 DCHECK(dictionary_list_dictionary);
114 115
115 return dictionary_list_dictionary; 116 return dictionary_list_dictionary;
116 } 117 }
117 118
118 // This function initializes a pref store with an empty version of the 119 // This function initializes a pref store with an empty version of the
119 // above schema, removing anything previously in the store under 120 // above schema, removing anything previously in the store under
120 // kPreferenceName. 121 // kPreferenceName.
121 void InitializePrefStore(SdchOwner::PrefStorage* store) { 122 void InitializePrefStore(SdchOwner::PrefStorage* store) {
122 scoped_ptr<base::DictionaryValue> empty_store(new base::DictionaryValue); 123 std::unique_ptr<base::DictionaryValue> empty_store(new base::DictionaryValue);
123 empty_store->SetInteger(kVersionKey, kVersion); 124 empty_store->SetInteger(kVersionKey, kVersion);
124 empty_store->Set(kDictionariesKey, 125 empty_store->Set(kDictionariesKey,
125 make_scoped_ptr(new base::DictionaryValue)); 126 base::WrapUnique(new base::DictionaryValue));
126 store->SetValue(std::move(empty_store)); 127 store->SetValue(std::move(empty_store));
127 } 128 }
128 129
129 // A class to allow iteration over all dictionaries in the pref store, and 130 // A class to allow iteration over all dictionaries in the pref store, and
130 // easy lookup of the information associated with those dictionaries. 131 // easy lookup of the information associated with those dictionaries.
131 // Note that this is an "Iterator" in the same sense (and for the same 132 // Note that this is an "Iterator" in the same sense (and for the same
132 // reasons) that base::Dictionary::Iterator is an iterator--it allows 133 // reasons) that base::Dictionary::Iterator is an iterator--it allows
133 // iterating over all the dictionaries in the preference store, but it 134 // iterating over all the dictionaries in the preference store, but it
134 // does not allow use as an STL iterator because the container it 135 // does not allow use as an STL iterator because the container it
135 // is iterating over does not export begin()/end() methods. This iterator can 136 // is iterating over does not export begin()/end() methods. This iterator can
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 for (const auto& val : consumed_byte_seconds_) { 332 for (const auto& val : consumed_byte_seconds_) {
332 if (object_lifetime > 0) { 333 if (object_lifetime > 0) {
333 // Objects that are created and immediately destroyed don't add any memory 334 // Objects that are created and immediately destroyed don't add any memory
334 // pressure over time (and also cause a crash here). 335 // pressure over time (and also cause a crash here).
335 UMA_HISTOGRAM_MEMORY_KB("Sdch3.TimeWeightedMemoryUse", 336 UMA_HISTOGRAM_MEMORY_KB("Sdch3.TimeWeightedMemoryUse",
336 val / object_lifetime); 337 val / object_lifetime);
337 } 338 }
338 } 339 }
339 } 340 }
340 341
341 void SdchOwner::EnablePersistentStorage(scoped_ptr<PrefStorage> pref_store) { 342 void SdchOwner::EnablePersistentStorage(
343 std::unique_ptr<PrefStorage> pref_store) {
342 DCHECK(!external_pref_store_); 344 DCHECK(!external_pref_store_);
343 DCHECK(pref_store); 345 DCHECK(pref_store);
344 external_pref_store_ = std::move(pref_store); 346 external_pref_store_ = std::move(pref_store);
345 external_pref_store_->StartObservingInit(this); 347 external_pref_store_->StartObservingInit(this);
346 348
347 if (external_pref_store_->IsInitializationComplete()) 349 if (external_pref_store_->IsInitializationComplete())
348 OnPrefStorageInitializationComplete(true); 350 OnPrefStorageInitializationComplete(true);
349 } 351 }
350 352
351 void SdchOwner::SetMaxTotalDictionarySize(size_t max_total_dictionary_size) { 353 void SdchOwner::SetMaxTotalDictionarySize(size_t max_total_dictionary_size) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 478
477 // If a dictionary has never been used, its dictionary addition time 479 // If a dictionary has never been used, its dictionary addition time
478 // is recorded as its last used time. Never used dictionaries are treated 480 // is recorded as its last used time. Never used dictionaries are treated
479 // specially in the freshness logic. 481 // specially in the freshness logic.
480 if (last_used.is_null()) 482 if (last_used.is_null())
481 last_used = clock_->Now(); 483 last_used = clock_->Now();
482 484
483 total_dictionary_bytes_ += dictionary_text.size(); 485 total_dictionary_bytes_ += dictionary_text.size();
484 486
485 // Record the addition in the pref store. 487 // Record the addition in the pref store.
486 scoped_ptr<base::DictionaryValue> dictionary_description( 488 std::unique_ptr<base::DictionaryValue> dictionary_description(
487 new base::DictionaryValue()); 489 new base::DictionaryValue());
488 dictionary_description->SetString(kDictionaryUrlKey, dictionary_url.spec()); 490 dictionary_description->SetString(kDictionaryUrlKey, dictionary_url.spec());
489 dictionary_description->SetDouble(kDictionaryLastUsedKey, 491 dictionary_description->SetDouble(kDictionaryLastUsedKey,
490 last_used.ToDoubleT()); 492 last_used.ToDoubleT());
491 dictionary_description->SetDouble(kDictionaryCreatedTimeKey, 493 dictionary_description->SetDouble(kDictionaryCreatedTimeKey,
492 created_time.ToDoubleT()); 494 created_time.ToDoubleT());
493 dictionary_description->SetInteger(kDictionaryUseCountKey, use_count); 495 dictionary_description->SetInteger(kDictionaryUseCountKey, use_count);
494 dictionary_description->SetInteger(kDictionarySizeKey, 496 dictionary_description->SetInteger(kDictionarySizeKey,
495 dictionary_text.size()); 497 dictionary_text.size());
496 pref_dictionary_map->Set(server_hash, std::move(dictionary_description)); 498 pref_dictionary_map->Set(server_hash, std::move(dictionary_description));
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 GetPersistentStoreDictionaryMap(external_pref_store_.get()) 635 GetPersistentStoreDictionaryMap(external_pref_store_.get())
634 ->Swap(GetPersistentStoreDictionaryMap(in_memory_pref_store_.get())); 636 ->Swap(GetPersistentStoreDictionaryMap(in_memory_pref_store_.get()));
635 637
636 // This object can stop waiting on (i.e. observing) the external preference 638 // This object can stop waiting on (i.e. observing) the external preference
637 // store and switch over to using it as the primary preference store. 639 // store and switch over to using it as the primary preference store.
638 pref_store_ = external_pref_store_.get(); 640 pref_store_ = external_pref_store_.get();
639 external_pref_store_->StopObservingInit(); 641 external_pref_store_->StopObservingInit();
640 in_memory_pref_store_ = nullptr; 642 in_memory_pref_store_ = nullptr;
641 } 643 }
642 644
643 void SdchOwner::SetClockForTesting(scoped_ptr<base::Clock> clock) { 645 void SdchOwner::SetClockForTesting(std::unique_ptr<base::Clock> clock) {
644 clock_ = std::move(clock); 646 clock_ = std::move(clock);
645 } 647 }
646 648
647 int SdchOwner::GetDictionaryCountForTesting() const { 649 int SdchOwner::GetDictionaryCountForTesting() const {
648 int count = 0; 650 int count = 0;
649 for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd(); 651 for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd();
650 it.Advance()) { 652 it.Advance()) {
651 count++; 653 count++;
652 } 654 }
653 return count; 655 return count;
654 } 656 }
655 657
656 bool SdchOwner::HasDictionaryFromURLForTesting(const GURL& url) const { 658 bool SdchOwner::HasDictionaryFromURLForTesting(const GURL& url) const {
657 for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd(); 659 for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd();
658 it.Advance()) { 660 it.Advance()) {
659 if (it.url() == url) 661 if (it.url() == url)
660 return true; 662 return true;
661 } 663 }
662 return false; 664 return false;
663 } 665 }
664 666
665 void SdchOwner::SetFetcherForTesting( 667 void SdchOwner::SetFetcherForTesting(
666 scoped_ptr<SdchDictionaryFetcher> fetcher) { 668 std::unique_ptr<SdchDictionaryFetcher> fetcher) {
667 fetcher_ = std::move(fetcher); 669 fetcher_ = std::move(fetcher);
668 } 670 }
669 671
670 void SdchOwner::OnMemoryPressure( 672 void SdchOwner::OnMemoryPressure(
671 base::MemoryPressureListener::MemoryPressureLevel level) { 673 base::MemoryPressureListener::MemoryPressureLevel level) {
672 DCHECK_NE(base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, level); 674 DCHECK_NE(base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE, level);
673 675
674 for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd(); 676 for (DictionaryPreferenceIterator it(pref_store_); !it.IsAtEnd();
675 it.Advance()) { 677 it.Advance()) {
676 int new_uses = it.use_count() - use_counts_at_load_[it.server_hash()]; 678 int new_uses = it.use_count() - use_counts_at_load_[it.server_hash()];
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 } 738 }
737 739
738 return true; 740 return true;
739 } 741 }
740 742
741 bool SdchOwner::IsPersistingDictionaries() const { 743 bool SdchOwner::IsPersistingDictionaries() const {
742 return in_memory_pref_store_.get() != nullptr; 744 return in_memory_pref_store_.get() != nullptr;
743 } 745 }
744 746
745 } // namespace net 747 } // namespace net
OLDNEW
« no previous file with comments | « net/sdch/sdch_owner.h ('k') | net/sdch/sdch_owner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698