Skip to content

Commit

Permalink
[FileSystem]: Use WeakPtr in FileWriterImpl where appropriate.
Browse files Browse the repository at this point in the history
Bug: 922677
Change-Id: Icd9466fb40cc54e94ffc612801bd73f2e59338ca
Reviewed-on: https://chromium-review.googlesource.com/c/1416630
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#623524}
  • Loading branch information
mkruisselbrink authored and Commit Bot committed Jan 17, 2019
1 parent 3fade37 commit b3a4ffd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions storage/browser/fileapi/file_writer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ FileWriterImpl::FileWriterImpl(
base::WeakPtr<BlobStorageContext> blob_context)
: operation_runner_(std::move(operation_runner)),
blob_context_(std::move(blob_context)),
url_(std::move(url)) {
url_(std::move(url)),
weak_ptr_factory_(this) {
DCHECK(url_.is_valid());
}

Expand All @@ -28,7 +29,7 @@ void FileWriterImpl::Write(uint64_t position,
WriteCallback callback) {
blob_context_->GetBlobDataFromBlobPtr(
std::move(blob),
base::BindOnce(&FileWriterImpl::DoWrite, base::Unretained(this),
base::BindOnce(&FileWriterImpl::DoWrite, weak_ptr_factory_.GetWeakPtr(),
std::move(callback), position));
}

Expand Down
3 changes: 3 additions & 0 deletions storage/browser/fileapi/file_writer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define STORAGE_BROWSER_FILEAPI_FILE_WRITER_IMPL_H_

#include "base/component_export.h"
#include "base/memory/weak_ptr.h"
#include "storage/browser/fileapi/file_system_operation_runner.h"
#include "storage/browser/fileapi/file_system_url.h"
#include "third_party/blink/public/mojom/filesystem/file_writer.mojom.h"
Expand Down Expand Up @@ -60,6 +61,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileWriterImpl
const std::unique_ptr<FileSystemOperationRunner> operation_runner_;
const base::WeakPtr<BlobStorageContext> blob_context_;
const FileSystemURL url_;

base::WeakPtrFactory<FileWriterImpl> weak_ptr_factory_;
};

} // namespace storage
Expand Down

0 comments on commit b3a4ffd

Please sign in to comment.