Commit 7667e30f authored by Stuart Langley's avatar Stuart Langley Committed by Commit Bot

Cleanup/Modernize code in chrome/browser/chromeos/drive

Some cleanup work for chrome/browser/chromeos/drive briging it in line
with recomended practices/c++ modernization.

- Use ThreadChecker macros.
- s/DCHECK(!callback.is_null())/DCHECK(callback)/

Ths CL introduces no logic changes.

Bug: 841659
Change-Id: I5a5784d2de7d8f1be0e6240414d7c64c921d3cff
Reviewed-on: https://chromium-review.googlesource.com/1122029Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Stuart Langley <slangley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572019}
parent e1cdab9d
......@@ -32,7 +32,7 @@ void IterateFileCacheInternal(
void RunGetResourceEntryCallback(const GetResourceEntryCallback& callback,
std::unique_ptr<ResourceEntry> entry,
FileError error) {
DCHECK(!callback.is_null());
DCHECK(callback);
if (error != FILE_ERROR_OK)
entry.reset();
callback.Run(error, std::move(entry));
......@@ -43,7 +43,7 @@ void RunReadDirectoryCallback(
const DebugInfoCollector::ReadDirectoryCallback& callback,
std::unique_ptr<ResourceEntryVector> entries,
FileError error) {
DCHECK(!callback.is_null());
DCHECK(callback);
if (error != FILE_ERROR_OK)
entries.reset();
callback.Run(error, std::move(entries));
......@@ -67,8 +67,8 @@ DebugInfoCollector::~DebugInfoCollector() = default;
void DebugInfoCollector::GetResourceEntry(
const base::FilePath& file_path,
const GetResourceEntryCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!callback.is_null());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(callback);
std::unique_ptr<ResourceEntry> entry(new ResourceEntry);
ResourceEntry* entry_ptr = entry.get();
......@@ -85,8 +85,8 @@ void DebugInfoCollector::GetResourceEntry(
void DebugInfoCollector::ReadDirectory(
const base::FilePath& file_path,
const ReadDirectoryCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!callback.is_null());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(callback);
std::unique_ptr<ResourceEntryVector> entries(new ResourceEntryVector);
ResourceEntryVector* entries_ptr = entries.get();
......@@ -103,9 +103,9 @@ void DebugInfoCollector::ReadDirectory(
void DebugInfoCollector::IterateFileCache(
const IterateFileCacheCallback& iteration_callback,
const base::Closure& completion_callback) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!iteration_callback.is_null());
DCHECK(!completion_callback.is_null());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(iteration_callback);
DCHECK(completion_callback);
blocking_task_runner_->PostTaskAndReply(
FROM_HERE,
......@@ -116,8 +116,8 @@ void DebugInfoCollector::IterateFileCache(
void DebugInfoCollector::GetMetadata(
const GetFilesystemMetadataCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!callback.is_null());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(callback);
// Currently, this is just a proxy to the FileSystem.
// TODO(hidehiko): Move the implementation to here to simplify the
......
......@@ -58,7 +58,7 @@ class DebugInfoCollector {
FileSystemInterface* file_system_; // Not owned.
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
base::ThreadChecker thread_checker_;
THREAD_CHECKER(thread_checker_);
DISALLOW_COPY_AND_ASSIGN(DebugInfoCollector);
};
......
......@@ -111,7 +111,7 @@ LocalReaderProxy::~LocalReaderProxy() = default;
int LocalReaderProxy::Read(net::IOBuffer* buffer, int buffer_length,
const net::CompletionCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(file_reader_);
if (buffer_length > remaining_length_) {
......@@ -141,7 +141,7 @@ void LocalReaderProxy::OnCompleted(FileError error) {
void LocalReaderProxy::OnReadCompleted(const net::CompletionCallback& callback,
int read_result) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(file_reader_);
if (read_result >= 0) {
......@@ -174,7 +174,7 @@ NetworkReaderProxy::~NetworkReaderProxy() {
int NetworkReaderProxy::Read(net::IOBuffer* buffer, int buffer_length,
const net::CompletionCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
// Check if there is no pending Read operation.
DCHECK(!buffer_.get());
DCHECK_EQ(buffer_length_, 0);
......@@ -182,7 +182,7 @@ int NetworkReaderProxy::Read(net::IOBuffer* buffer, int buffer_length,
// Validate the arguments.
DCHECK(buffer);
DCHECK_GT(buffer_length, 0);
DCHECK(!callback.is_null());
DCHECK(callback);
if (error_code_ != net::OK) {
// An error is already found. Return it immediately.
......@@ -221,7 +221,7 @@ int NetworkReaderProxy::Read(net::IOBuffer* buffer, int buffer_length,
}
void NetworkReaderProxy::OnGetContent(std::unique_ptr<std::string> data) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(data && !data->empty());
if (remaining_offset_ >= static_cast<int64_t>(data->length())) {
......@@ -256,7 +256,7 @@ void NetworkReaderProxy::OnGetContent(std::unique_ptr<std::string> data) {
}
void NetworkReaderProxy::OnCompleted(FileError error) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
// The downloading is completed, so we do not need to cancel the job
// in the destructor.
job_canceller_.Reset();
......@@ -341,7 +341,7 @@ DriveFileStreamReader::DriveFileStreamReader(
DriveFileStreamReader::~DriveFileStreamReader() = default;
bool DriveFileStreamReader::IsInitialized() const {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
return reader_proxy_.get() != nullptr;
}
......@@ -349,8 +349,8 @@ void DriveFileStreamReader::Initialize(
const base::FilePath& drive_file_path,
const net::HttpByteRange& byte_range,
const InitializeCompletionCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!callback.is_null());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(callback);
GetFileContent(
file_system_getter_,
......@@ -371,16 +371,16 @@ void DriveFileStreamReader::Initialize(
int DriveFileStreamReader::Read(net::IOBuffer* buffer, int buffer_length,
const net::CompletionCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(reader_proxy_);
DCHECK(buffer);
DCHECK(!callback.is_null());
DCHECK(callback);
return reader_proxy_->Read(buffer, buffer_length, callback);
}
void DriveFileStreamReader::StoreCancelDownloadClosure(
const base::Closure& cancel_download_closure) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
cancel_download_closure_ = cancel_download_closure;
}
......@@ -390,7 +390,7 @@ void DriveFileStreamReader::InitializeAfterGetFileContentInitialized(
FileError error,
const base::FilePath& local_cache_file_path,
std::unique_ptr<ResourceEntry> entry) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
// StoreCancelDownloadClosure() should be called before this function.
DCHECK(!cancel_download_closure_.is_null());
......@@ -445,7 +445,7 @@ void DriveFileStreamReader::InitializeAfterLocalFileOpen(
std::unique_ptr<ResourceEntry> entry,
std::unique_ptr<util::LocalFileReader> file_reader,
int open_result) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (open_result != net::OK) {
callback.Run(net::ERR_FAILED, std::unique_ptr<ResourceEntry>());
......@@ -460,7 +460,7 @@ void DriveFileStreamReader::InitializeAfterLocalFileOpen(
void DriveFileStreamReader::OnGetContent(
google_apis::DriveApiErrorCode error_code,
std::unique_ptr<std::string> data) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(reader_proxy_);
reader_proxy_->OnGetContent(std::move(data));
}
......@@ -468,7 +468,7 @@ void DriveFileStreamReader::OnGetContent(
void DriveFileStreamReader::OnGetFileContentCompletion(
const InitializeCompletionCallback& callback,
FileError error) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (reader_proxy_) {
// If the proxy object available, send the error to it.
......
......@@ -81,7 +81,7 @@ class LocalReaderProxy : public ReaderProxy {
// The number of remaining bytes to be read.
int64_t remaining_length_;
base::ThreadChecker thread_checker_;
THREAD_CHECKER(thread_checker_);
// This should remain the last member so it'll be destroyed first and
// invalidate its weak pointers before other members are destroyed.
......@@ -131,7 +131,7 @@ class NetworkReaderProxy : public ReaderProxy {
int buffer_length_;
net::CompletionCallback callback_;
base::ThreadChecker thread_checker_;
THREAD_CHECKER(thread_checker_);
// Keeps the closure to cancel downloading job if necessary.
// Will be reset when the job is completed (regardless whether the job is
......@@ -222,7 +222,7 @@ class DriveFileStreamReader {
base::Closure cancel_download_closure_;
std::unique_ptr<internal::ReaderProxy> reader_proxy_;
base::ThreadChecker thread_checker_;
THREAD_CHECKER(thread_checker_);
// This should remain the last member so it'll be destroyed first and
// invalidate its weak pointers before other members are destroyed.
......
......@@ -553,7 +553,7 @@ void DriveIntegrationService::OnPushNotificationEnabled(bool enabled) {
void DriveIntegrationService::ClearCacheAndRemountFileSystem(
const base::Callback<void(bool)>& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!callback.is_null());
DCHECK(callback);
// TODO(crbug.com/845393): Implement for DriveFS.
if (state_ != INITIALIZED || drivefs_holder_) {
......@@ -589,7 +589,7 @@ void DriveIntegrationService::AddBackDriveMountPoint(
const base::Callback<void(bool)>& callback,
FileError error) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!callback.is_null());
DCHECK(callback);
state_ = error == FILE_ERROR_OK ? INITIALIZED : NOT_INITIALIZED;
......
......@@ -190,7 +190,7 @@ void PrepareWritableFileAndRun(Profile* profile,
const base::FilePath& path,
const PrepareWritableFileCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!callback.is_null());
DCHECK(callback);
FileSystemInterface* file_system = GetFileSystemByProfile(profile);
if (!file_system || !IsUnderDriveMountPoint(path)) {
......@@ -209,7 +209,7 @@ void EnsureDirectoryExists(Profile* profile,
const base::FilePath& directory,
const FileOperationCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!callback.is_null());
DCHECK(callback);
if (IsUnderDriveMountPoint(directory)) {
FileSystemInterface* file_system = GetFileSystemByProfile(profile);
DCHECK(file_system);
......
......@@ -44,7 +44,7 @@ int WebkitFileStreamReaderImpl::Read(net::IOBuffer* buffer,
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(stream_reader_);
DCHECK(buffer);
DCHECK(!callback.is_null());
DCHECK(callback);
if (stream_reader_->IsInitialized())
return stream_reader_->Read(buffer, buffer_length, callback);
......@@ -67,7 +67,7 @@ int64_t WebkitFileStreamReaderImpl::GetLength(
const net::Int64CompletionCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(stream_reader_);
DCHECK(!callback.is_null());
DCHECK(callback);
if (stream_reader_->IsInitialized()) {
// Returns file_size regardless of |offset_|.
......@@ -94,7 +94,7 @@ void WebkitFileStreamReaderImpl::OnStreamReaderInitialized(
std::unique_ptr<ResourceEntry> entry) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(stream_reader_);
DCHECK(!callback.is_null());
DCHECK(callback);
// TODO(hashimoto): Report ERR_UPLOAD_FILE_CHANGED when modification time
// doesn't match. crbug.com/346625
......@@ -116,7 +116,7 @@ void WebkitFileStreamReaderImpl::ReadAfterStreamReaderInitialized(
const net::CompletionCallback& callback,
int initialization_result) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(!callback.is_null());
DCHECK(callback);
if (initialization_result != net::OK) {
callback.Run(initialization_result);
......@@ -133,7 +133,7 @@ void WebkitFileStreamReaderImpl::GetLengthAfterStreamReaderInitialized(
const net::Int64CompletionCallback& callback,
int initialization_result) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(!callback.is_null());
DCHECK(callback);
if (initialization_result != net::OK) {
callback.Run(initialization_result);
......
......@@ -68,7 +68,7 @@ int WebkitFileStreamWriterImpl::Write(net::IOBuffer* buf,
const net::CompletionCallback& callback) {
DCHECK(pending_write_callback_.is_null());
DCHECK(pending_cancel_callback_.is_null());
DCHECK(!callback.is_null());
DCHECK(callback);
// If the local file is already available, just delegate to it.
if (local_file_writer_)
......@@ -90,7 +90,7 @@ int WebkitFileStreamWriterImpl::Write(net::IOBuffer* buf,
int WebkitFileStreamWriterImpl::Cancel(
const net::CompletionCallback& callback) {
DCHECK(pending_cancel_callback_.is_null());
DCHECK(!callback.is_null());
DCHECK(callback);
// If LocalFileWriter is already created, just delegate the cancel to it.
if (local_file_writer_)
......@@ -111,7 +111,7 @@ int WebkitFileStreamWriterImpl::Cancel(
int WebkitFileStreamWriterImpl::Flush(const net::CompletionCallback& callback) {
DCHECK(pending_cancel_callback_.is_null());
DCHECK(!callback.is_null());
DCHECK(callback);
// If LocalFileWriter is already created, just delegate to it.
if (local_file_writer_)
......
......@@ -22,7 +22,7 @@ void RunCloseCallbackAndReplyTask(const base::Closure& close_callback,
FileError error) {
if (!close_callback.is_null())
close_callback.Run();
DCHECK(!reply.is_null());
DCHECK(reply);
reply.Run(error);
}
......@@ -61,8 +61,8 @@ void WriteOnCacheFileAndReply(FileSystemInterface* file_system,
const FileOperationCallback& reply) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(file_system);
DCHECK(!callback.is_null());
DCHECK(!reply.is_null());
DCHECK(callback);
DCHECK(reply);
file_system->OpenFile(
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