Commit f5047a45 authored by rdsmith's avatar rdsmith Committed by Commit bot

Instrument SdchOwner for clock nullification.

BUG=454198
R=ellyjones@chromium.org

Review URL: https://codereview.chromium.org/935073003

Cr-Commit-Position: refs/heads/master@{#317364}
parent 6d39a934
...@@ -259,6 +259,12 @@ SdchManager::~SdchManager() { ...@@ -259,6 +259,12 @@ SdchManager::~SdchManager() {
auto it = dictionaries_.begin(); auto it = dictionaries_.begin();
dictionaries_.erase(it->first); dictionaries_.erase(it->first);
} }
#if defined(OS_CHROMEOS)
// For debugging http://crbug.com/454198; remove when resolved.
// Explicitly confirm that we can't notify any observers anymore.
CHECK(!observers_.might_have_observers());
#endif
} }
void SdchManager::ClearData() { void SdchManager::ClearData() {
......
...@@ -86,22 +86,40 @@ SdchOwner::SdchOwner(net::SdchManager* sdch_manager, ...@@ -86,22 +86,40 @@ SdchOwner::SdchOwner(net::SdchManager* sdch_manager,
clock_(new base::DefaultClock), clock_(new base::DefaultClock),
max_total_dictionary_size_(kMaxTotalDictionarySize), max_total_dictionary_size_(kMaxTotalDictionarySize),
min_space_for_dictionary_fetch_(kMinSpaceForDictionaryFetch), min_space_for_dictionary_fetch_(kMinSpaceForDictionaryFetch),
#if defined(OS_CHROMEOS)
// For debugging http://crbug.com/454198; remove when resolved.
destroyed_(0),
#endif
memory_pressure_listener_( memory_pressure_listener_(
base::Bind(&SdchOwner::OnMemoryPressure, base::Bind(&SdchOwner::OnMemoryPressure,
// Because |memory_pressure_listener_| is owned by // Because |memory_pressure_listener_| is owned by
// SdchOwner, the SdchOwner object will be available // SdchOwner, the SdchOwner object will be available
// for the lifetime of |memory_pressure_listener_|. // for the lifetime of |memory_pressure_listener_|.
base::Unretained(this))) { base::Unretained(this))) {
#if defined(OS_CHROMEOS)
// For debugging http://crbug.com/454198; remove when resolved.
CHECK(clock_.get());
#endif
manager_->AddObserver(this); manager_->AddObserver(this);
} }
SdchOwner::~SdchOwner() { SdchOwner::~SdchOwner() {
#if defined(OS_CHROMEOS)
// For debugging http://crbug.com/454198; remove when resolved.
CHECK_EQ(0u, destroyed_);
CHECK(clock_.get());
clock_.reset();
#endif
for (auto it = local_dictionary_info_.begin(); for (auto it = local_dictionary_info_.begin();
it != local_dictionary_info_.end(); ++it) { it != local_dictionary_info_.end(); ++it) {
RecordDictionaryEviction(it->second.use_count, RecordDictionaryEviction(it->second.use_count,
DICTIONARY_FATE_EVICT_FOR_DESTRUCTION); DICTIONARY_FATE_EVICT_FOR_DESTRUCTION);
} }
manager_->RemoveObserver(this); manager_->RemoveObserver(this);
#if defined(OS_CHROMEOS)
destroyed_ = 0xdeadbeef;
#endif
} }
void SdchOwner::SetMaxTotalDictionarySize(size_t max_total_dictionary_size) { void SdchOwner::SetMaxTotalDictionarySize(size_t max_total_dictionary_size) {
...@@ -138,6 +156,12 @@ void SdchOwner::OnDictionaryFetched(const std::string& dictionary_text, ...@@ -138,6 +156,12 @@ void SdchOwner::OnDictionaryFetched(const std::string& dictionary_text,
} }
}; };
#if defined(OS_CHROMEOS)
// For debugging http://crbug.com/454198; remove when resolved.
CHECK_EQ(0u, destroyed_);
CHECK(clock_.get());
#endif
std::vector<DictionaryItem> stale_dictionary_list; std::vector<DictionaryItem> stale_dictionary_list;
size_t recoverable_bytes = 0; size_t recoverable_bytes = 0;
base::Time stale_boundary(clock_->Now() - base::TimeDelta::FromDays(1)); base::Time stale_boundary(clock_->Now() - base::TimeDelta::FromDays(1));
...@@ -151,6 +175,12 @@ void SdchOwner::OnDictionaryFetched(const std::string& dictionary_text, ...@@ -151,6 +175,12 @@ void SdchOwner::OnDictionaryFetched(const std::string& dictionary_text,
} }
} }
#if defined(OS_CHROMEOS)
// For debugging http://crbug.com/454198; remove when resolved.
CHECK_EQ(0u, destroyed_);
CHECK(clock_.get());
#endif
if (total_dictionary_bytes_ + dictionary_text.size() - recoverable_bytes > if (total_dictionary_bytes_ + dictionary_text.size() - recoverable_bytes >
max_total_dictionary_size_) { max_total_dictionary_size_) {
RecordDictionaryFate(DICTIONARY_FATE_FETCH_IGNORED_NO_SPACE); RecordDictionaryFate(DICTIONARY_FATE_FETCH_IGNORED_NO_SPACE);
...@@ -198,6 +228,12 @@ void SdchOwner::OnDictionaryFetched(const std::string& dictionary_text, ...@@ -198,6 +228,12 @@ void SdchOwner::OnDictionaryFetched(const std::string& dictionary_text,
// to avoid taking too much time/space with useless dictionaries/one-off // to avoid taking too much time/space with useless dictionaries/one-off
// visits to web sites. // visits to web sites.
clock_->Now() - base::TimeDelta::FromHours(23), dictionary_text.size()); clock_->Now() - base::TimeDelta::FromHours(23), dictionary_text.size());
#if defined(OS_CHROMEOS)
// For debugging http://crbug.com/454198; remove when resolved.
CHECK_EQ(0u, destroyed_);
CHECK(clock_.get());
#endif
} }
void SdchOwner::OnDictionaryUsed(SdchManager* manager, void SdchOwner::OnDictionaryUsed(SdchManager* manager,
...@@ -212,6 +248,12 @@ void SdchOwner::OnDictionaryUsed(SdchManager* manager, ...@@ -212,6 +248,12 @@ void SdchOwner::OnDictionaryUsed(SdchManager* manager,
void SdchOwner::OnGetDictionary(net::SdchManager* manager, void SdchOwner::OnGetDictionary(net::SdchManager* manager,
const GURL& request_url, const GURL& request_url,
const GURL& dictionary_url) { const GURL& dictionary_url) {
#if defined(OS_CHROMEOS)
// For debugging http://crbug.com/454198; remove when resolved.
CHECK_EQ(0u, destroyed_);
CHECK(clock_.get());
#endif
base::Time stale_boundary(clock_->Now() - base::TimeDelta::FromDays(1)); base::Time stale_boundary(clock_->Now() - base::TimeDelta::FromDays(1));
size_t avail_bytes = 0; size_t avail_bytes = 0;
for (auto it = local_dictionary_info_.begin(); for (auto it = local_dictionary_info_.begin();
...@@ -245,6 +287,12 @@ void SdchOwner::OnClearDictionaries(net::SdchManager* manager) { ...@@ -245,6 +287,12 @@ void SdchOwner::OnClearDictionaries(net::SdchManager* manager) {
void SdchOwner::SetClockForTesting(scoped_ptr<base::Clock> clock) { void SdchOwner::SetClockForTesting(scoped_ptr<base::Clock> clock) {
clock_ = clock.Pass(); clock_ = clock.Pass();
#if defined(OS_CHROMEOS)
// For debugging http://crbug.com/454198; remove when resolved.
CHECK_EQ(0u, destroyed_);
CHECK(clock_.get());
#endif
} }
void SdchOwner::OnMemoryPressure( void SdchOwner::OnMemoryPressure(
......
...@@ -87,6 +87,11 @@ class NET_EXPORT SdchOwner : public net::SdchObserver { ...@@ -87,6 +87,11 @@ class NET_EXPORT SdchOwner : public net::SdchObserver {
size_t max_total_dictionary_size_; size_t max_total_dictionary_size_;
size_t min_space_for_dictionary_fetch_; size_t min_space_for_dictionary_fetch_;
#if defined(OS_CHROMEOS)
// For debugging http://crbug.com/454198; remove when resolved.
unsigned int destroyed_;
#endif
base::MemoryPressureListener memory_pressure_listener_; base::MemoryPressureListener memory_pressure_listener_;
DISALLOW_COPY_AND_ASSIGN(SdchOwner); DISALLOW_COPY_AND_ASSIGN(SdchOwner);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment