Commit 67a627d5 authored by ajith.v's avatar ajith.v Committed by Commit bot

Reorganizing few DCHECKs for better catching of failrue.

In current code, some of the DCHECKs are having multiple conditions.
It's difficult to identify the failures if DCHECK fails due to one
of those conditions. Now moved the conditions to separate DCHECKs, so
that failure can identify at correct point.

BUG=

Review-Url: https://codereview.chromium.org/2168093002
Cr-Commit-Position: refs/heads/master@{#407201}
parent b9ca2ee1
......@@ -158,7 +158,7 @@ void BrowserThreadImpl::ShutdownThreadPool() {
// static
void BrowserThreadImpl::FlushThreadPoolHelperForTesting() {
// We don't want to create a pool if none exists.
if (g_globals == NULL)
if (g_globals == nullptr)
return;
g_globals.Get().blocking_pool->FlushForTesting();
disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
......@@ -286,15 +286,16 @@ void BrowserThreadImpl::CleanUp() {
// to prevent a race with accessing the message loop in PostTaskHelper(),
// remove this thread from the global array now.
base::AutoLock lock(globals.lock);
globals.threads[identifier_] = NULL;
globals.threads[identifier_] = nullptr;
}
void BrowserThreadImpl::Initialize() {
BrowserThreadGlobals& globals = g_globals.Get();
base::AutoLock lock(globals.lock);
DCHECK(identifier_ >= 0 && identifier_ < ID_COUNT);
DCHECK(globals.threads[identifier_] == NULL);
DCHECK_GE(identifier_, 0);
DCHECK_LT(identifier_, ID_COUNT);
DCHECK_EQ(globals.threads[identifier_], nullptr);
globals.threads[identifier_] = this;
}
......@@ -306,7 +307,7 @@ BrowserThreadImpl::~BrowserThreadImpl() {
BrowserThreadGlobals& globals = g_globals.Get();
base::AutoLock lock(globals.lock);
globals.threads[identifier_] = NULL;
globals.threads[identifier_] = nullptr;
#ifndef NDEBUG
// Double check that the threads are ordered correctly in the enumeration.
for (int i = identifier_ + 1; i < ID_COUNT; ++i) {
......@@ -332,7 +333,8 @@ bool BrowserThreadImpl::PostTaskHelper(
const base::Closure& task,
base::TimeDelta delay,
bool nestable) {
DCHECK(identifier >= 0 && identifier < ID_COUNT);
DCHECK_GE(identifier, 0);
DCHECK_LT(identifier, ID_COUNT);
// Optimization: to avoid unnecessary locks, we listed the ID enumeration in
// order of lifetime. So no need to lock if we know that the target thread
// outlives current thread.
......@@ -350,7 +352,7 @@ bool BrowserThreadImpl::PostTaskHelper(
base::MessageLoop* message_loop =
globals.threads[identifier] ? globals.threads[identifier]->message_loop()
: NULL;
: nullptr;
if (message_loop) {
if (nestable) {
message_loop->task_runner()->PostDelayedTask(from_here, task, delay);
......@@ -407,20 +409,22 @@ base::SequencedWorkerPool* BrowserThread::GetBlockingPool() {
// static
bool BrowserThread::IsThreadInitialized(ID identifier) {
if (g_globals == NULL)
if (g_globals == nullptr)
return false;
BrowserThreadGlobals& globals = g_globals.Get();
base::AutoLock lock(globals.lock);
DCHECK(identifier >= 0 && identifier < ID_COUNT);
return globals.threads[identifier] != NULL;
DCHECK_GE(identifier, 0);
DCHECK_LT(identifier, ID_COUNT);
return globals.threads[identifier] != nullptr;
}
// static
bool BrowserThread::CurrentlyOn(ID identifier) {
BrowserThreadGlobals& globals = g_globals.Get();
base::AutoLock lock(globals.lock);
DCHECK(identifier >= 0 && identifier < ID_COUNT);
DCHECK_GE(identifier, 0);
DCHECK_LT(identifier, ID_COUNT);
return globals.threads[identifier] &&
globals.threads[identifier]->message_loop() ==
base::MessageLoop::current();
......@@ -442,12 +446,13 @@ std::string BrowserThread::GetDCheckCurrentlyOnErrorMessage(ID expected) {
// static
bool BrowserThread::IsMessageLoopValid(ID identifier) {
if (g_globals == NULL)
if (g_globals == nullptr)
return false;
BrowserThreadGlobals& globals = g_globals.Get();
base::AutoLock lock(globals.lock);
DCHECK(identifier >= 0 && identifier < ID_COUNT);
DCHECK_GE(identifier, 0);
DCHECK_LT(identifier, ID_COUNT);
return globals.threads[identifier] &&
globals.threads[identifier]->message_loop();
}
......@@ -500,7 +505,7 @@ bool BrowserThread::PostTaskAndReply(
// static
bool BrowserThread::GetCurrentThreadIdentifier(ID* identifier) {
if (g_globals == NULL)
if (g_globals == nullptr)
return false;
base::MessageLoop* cur_message_loop = base::MessageLoop::current();
......@@ -529,8 +534,8 @@ BrowserThread::GetTaskRunnerForThread(ID identifier) {
// static
base::MessageLoop* BrowserThread::UnsafeGetMessageLoopForThread(ID identifier) {
if (g_globals == NULL)
return NULL;
if (g_globals == nullptr)
return nullptr;
BrowserThreadGlobals& globals = g_globals.Get();
base::AutoLock lock(globals.lock);
......
......@@ -46,7 +46,7 @@ SaveItem::~SaveItem() {}
// Set start state for save item.
void SaveItem::Start() {
DCHECK(state_ == WAIT_START);
DCHECK_EQ(state_, WAIT_START);
state_ = IN_PROGRESS;
}
......@@ -93,7 +93,8 @@ void SaveItem::Finish(int64_t size, bool is_success) {
}
void SaveItem::SetTargetPath(const base::FilePath& full_path) {
DCHECK(!full_path.empty() && !has_final_name());
DCHECK(!full_path.empty());
DCHECK(!has_final_name());
full_path_ = full_path;
}
......
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