Skip to content

Commit

Permalink
Update net/ to use WeakPtr<T>::get() instead of implicit "operator T*"
Browse files Browse the repository at this point in the history
BUG=245942

Review URL: https://chromiumcodereview.appspot.com/15881011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203633 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
akalin@chromium.org committed Jun 2, 2013
1 parent 5c6ac84 commit 11fbca0
Show file tree
Hide file tree
Showing 20 changed files with 134 additions and 133 deletions.
50 changes: 25 additions & 25 deletions net/disk_cache/entry_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class EntryImpl::UserBuffer {
buffer_.reserve(kMaxBlockSize);
}
~UserBuffer() {
if (backend_)
if (backend_.get())
backend_->BufferDeleted(capacity() - kMaxBlockSize);
}

Expand Down Expand Up @@ -252,7 +252,7 @@ int EntryImpl::UserBuffer::Read(int offset, IOBuffer* buf, int len) {

void EntryImpl::UserBuffer::Reset() {
if (!grow_allowed_) {
if (backend_)
if (backend_.get())
backend_->BufferDeleted(capacity() - kMaxBlockSize);
grow_allowed_ = true;
std::vector<char> tmp;
Expand All @@ -272,7 +272,7 @@ bool EntryImpl::UserBuffer::GrowBuffer(int required, int limit) {
if (required > limit)
return false;

if (!backend_)
if (!backend_.get())
return false;

int to_add = std::max(required - current_size, kMaxBlockSize * 4);
Expand Down Expand Up @@ -302,7 +302,7 @@ EntryImpl::EntryImpl(BackendImpl* backend, Addr address, bool read_only)
}

void EntryImpl::DoomImpl() {
if (doomed_ || !backend_)
if (doomed_ || !backend_.get())
return;

SetPointerForInvalidEntry(backend_->GetCurrentEntryId());
Expand Down Expand Up @@ -672,7 +672,7 @@ void EntryImpl::IncrementIoCount() {
}

void EntryImpl::DecrementIoCount() {
if (backend_)
if (backend_.get())
backend_->DecrementIoCount();
}

Expand All @@ -688,7 +688,7 @@ void EntryImpl::SetTimes(base::Time last_used, base::Time last_modified) {
}

void EntryImpl::ReportIOTime(Operation op, const base::TimeTicks& start) {
if (!backend_)
if (!backend_.get())
return;

switch (op) {
Expand Down Expand Up @@ -746,12 +746,12 @@ int EntryImpl::NumBlocksForEntry(int key_size) {
// ------------------------------------------------------------------------

void EntryImpl::Doom() {
if (background_queue_)
if (background_queue_.get())
background_queue_->DoomEntryImpl(this);
}

void EntryImpl::Close() {
if (background_queue_)
if (background_queue_.get())
background_queue_->CloseEntryImpl(this);
}

Expand Down Expand Up @@ -821,7 +821,7 @@ int EntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len,
if (buf_len < 0)
return net::ERR_INVALID_ARGUMENT;

if (!background_queue_)
if (!background_queue_.get())
return net::ERR_UNEXPECTED;

background_queue_->ReadData(this, index, offset, buf, buf_len, callback);
Expand All @@ -840,7 +840,7 @@ int EntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len,
if (offset < 0 || buf_len < 0)
return net::ERR_INVALID_ARGUMENT;

if (!background_queue_)
if (!background_queue_.get())
return net::ERR_UNEXPECTED;

background_queue_->WriteData(this, index, offset, buf, buf_len, truncate,
Expand All @@ -853,7 +853,7 @@ int EntryImpl::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len,
if (callback.is_null())
return ReadSparseDataImpl(offset, buf, buf_len, callback);

if (!background_queue_)
if (!background_queue_.get())
return net::ERR_UNEXPECTED;

background_queue_->ReadSparseData(this, offset, buf, buf_len, callback);
Expand All @@ -865,7 +865,7 @@ int EntryImpl::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len,
if (callback.is_null())
return WriteSparseDataImpl(offset, buf, buf_len, callback);

if (!background_queue_)
if (!background_queue_.get())
return net::ERR_UNEXPECTED;

background_queue_->WriteSparseData(this, offset, buf, buf_len, callback);
Expand All @@ -874,7 +874,7 @@ int EntryImpl::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len,

int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
const CompletionCallback& callback) {
if (!background_queue_)
if (!background_queue_.get())
return net::ERR_UNEXPECTED;

background_queue_->GetAvailableRange(this, offset, len, start, callback);
Expand All @@ -891,15 +891,15 @@ bool EntryImpl::CouldBeSparse() const {
}

void EntryImpl::CancelSparseIO() {
if (background_queue_)
if (background_queue_.get())
background_queue_->CancelSparseIO(this);
}

int EntryImpl::ReadyForSparseIO(const CompletionCallback& callback) {
if (!sparse_.get())
return net::OK;

if (!background_queue_)
if (!background_queue_.get())
return net::ERR_UNEXPECTED;

background_queue_->ReadyForSparseIO(this, callback);
Expand All @@ -913,7 +913,7 @@ int EntryImpl::ReadyForSparseIO(const CompletionCallback& callback) {
// data related to a previous cache entry because the range was not fully
// written before).
EntryImpl::~EntryImpl() {
if (!backend_) {
if (!backend_.get()) {
entry_.clear_modified();
node_.clear_modified();
return;
Expand Down Expand Up @@ -981,7 +981,7 @@ int EntryImpl::InternalReadData(int index, int offset,
if (buf_len < 0)
return net::ERR_INVALID_ARGUMENT;

if (!backend_)
if (!backend_.get())
return net::ERR_UNEXPECTED;

TimeTicks start = TimeTicks::Now();
Expand Down Expand Up @@ -1063,7 +1063,7 @@ int EntryImpl::InternalWriteData(int index, int offset,
if (offset < 0 || buf_len < 0)
return net::ERR_INVALID_ARGUMENT;

if (!backend_)
if (!backend_.get())
return net::ERR_UNEXPECTED;

int max_file_size = backend_->MaxFileSize();
Expand Down Expand Up @@ -1171,7 +1171,7 @@ bool EntryImpl::CreateDataBlock(int index, int size) {

bool EntryImpl::CreateBlock(int size, Addr* address) {
DCHECK(!address->is_initialized());
if (!backend_)
if (!backend_.get())
return false;

FileType file_type = Addr::RequiredFileType(size);
Expand All @@ -1196,7 +1196,7 @@ bool EntryImpl::CreateBlock(int size, Addr* address) {
// important that the entry doesn't keep a reference to this address, or we'll
// end up deleting the contents of |address| once again.
void EntryImpl::DeleteData(Addr address, int index) {
DCHECK(backend_);
DCHECK(backend_.get());
if (!address.is_initialized())
return;
if (address.is_separate_file()) {
Expand All @@ -1214,7 +1214,7 @@ void EntryImpl::DeleteData(Addr address, int index) {
}

void EntryImpl::UpdateRank(bool modified) {
if (!backend_)
if (!backend_.get())
return;

if (!doomed_) {
Expand All @@ -1231,7 +1231,7 @@ void EntryImpl::UpdateRank(bool modified) {
}

File* EntryImpl::GetBackingFile(Addr address, int index) {
if (!backend_)
if (!backend_.get())
return NULL;

File* file;
Expand Down Expand Up @@ -1288,7 +1288,7 @@ bool EntryImpl::PrepareTarget(int index, int offset, int buf_len,
}

if (!user_buffers_[index].get())
user_buffers_[index].reset(new UserBuffer(backend_));
user_buffers_[index].reset(new UserBuffer(backend_.get()));

return PrepareBuffer(index, offset, buf_len);
}
Expand Down Expand Up @@ -1359,7 +1359,7 @@ bool EntryImpl::CopyToLocalBuffer(int index) {
DCHECK(address.is_initialized());

int len = std::min(entry_.Data()->data_size[index], kMaxBlockSize);
user_buffers_[index].reset(new UserBuffer(backend_));
user_buffers_[index].reset(new UserBuffer(backend_.get()));
user_buffers_[index]->Write(len, NULL, 0);

File* file = GetBackingFile(address, index);
Expand Down Expand Up @@ -1505,7 +1505,7 @@ uint32 EntryImpl::GetEntryFlags() {
}

void EntryImpl::GetData(int index, char** buffer, Addr* address) {
DCHECK(backend_);
DCHECK(backend_.get());
if (user_buffers_[index].get() && user_buffers_[index]->Size() &&
!user_buffers_[index]->Start()) {
// The data is already in memory, just copy it and we're done.
Expand Down
8 changes: 4 additions & 4 deletions net/disk_cache/simple/simple_backend_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void SimpleBackendImpl::IndexReadyForDoom(Time initial_time,
EntryMap::iterator it = active_entries_.find(entry_hash);
if (it == active_entries_.end())
continue;
SimpleEntryImpl* entry = it->second;
SimpleEntryImpl* entry = it->second.get();
entry->Doom();

(*removed_key_hashes)[i] = removed_key_hashes->back();
Expand Down Expand Up @@ -330,12 +330,12 @@ scoped_refptr<SimpleEntryImpl> SimpleBackendImpl::CreateOrFindActiveEntry(
base::WeakPtr<SimpleEntryImpl>()));
EntryMap::iterator& it = insert_result.first;
if (insert_result.second)
DCHECK(!it->second);
if (!it->second) {
DCHECK(!it->second.get());
if (!it->second.get()) {
SimpleEntryImpl* entry = new SimpleEntryImpl(this, path_, key, entry_hash);
it->second = entry->AsWeakPtr();
}
DCHECK(it->second);
DCHECK(it->second.get());
// It's possible, but unlikely, that we have an entry hash collision with a
// currently active entry.
if (key != it->second->key()) {
Expand Down
20 changes: 10 additions & 10 deletions net/disk_cache/simple/simple_entry_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ SimpleEntryImpl::SimpleEntryImpl(SimpleBackendImpl* backend,

int SimpleEntryImpl::OpenEntry(Entry** out_entry,
const CompletionCallback& callback) {
DCHECK(backend_);
DCHECK(backend_.get());
// This enumeration is used in histograms, add entries only at end.
enum OpenEntryIndexEnum {
INDEX_NOEXIST = 0,
Expand All @@ -126,7 +126,7 @@ int SimpleEntryImpl::OpenEntry(Entry** out_entry,
INDEX_MAX = 3,
};
OpenEntryIndexEnum open_entry_index_enum = INDEX_NOEXIST;
if (backend_) {
if (backend_.get()) {
if (backend_->index()->Has(key_))
open_entry_index_enum = INDEX_HIT;
else
Expand All @@ -147,7 +147,7 @@ int SimpleEntryImpl::OpenEntry(Entry** out_entry,

int SimpleEntryImpl::CreateEntry(Entry** out_entry,
const CompletionCallback& callback) {
DCHECK(backend_);
DCHECK(backend_.get());
int ret_value = net::ERR_FAILED;
if (state_ == STATE_UNINITIALIZED &&
pending_operations_.size() == 0) {
Expand All @@ -171,7 +171,7 @@ int SimpleEntryImpl::CreateEntry(Entry** out_entry,
// have the entry in the index but we don't have the created files yet, this
// way we never leak files. CreationOperationComplete will remove the entry
// from the index if the creation fails.
if (backend_)
if (backend_.get())
backend_->index()->Insert(key_);

RunNextOperationIfNeeded();
Expand Down Expand Up @@ -274,7 +274,7 @@ int SimpleEntryImpl::WriteData(int stream_index,
RecordWriteResult(WRITE_RESULT_INVALID_ARGUMENT);
return net::ERR_INVALID_ARGUMENT;
}
if (backend_ && offset + buf_len > backend_->GetMaxFileSize()) {
if (backend_.get() && offset + buf_len > backend_->GetMaxFileSize()) {
RecordWriteResult(WRITE_RESULT_OVER_MAX_SIZE);
return net::ERR_FAILED;
}
Expand Down Expand Up @@ -385,14 +385,14 @@ void SimpleEntryImpl::ReturnEntryToCaller(Entry** out_entry) {
}

void SimpleEntryImpl::RemoveSelfFromBackend() {
if (!backend_)
if (!backend_.get())
return;
backend_->OnDeactivated(this);
backend_.reset();
}

void SimpleEntryImpl::MarkAsDoomed() {
if (!backend_)
if (!backend_.get())
return;
backend_->index()->Remove(key_);
RemoveSelfFromBackend();
Expand Down Expand Up @@ -543,7 +543,7 @@ void SimpleEntryImpl::ReadDataInternal(int stream_index,
buf_len = std::min(buf_len, GetDataSize(stream_index) - offset);

state_ = STATE_IO_PENDING;
if (backend_)
if (backend_.get())
backend_->index()->UseIfExists(key_);

scoped_ptr<uint32> read_crc32(new uint32());
Expand Down Expand Up @@ -579,7 +579,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index,
}
DCHECK_EQ(STATE_READY, state_);
state_ = STATE_IO_PENDING;
if (backend_)
if (backend_.get())
backend_->index()->UseIfExists(key_);
// It is easy to incrementally compute the CRC from [0 .. |offset + buf_len|)
// if |offset == 0| or we have already computed the CRC for [0 .. offset).
Expand Down Expand Up @@ -786,7 +786,7 @@ void SimpleEntryImpl::SetSynchronousData() {
last_modified_ = synchronous_entry_->last_modified();
for (int i = 0; i < kSimpleEntryFileCount; ++i)
data_size_[i] = synchronous_entry_->data_size(i);
if (backend_)
if (backend_.get())
backend_->index()->UpdateEntrySize(key_, synchronous_entry_->GetFileSize());
}

Expand Down
14 changes: 7 additions & 7 deletions net/disk_cache/sparse_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void ChildrenDeleter::Start(char* buffer, int len) {

void ChildrenDeleter::ReadData(disk_cache::Addr address, int len) {
DCHECK(address.is_block_file());
if (!backend_)
if (!backend_.get())
return Release();

disk_cache::File* file(backend_->File(address));
Expand All @@ -127,7 +127,7 @@ void ChildrenDeleter::ReadData(disk_cache::Addr address, int len) {

void ChildrenDeleter::DeleteChildren() {
int child_id = 0;
if (!children_map_.FindNextSetBit(&child_id) || !backend_) {
if (!children_map_.FindNextSetBit(&child_id) || !backend_.get()) {
// We are done. Just delete this object.
return Release();
}
Expand Down Expand Up @@ -350,9 +350,9 @@ void SparseControl::DeleteChildren(EntryImpl* entry) {

entry->net_log().AddEvent(net::NetLog::TYPE_SPARSE_DELETE_CHILDREN);

DCHECK(entry->backend_);
ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_,
entry->GetKey());
DCHECK(entry->backend_.get());
ChildrenDeleter* deleter =
new ChildrenDeleter(entry->backend_.get(), entry->GetKey());
// The object will self destruct when finished.
deleter->AddRef();

Expand Down Expand Up @@ -461,7 +461,7 @@ bool SparseControl::OpenChild() {
if (!ChildPresent())
return ContinueWithoutChild(key);

if (!entry_->backend_)
if (!entry_->backend_.get())
return false;

child_ = entry_->backend_->OpenEntryImpl(key);
Expand Down Expand Up @@ -539,7 +539,7 @@ bool SparseControl::ContinueWithoutChild(const std::string& key) {
if (kGetRangeOperation == operation_)
return true;

if (!entry_->backend_)
if (!entry_->backend_.get())
return false;

child_ = entry_->backend_->CreateEntryImpl(key);
Expand Down
Loading

0 comments on commit 11fbca0

Please sign in to comment.