| Index: chrome/browser/chromeos/drive/drive_file_stream_reader.cc
|
| diff --git a/chrome/browser/chromeos/drive/drive_file_stream_reader.cc b/chrome/browser/chromeos/drive/drive_file_stream_reader.cc
|
| index e9d97b115936e6803b274d78bb759b6c4b637f31..44d9bf45cc6da055a203fa5198cb0c0ccbe967d0 100644
|
| --- a/chrome/browser/chromeos/drive/drive_file_stream_reader.cc
|
| +++ b/chrome/browser/chromeos/drive/drive_file_stream_reader.cc
|
| @@ -29,12 +29,6 @@ int FileErrorToNetError(FileError error) {
|
| return net::FileErrorToNetError(FileErrorToBaseFileError(error));
|
| }
|
|
|
| -// Runs task on UI thread.
|
| -void RunTaskOnUIThread(const base::Closure& task) {
|
| - google_apis::RunTaskOnThread(
|
| - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), task);
|
| -}
|
| -
|
| // Computes the concrete |start| offset and the |length| of |range| in a file
|
| // of |total| size.
|
| //
|
| @@ -273,7 +267,7 @@ namespace {
|
| // Calls FileSystemInterface::GetFileContent if the file system
|
| // is available. If not, the |completion_callback| is invoked with
|
| // FILE_ERROR_FAILED.
|
| -void GetFileContentOnUIThread(
|
| +base::Closure GetFileContentOnUIThread(
|
| const DriveFileStreamReader::FileSystemGetter& file_system_getter,
|
| const base::FilePath& drive_file_path,
|
| const GetFileContentInitializedCallback& initialized_callback,
|
| @@ -284,13 +278,14 @@ void GetFileContentOnUIThread(
|
| FileSystemInterface* file_system = file_system_getter.Run();
|
| if (!file_system) {
|
| completion_callback.Run(FILE_ERROR_FAILED);
|
| - return;
|
| + return base::Closure();
|
| }
|
|
|
| - file_system->GetFileContent(drive_file_path,
|
| - initialized_callback,
|
| - get_content_callback,
|
| - completion_callback);
|
| + return google_apis::CreateRelayCallback(
|
| + file_system->GetFileContent(drive_file_path,
|
| + initialized_callback,
|
| + get_content_callback,
|
| + completion_callback));
|
| }
|
|
|
| // Helper to run FileSystemInterface::GetFileContent on UI thread.
|
| @@ -299,10 +294,11 @@ void GetFileContent(
|
| const base::FilePath& drive_file_path,
|
| const GetFileContentInitializedCallback& initialized_callback,
|
| const google_apis::GetContentCallback& get_content_callback,
|
| - const FileOperationCallback& completion_callback) {
|
| + const FileOperationCallback& completion_callback,
|
| + const base::Callback<void(const base::Closure&)>& reply_callback) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
|
|
| - BrowserThread::PostTask(
|
| + BrowserThread::PostTaskAndReplyWithResult(
|
| BrowserThread::UI,
|
| FROM_HERE,
|
| base::Bind(&GetFileContentOnUIThread,
|
| @@ -310,7 +306,8 @@ void GetFileContent(
|
| drive_file_path,
|
| google_apis::CreateRelayCallback(initialized_callback),
|
| google_apis::CreateRelayCallback(get_content_callback),
|
| - google_apis::CreateRelayCallback(completion_callback)));
|
| + google_apis::CreateRelayCallback(completion_callback)),
|
| + reply_callback);
|
| }
|
|
|
| } // namespace
|
| @@ -351,7 +348,9 @@ void DriveFileStreamReader::Initialize(
|
| weak_ptr_factory_.GetWeakPtr()),
|
| base::Bind(&DriveFileStreamReader::OnGetFileContentCompletion,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| - callback));
|
| + callback),
|
| + base::Bind(&DriveFileStreamReader::StoreCancelDownloadClosure,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| }
|
|
|
| int DriveFileStreamReader::Read(net::IOBuffer* buffer, int buffer_length,
|
| @@ -363,14 +362,21 @@ int DriveFileStreamReader::Read(net::IOBuffer* buffer, int buffer_length,
|
| return reader_proxy_->Read(buffer, buffer_length, callback);
|
| }
|
|
|
| +void DriveFileStreamReader::StoreCancelDownloadClosure(
|
| + const base::Closure& cancel_download_closure) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + cancel_download_closure_ = cancel_download_closure;
|
| +}
|
| +
|
| void DriveFileStreamReader::InitializeAfterGetFileContentInitialized(
|
| const net::HttpByteRange& byte_range,
|
| const InitializeCompletionCallback& callback,
|
| FileError error,
|
| - scoped_ptr<ResourceEntry> entry,
|
| const base::FilePath& local_cache_file_path,
|
| - const base::Closure& ui_cancel_download_closure) {
|
| + scoped_ptr<ResourceEntry> entry) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + // StoreCancelDownloadClosure() should be called before this function.
|
| + DCHECK(!cancel_download_closure_.is_null());
|
|
|
| if (error != FILE_ERROR_OK) {
|
| callback.Run(FileErrorToNetError(error), scoped_ptr<ResourceEntry>());
|
| @@ -385,8 +391,7 @@ void DriveFileStreamReader::InitializeAfterGetFileContentInitialized(
|
| // At the same time, we cancel the in-flight downloading operation if
|
| // needed and and invalidate weak pointers so that we won't
|
| // receive unwanted callbacks.
|
| - if (!ui_cancel_download_closure.is_null())
|
| - RunTaskOnUIThread(ui_cancel_download_closure);
|
| + cancel_download_closure_.Run();
|
| weak_ptr_factory_.InvalidateWeakPtrs();
|
| callback.Run(
|
| net::ERR_REQUEST_RANGE_NOT_SATISFIABLE, scoped_ptr<ResourceEntry>());
|
| @@ -395,11 +400,9 @@ void DriveFileStreamReader::InitializeAfterGetFileContentInitialized(
|
|
|
| if (local_cache_file_path.empty()) {
|
| // The file is not cached, and being downloaded.
|
| - DCHECK(!ui_cancel_download_closure.is_null());
|
| reader_proxy_.reset(
|
| new internal::NetworkReaderProxy(
|
| - range_start, range_length,
|
| - base::Bind(&RunTaskOnUIThread, ui_cancel_download_closure)));
|
| + range_start, range_length, cancel_download_closure_));
|
| callback.Run(net::OK, entry.Pass());
|
| return;
|
| }
|
|
|