diff options
author | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-17 12:24:41 +0000 |
---|---|---|
committer | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-17 12:24:41 +0000 |
commit | d748fce1bde33c270b2c6f563d56ba54f5361aaf (patch) | |
tree | 5d2d7bbc6e598cd50ab31ae1fbaad0fcf668ec18 | |
parent | 8d68f288ad832d91bad4caf4de6ca78ffe6dd06a (diff) | |
download | chromium_src-d748fce1bde33c270b2c6f563d56ba54f5361aaf.zip chromium_src-d748fce1bde33c270b2c6f563d56ba54f5361aaf.tar.gz chromium_src-d748fce1bde33c270b2c6f563d56ba54f5361aaf.tar.bz2 |
Some clean up in drive::file_system.
- Consolidate the naming and the argument order of each Operation's constructor.
See DriveOperations::Init. I chose the order:
(observer,scheduler,metadata,cache,file_system,task_runner).
- Remove comments mentioning to running thread. Now our code base
is clean enough about thread safety, even without comments.
- Remove "callback must not be null" from private method comments.
- Fix incorrect #include and forward declarations.
- (Piggyback: One tiny irrelevant comment fix in file_system_util.h)
BUG=none
Review URL: https://chromiumcodereview.appspot.com/15047015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200793 0039d316-1c4b-4281-b951-d872f2087c98
19 files changed, 224 insertions, 338 deletions
diff --git a/chrome/browser/chromeos/drive/file_system.cc b/chrome/browser/chromeos/drive/file_system.cc index f42a428..b6a78f7 100644 --- a/chrome/browser/chromeos/drive/file_system.cc +++ b/chrome/browser/chromeos/drive/file_system.cc @@ -234,12 +234,12 @@ void FileSystem::Initialize() { SetupChangeListLoader(); // Allocate the drive operation handlers. - drive_operations_.Init(scheduler_, - this, // FileSystemInterface - cache_, + drive_operations_.Init(this, // OperationObserver + scheduler_, resource_metadata_, - blocking_task_runner_, - this); // OperationObserver + cache_, + this, // FileSystemInterface + blocking_task_runner_); PrefService* pref_service = profile_->GetPrefs(); hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableDriveHostedFiles); diff --git a/chrome/browser/chromeos/drive/file_system/copy_operation.cc b/chrome/browser/chromeos/drive/file_system/copy_operation.cc index be6029d..ae75595 100644 --- a/chrome/browser/chromeos/drive/file_system/copy_operation.cc +++ b/chrome/browser/chromeos/drive/file_system/copy_operation.cc @@ -56,27 +56,24 @@ std::string GetDocumentResourceIdOnBlockingPool( } // namespace -CopyOperation::CopyOperation( - JobScheduler* job_scheduler, - FileSystemInterface* file_system, - internal::ResourceMetadata* metadata, - internal::FileCache* cache, - scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, - OperationObserver* observer) - : job_scheduler_(job_scheduler), - file_system_(file_system), +CopyOperation::CopyOperation(base::SequencedTaskRunner* blocking_task_runner, + OperationObserver* observer, + JobScheduler* scheduler, + internal::ResourceMetadata* metadata, + internal::FileCache* cache, + FileSystemInterface* file_system) + : blocking_task_runner_(blocking_task_runner), + observer_(observer), + scheduler_(scheduler), metadata_(metadata), cache_(cache), - blocking_task_runner_(blocking_task_runner), - observer_(observer), - create_file_operation_(new CreateFileOperation(job_scheduler, - cache, + file_system_(file_system), + create_file_operation_(new CreateFileOperation(blocking_task_runner, + observer, + scheduler, metadata, - blocking_task_runner, - observer)), - move_operation_(new MoveOperation(job_scheduler, - metadata, - observer)), + cache)), + move_operation_(new MoveOperation(observer, scheduler, metadata)), weak_ptr_factory_(this) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } @@ -222,7 +219,7 @@ void CopyOperation::CopyHostedDocumentToDirectory( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!callback.is_null()); - job_scheduler_->CopyHostedDocument( + scheduler_->CopyHostedDocument( resource_id, base::FilePath(new_name).AsUTF8Unsafe(), base::Bind(&CopyOperation::OnCopyHostedDocumentCompleted, diff --git a/chrome/browser/chromeos/drive/file_system/copy_operation.h b/chrome/browser/chromeos/drive/file_system/copy_operation.h index f1fadfd..4aa5596 100644 --- a/chrome/browser/chromeos/drive/file_system/copy_operation.h +++ b/chrome/browser/chromeos/drive/file_system/copy_operation.h @@ -6,8 +6,10 @@ #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_COPY_OPERATION_H_ #include "base/basictypes.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "base/sequenced_task_runner.h" #include "chrome/browser/chromeos/drive/file_system_interface.h" #include "chrome/browser/google_apis/gdata_errorcode.h" @@ -26,6 +28,7 @@ class ResourceEntry; namespace internal { class FileCache; +class ResourceMetadata; } // namespace internal namespace file_system { @@ -39,40 +42,37 @@ class OperationObserver; // metadata to reflect the new state. class CopyOperation { public: - CopyOperation(JobScheduler* job_scheduler, - FileSystemInterface* file_system, + CopyOperation(base::SequencedTaskRunner* blocking_task_runner, + OperationObserver* observer, + JobScheduler* scheduler, internal::ResourceMetadata* metadata, internal::FileCache* cache, - scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, - OperationObserver* observer); - virtual ~CopyOperation(); + FileSystemInterface* file_system); + ~CopyOperation(); // Performs the copy operation on the file at drive path |src_file_path| // with a target of |dest_file_path|. Invokes |callback| when finished with // the result of the operation. |callback| must not be null. - virtual void Copy(const base::FilePath& src_file_path, - const base::FilePath& dest_file_path, - const FileOperationCallback& callback); + void Copy(const base::FilePath& src_file_path, + const base::FilePath& dest_file_path, + const FileOperationCallback& callback); // Initiates transfer of |remote_src_file_path| to |local_dest_file_path|. // |remote_src_file_path| is the virtual source path on the Drive file system. // |local_dest_file_path| is the destination path on the local file system. // - // Must be called from *UI* thread. |callback| is run on the calling thread. // |callback| must not be null. - virtual void TransferFileFromRemoteToLocal( - const base::FilePath& remote_src_file_path, - const base::FilePath& local_dest_file_path, - const FileOperationCallback& callback); + void TransferFileFromRemoteToLocal(const base::FilePath& remote_src_file_path, + const base::FilePath& local_dest_file_path, + const FileOperationCallback& callback); // Initiates transfer of |local_src_file_path| to |remote_dest_file_path|. // |local_src_file_path| must be a file from the local file system. // |remote_dest_file_path| is the virtual destination path within Drive file // system. // - // Must be called from *UI* thread. |callback| is run on the calling thread. // |callback| must not be null. - virtual void TransferFileFromLocalToRemote( + void TransferFileFromLocalToRemote( const base::FilePath& local_src_file_path, const base::FilePath& remote_dest_file_path, const FileOperationCallback& callback); @@ -98,9 +98,6 @@ class CopyOperation { // TransferFileFromRemoteToLocal. If GetFileByPath reports no error, calls // CopyLocalFileOnBlockingPool to copy |local_file_path| to // |local_dest_file_path|. - // - // Can be called from UI thread. |callback| is run on the calling thread. - // |callback| must not be null. void OnGetFileCompleteForTransferFile( const base::FilePath& local_dest_file_path, const FileOperationCallback& callback, @@ -110,16 +107,12 @@ class CopyOperation { // Copies a hosted document with |resource_id| to the directory at |dir_path| // and names the copied document as |new_name|. - // - // Can be called from UI thread. |callback| is run on the calling thread. - // |callback| must not be null. void CopyHostedDocumentToDirectory(const base::FilePath& dir_path, const std::string& resource_id, const base::FilePath::StringType& new_name, const FileOperationCallback& callback); // Callback for handling document copy attempt. - // |callback| must not be null. void OnCopyHostedDocumentCompleted( const base::FilePath& dir_path, const FileOperationCallback& callback, @@ -129,16 +122,12 @@ class CopyOperation { // Moves a file or directory at |file_path| in the root directory to // another directory at |dir_path|. This function does nothing if // |dir_path| points to the root directory. - // - // Can be called from UI thread. |callback| is run on the calling thread. - // |callback| must not be null. void MoveEntryFromRootDirectory(const base::FilePath& directory_path, const FileOperationCallback& callback, FileError error, const base::FilePath& file_path); - // Part of Copy(). Called after GetResourceEntryPairByPaths() is - // complete. |callback| must not be null. + // Part of Copy(). Called after GetResourceEntryPairByPaths() is complete. void CopyAfterGetResourceEntryPair(const base::FilePath& dest_file_path, const FileOperationCallback& callback, scoped_ptr<EntryInfoPairResult> result); @@ -146,8 +135,6 @@ class CopyOperation { // Invoked upon completion of GetFileByPath initiated by Copy. If // GetFileByPath reports no error, calls TransferRegularFile to transfer // |local_file_path| to |remote_dest_file_path|. - // - // Can be called from UI thread. |callback| is run on the calling thread. void OnGetFileCompleteForCopy(const base::FilePath& remote_dest_file_path, const FileOperationCallback& callback, FileError error, @@ -169,31 +156,26 @@ class CopyOperation { // Drive file system. If |resource_id| is a non-empty string, the transfer is // handled by CopyDocumentToDirectory. Otherwise, the transfer is handled by // TransferRegularFile. - // - // Must be called from *UI* thread. |callback| is run on the calling thread. - // |callback| must not be null. void TransferFileForResourceId(const base::FilePath& local_file_path, const base::FilePath& remote_dest_file_path, const FileOperationCallback& callback, const std::string& resource_id); - JobScheduler* job_scheduler_; - FileSystemInterface* file_system_; - internal::ResourceMetadata* metadata_; - internal::FileCache* cache_; scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; OperationObserver* observer_; + JobScheduler* scheduler_; + internal::ResourceMetadata* metadata_; + internal::FileCache* cache_; + FileSystemInterface* file_system_; // Uploading a new file is internally implemented by creating a dirty file. scoped_ptr<CreateFileOperation> create_file_operation_; // Copying a hosted document is internally implemented by using a move. scoped_ptr<MoveOperation> move_operation_; - // WeakPtrFactory bound to the UI thread. // Note: This should remain the last member so it'll be destroyed and // invalidate the weak pointers before any other members are destroyed. base::WeakPtrFactory<CopyOperation> weak_ptr_factory_; - DISALLOW_COPY_AND_ASSIGN(CopyOperation); }; diff --git a/chrome/browser/chromeos/drive/file_system/create_directory_operation.cc b/chrome/browser/chromeos/drive/file_system/create_directory_operation.cc index f84fb49..0e4b470 100644 --- a/chrome/browser/chromeos/drive/file_system/create_directory_operation.cc +++ b/chrome/browser/chromeos/drive/file_system/create_directory_operation.cc @@ -74,12 +74,12 @@ struct CreateDirectoryOperation::FindFirstMissingParentDirectoryParams { }; CreateDirectoryOperation::CreateDirectoryOperation( - JobScheduler* job_scheduler, - internal::ResourceMetadata* metadata, - OperationObserver* observer) - : job_scheduler_(job_scheduler), + OperationObserver* observer, + JobScheduler* scheduler, + internal::ResourceMetadata* metadata) + : observer_(observer), + scheduler_(scheduler), metadata_(metadata), - observer_(observer), weak_ptr_factory_(this) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } @@ -142,7 +142,7 @@ void CreateDirectoryOperation::CreateDirectoryAfterFindFirstMissingPath( return; } - job_scheduler_->AddNewDirectory( + scheduler_->AddNewDirectory( result.last_dir_resource_id, result.first_missing_parent_path.BaseName().AsUTF8Unsafe(), base::Bind(&CreateDirectoryOperation::AddNewDirectory, diff --git a/chrome/browser/chromeos/drive/file_system/create_directory_operation.h b/chrome/browser/chromeos/drive/file_system/create_directory_operation.h index 42bfaa9..f12886a 100644 --- a/chrome/browser/chromeos/drive/file_system/create_directory_operation.h +++ b/chrome/browser/chromeos/drive/file_system/create_directory_operation.h @@ -12,12 +12,9 @@ #include "base/memory/weak_ptr.h" #include "chrome/browser/chromeos/drive/file_errors.h" #include "chrome/browser/google_apis/gdata_errorcode.h" -#include "googleurl/src/gurl.h" namespace google_apis { - class ResourceEntry; - } // namespace google_apis namespace drive { @@ -38,9 +35,9 @@ class OperationObserver; // local state and metadata to reflect the new state. class CreateDirectoryOperation { public: - CreateDirectoryOperation(JobScheduler* job_scheduler, - internal::ResourceMetadata* metadata, - OperationObserver* observer); + CreateDirectoryOperation(OperationObserver* observer, + JobScheduler* scheduler, + internal::ResourceMetadata* metadata); ~CreateDirectoryOperation(); // Creates a new directory at |directory_path|. @@ -144,15 +141,13 @@ class CreateDirectoryOperation { FileError error, scoped_ptr<ResourceEntry> entry); - JobScheduler* job_scheduler_; - internal::ResourceMetadata* metadata_; OperationObserver* observer_; + JobScheduler* scheduler_; + internal::ResourceMetadata* metadata_; - // WeakPtrFactory bound to the UI thread. // Note: This should remain the last member so it'll be destroyed and // invalidate the weak pointers before any other members are destroyed. base::WeakPtrFactory<CreateDirectoryOperation> weak_ptr_factory_; - DISALLOW_COPY_AND_ASSIGN(CreateDirectoryOperation); }; diff --git a/chrome/browser/chromeos/drive/file_system/create_directory_operation_unittest.cc b/chrome/browser/chromeos/drive/file_system/create_directory_operation_unittest.cc index 0226975..5a5bcc0 100644 --- a/chrome/browser/chromeos/drive/file_system/create_directory_operation_unittest.cc +++ b/chrome/browser/chromeos/drive/file_system/create_directory_operation_unittest.cc @@ -70,7 +70,7 @@ class CreateDirectoryOperationTest ASSERT_EQ(FILE_ERROR_OK, error); operation_.reset( - new CreateDirectoryOperation(scheduler_.get(), metadata_.get(), this)); + new CreateDirectoryOperation(this, scheduler_.get(), metadata_.get())); } virtual void TearDown() OVERRIDE { diff --git a/chrome/browser/chromeos/drive/file_system/create_file_operation.cc b/chrome/browser/chromeos/drive/file_system/create_file_operation.cc index bdf53f4..532b0a9 100644 --- a/chrome/browser/chromeos/drive/file_system/create_file_operation.cc +++ b/chrome/browser/chromeos/drive/file_system/create_file_operation.cc @@ -34,16 +34,16 @@ void IgnoreError(const FileOperationCallback& callback, FileError error) { } // namespace CreateFileOperation::CreateFileOperation( - JobScheduler* job_scheduler, - internal::FileCache* cache, + base::SequencedTaskRunner* blocking_task_runner, + OperationObserver* observer, + JobScheduler* scheduler, internal::ResourceMetadata* metadata, - scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, - OperationObserver* observer) - : job_scheduler_(job_scheduler), - cache_(cache), - metadata_(metadata), - blocking_task_runner_(blocking_task_runner), + internal::FileCache* cache) + : blocking_task_runner_(blocking_task_runner), observer_(observer), + scheduler_(scheduler), + metadata_(metadata), + cache_(cache), weak_ptr_factory_(this) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } @@ -129,7 +129,7 @@ void CreateFileOperation::CreateFileAfterGetMimeType( bool got_content_type) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - job_scheduler_->CreateFile( + scheduler_->CreateFile( parent_resource_id, file_path, file_path.BaseName().value(), diff --git a/chrome/browser/chromeos/drive/file_system/create_file_operation.h b/chrome/browser/chromeos/drive/file_system/create_file_operation.h index a95f147..660d265 100644 --- a/chrome/browser/chromeos/drive/file_system/create_file_operation.h +++ b/chrome/browser/chromeos/drive/file_system/create_file_operation.h @@ -6,25 +6,29 @@ #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_ #include "base/basictypes.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "chrome/browser/chromeos/drive/resource_metadata.h" +#include "base/sequenced_task_runner.h" +#include "chrome/browser/chromeos/drive/file_errors.h" #include "chrome/browser/google_apis/gdata_errorcode.h" namespace base { class FilePath; -} +} // namespace base namespace google_apis { class ResourceEntry; -} +} // namespace google_apis namespace drive { namespace internal { class FileCache; +class ResourceMetadata; } // namespace internal +struct EntryInfoPairResult; class JobScheduler; class ResourceEntry; @@ -37,12 +41,11 @@ class OperationObserver; // metadata to reflect the new state. class CreateFileOperation { public: - CreateFileOperation( - JobScheduler* job_scheduler, - internal::FileCache* cache, - internal::ResourceMetadata* metadata, - scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, - OperationObserver* observer); + CreateFileOperation(base::SequencedTaskRunner* blocking_task_runner, + OperationObserver* observer, + JobScheduler* scheduler, + internal::ResourceMetadata* metadata, + internal::FileCache* cache); ~CreateFileOperation(); // Creates an empty file at |file_path| in the remote server. When the file @@ -77,11 +80,11 @@ class CreateFileOperation { FileError error, const base::FilePath& drive_path); - JobScheduler* job_scheduler_; - internal::FileCache* cache_; - internal::ResourceMetadata* metadata_; scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; OperationObserver* observer_; + JobScheduler* scheduler_; + internal::ResourceMetadata* metadata_; + internal::FileCache* cache_; // Note: This should remain the last member so it'll be destroyed and // invalidate the weak pointers before any other members are destroyed. diff --git a/chrome/browser/chromeos/drive/file_system/drive_operations.cc b/chrome/browser/chromeos/drive/file_system/drive_operations.cc index 01ec103..ea3b576 100644 --- a/chrome/browser/chromeos/drive/file_system/drive_operations.cc +++ b/chrome/browser/chromeos/drive/file_system/drive_operations.cc @@ -27,57 +27,35 @@ DriveOperations::~DriveOperations() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } -void DriveOperations::Init( - JobScheduler* job_scheduler, - FileSystemInterface* file_system, - internal::FileCache* cache, - internal::ResourceMetadata* metadata, - scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, - OperationObserver* observer) { +void DriveOperations::Init(OperationObserver* observer, + JobScheduler* scheduler, + internal::ResourceMetadata* metadata, + internal::FileCache* cache, + FileSystemInterface* file_system, + base::SequencedTaskRunner* blocking_task_runner) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - copy_operation_.reset(new file_system::CopyOperation(job_scheduler, - file_system, + copy_operation_.reset(new file_system::CopyOperation(blocking_task_runner, + observer, + scheduler, metadata, cache, - blocking_task_runner, - observer)); + file_system)); create_directory_operation_.reset( - new CreateDirectoryOperation(job_scheduler, - metadata, - observer)); - create_file_operation_.reset(new CreateFileOperation(job_scheduler, - cache, + new CreateDirectoryOperation(observer, scheduler, metadata)); + create_file_operation_.reset(new CreateFileOperation(blocking_task_runner, + observer, + scheduler, metadata, - blocking_task_runner, - observer)); - move_operation_.reset(new MoveOperation(job_scheduler, - metadata, - observer)); - remove_operation_.reset(new RemoveOperation(job_scheduler, - cache, - metadata, - observer)); - update_operation_.reset(new UpdateOperation(cache, - metadata, - job_scheduler, - blocking_task_runner, - observer)); - search_operation_.reset(new SearchOperation(blocking_task_runner, - job_scheduler, - metadata)); -} - -void DriveOperations::InitForTesting(CopyOperation* copy_operation, - MoveOperation* move_operation, - RemoveOperation* remove_operation, - UpdateOperation* update_operation) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - copy_operation_.reset(copy_operation); - move_operation_.reset(move_operation); - remove_operation_.reset(remove_operation); - update_operation_.reset(update_operation); + cache)); + move_operation_.reset( + new MoveOperation(observer, scheduler, metadata)); + remove_operation_.reset( + new RemoveOperation(observer, scheduler, metadata, cache)); + update_operation_.reset( + new UpdateOperation(observer, scheduler, metadata, cache)); + search_operation_.reset( + new SearchOperation(blocking_task_runner, scheduler, metadata)); } void DriveOperations::Copy(const base::FilePath& src_file_path, @@ -113,11 +91,10 @@ void DriveOperations::TransferFileFromLocalToRemote( callback); } -void DriveOperations::CreateDirectory( - const base::FilePath& directory_path, - bool is_exclusive, - bool is_recursive, - const FileOperationCallback& callback) { +void DriveOperations::CreateDirectory(const base::FilePath& directory_path, + bool is_exclusive, + bool is_recursive, + const FileOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!callback.is_null()); diff --git a/chrome/browser/chromeos/drive/file_system/drive_operations.h b/chrome/browser/chromeos/drive/file_system/drive_operations.h index 453377a..d8c5dca 100644 --- a/chrome/browser/chromeos/drive/file_system/drive_operations.h +++ b/chrome/browser/chromeos/drive/file_system/drive_operations.h @@ -6,21 +6,20 @@ #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DRIVE_OPERATIONS_H_ #include "base/memory/scoped_ptr.h" -#include "base/sequenced_task_runner.h" #include "chrome/browser/chromeos/drive/file_system_interface.h" -#include "chrome/browser/chromeos/drive/resource_metadata.h" namespace base { class FilePath; +class SequencedTaskRunner; } // namespace base namespace drive { -class FileSystemInterface; class JobScheduler; namespace internal { class FileCache; +class ResourceMetadata; } // namespace internal namespace file_system { @@ -31,8 +30,8 @@ class CreateFileOperation; class MoveOperation; class OperationObserver; class RemoveOperation; -class UpdateOperation; class SearchOperation; +class UpdateOperation; // Callback for DriveOperations::Search. // On success, |error| is FILE_ERROR_OK, and remaining arguments are valid to @@ -56,18 +55,12 @@ class DriveOperations { ~DriveOperations(); // Allocates the operation objects and initializes the operation pointers. - void Init(JobScheduler* job_scheduler, - FileSystemInterface* file_system, - internal::FileCache* cache, + void Init(OperationObserver* observer, + JobScheduler* scheduler, internal::ResourceMetadata* metadata, - scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, - OperationObserver* observer); - - // Initializes the operation pointers. For testing only. - void InitForTesting(CopyOperation* copy_operation, - MoveOperation* move_operation, - RemoveOperation* remove_operation, - UpdateOperation* update_operation); + internal::FileCache* cache, + FileSystemInterface* file_system, + base::SequencedTaskRunner* blocking_task_runner); // Wrapper function for create_directory_operation_. // |callback| must not be null. diff --git a/chrome/browser/chromeos/drive/file_system/move_operation.cc b/chrome/browser/chromeos/drive/file_system/move_operation.cc index 3053bef..c7e490a 100644 --- a/chrome/browser/chromeos/drive/file_system/move_operation.cc +++ b/chrome/browser/chromeos/drive/file_system/move_operation.cc @@ -5,7 +5,6 @@ #include "chrome/browser/chromeos/drive/file_system/move_operation.h" #include "chrome/browser/chromeos/drive/drive.pb.h" -#include "chrome/browser/chromeos/drive/file_cache.h" #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" #include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/job_scheduler.h" @@ -16,12 +15,12 @@ using content::BrowserThread; namespace drive { namespace file_system { -MoveOperation::MoveOperation(JobScheduler* job_scheduler, - internal::ResourceMetadata* metadata, - OperationObserver* observer) - : job_scheduler_(job_scheduler), +MoveOperation::MoveOperation(OperationObserver* observer, + JobScheduler* scheduler, + internal::ResourceMetadata* metadata) + : observer_(observer), + scheduler_(scheduler), metadata_(metadata), - observer_(observer), weak_ptr_factory_(this) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } @@ -153,13 +152,13 @@ void MoveOperation::Rename(const std::string& src_id, new_name_has_hosted_extension ? new_name.RemoveExtension() : new_name); // Rename on the server. - job_scheduler_->RenameResource(src_id, - new_name_arg.AsUTF8Unsafe(), - base::Bind(&MoveOperation::RenameLocally, - weak_ptr_factory_.GetWeakPtr(), - src_path, - new_name_arg, - callback)); + scheduler_->RenameResource(src_id, + new_name_arg.AsUTF8Unsafe(), + base::Bind(&MoveOperation::RenameLocally, + weak_ptr_factory_.GetWeakPtr(), + src_path, + new_name_arg, + callback)); } void MoveOperation::RenameLocally(const base::FilePath& src_path, @@ -184,7 +183,7 @@ void MoveOperation::AddToDirectory(const std::string& src_id, const FileMoveCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - job_scheduler_->AddResourceToDirectory( + scheduler_->AddResourceToDirectory( dest_dir_id, src_id, base::Bind(&MoveOperation::AddToDirectoryLocally, weak_ptr_factory_.GetWeakPtr(), @@ -213,7 +212,7 @@ void MoveOperation::RemoveFromDirectory( const FileOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - job_scheduler_->RemoveResourceFromDirectory( + scheduler_->RemoveResourceFromDirectory( directory_resource_id, resource_id, base::Bind(&MoveOperation::RemoveFromDirectoryCompleted, diff --git a/chrome/browser/chromeos/drive/file_system/move_operation.h b/chrome/browser/chromeos/drive/file_system/move_operation.h index 61fac1a..ec18427 100644 --- a/chrome/browser/chromeos/drive/file_system/move_operation.h +++ b/chrome/browser/chromeos/drive/file_system/move_operation.h @@ -11,21 +11,15 @@ #include "chrome/browser/chromeos/drive/resource_metadata.h" #include "chrome/browser/google_apis/gdata_errorcode.h" -class GURL; - namespace base { class FilePath; -} +} // namespace base; namespace drive { class JobScheduler; class ResourceEntry; -namespace internal { -class ResourceMetadata; -} // namespace internal - namespace file_system { class OperationObserver; @@ -35,17 +29,17 @@ class OperationObserver; // metadata to reflect the new state. class MoveOperation { public: - MoveOperation(JobScheduler* job_scheduler, - internal::ResourceMetadata* metadata, - OperationObserver* observer); - virtual ~MoveOperation(); + MoveOperation(OperationObserver* observer, + JobScheduler* scheduler, + internal::ResourceMetadata* metadata); + ~MoveOperation(); // Performs the move operation on the file at drive path |src_file_path| // with a target of |dest_file_path|. Invokes |callback| when finished with // the result of the operation. |callback| must not be null. - virtual void Move(const base::FilePath& src_file_path, - const base::FilePath& dest_file_path, - const FileOperationCallback& callback); + void Move(const base::FilePath& src_file_path, + const base::FilePath& dest_file_path, + const FileOperationCallback& callback); private: // Step 1 of Move(), called after the resource entry of the source and the // destination directory is obtained. It renames the resource in the source @@ -121,11 +115,10 @@ class MoveOperation { void RemoveFromDirectoryCompleted(const FileOperationCallback& callback, google_apis::GDataErrorCode status); - JobScheduler* job_scheduler_; - internal::ResourceMetadata* metadata_; OperationObserver* observer_; + JobScheduler* scheduler_; + internal::ResourceMetadata* metadata_; - // WeakPtrFactory bound to the UI thread. // Note: This should remain the last member so it'll be destroyed and // invalidate the weak pointers before any other members are destroyed. base::WeakPtrFactory<MoveOperation> weak_ptr_factory_; diff --git a/chrome/browser/chromeos/drive/file_system/remove_operation.cc b/chrome/browser/chromeos/drive/file_system/remove_operation.cc index 819df87..27904df 100644 --- a/chrome/browser/chromeos/drive/file_system/remove_operation.cc +++ b/chrome/browser/chromeos/drive/file_system/remove_operation.cc @@ -16,21 +16,14 @@ using content::BrowserThread; namespace drive { namespace file_system { -namespace { - -void EmptyFileOperationCallback(FileError error) {} - -} // namespace - -RemoveOperation::RemoveOperation( - JobScheduler* job_scheduler, - internal::FileCache* cache, - internal::ResourceMetadata* metadata, - OperationObserver* observer) - : job_scheduler_(job_scheduler), - cache_(cache), +RemoveOperation::RemoveOperation(OperationObserver* observer, + JobScheduler* scheduler, + internal::ResourceMetadata* metadata, + internal::FileCache* cache) + : observer_(observer), + scheduler_(scheduler), metadata_(metadata), - observer_(observer), + cache_(cache), weak_ptr_factory_(this) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } @@ -39,10 +32,9 @@ RemoveOperation::~RemoveOperation() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } -void RemoveOperation::Remove( - const base::FilePath& file_path, - bool is_recursive, - const FileOperationCallback& callback) { +void RemoveOperation::Remove(const base::FilePath& file_path, + bool is_recursive, + const FileOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!callback.is_null()); @@ -66,9 +58,9 @@ void RemoveOperation::RemoveAfterGetResourceEntry( callback.Run(error); return; } - DCHECK(entry.get()); + DCHECK(entry); - job_scheduler_->DeleteResource( + scheduler_->DeleteResource( entry->resource_id(), base::Bind(&RemoveOperation::RemoveResourceLocally, weak_ptr_factory_.GetWeakPtr(), @@ -96,7 +88,7 @@ void RemoveOperation::RemoveResourceLocally( callback)); cache_->RemoveOnUIThread(resource_id, - base::Bind(&EmptyFileOperationCallback)); + base::Bind(&util::EmptyFileOperationCallback)); } void RemoveOperation::NotifyDirectoryChanged( diff --git a/chrome/browser/chromeos/drive/file_system/remove_operation.h b/chrome/browser/chromeos/drive/file_system/remove_operation.h index a13686a..d8c29ee 100644 --- a/chrome/browser/chromeos/drive/file_system/remove_operation.h +++ b/chrome/browser/chromeos/drive/file_system/remove_operation.h @@ -11,15 +11,12 @@ #include "chrome/browser/chromeos/drive/file_errors.h" #include "chrome/browser/google_apis/gdata_errorcode.h" -class GURL; - namespace base { class FilePath; } // namespace base namespace drive { -class FileSystem; class JobScheduler; class ResourceEntry; @@ -37,52 +34,45 @@ class OperationObserver; // metadata to reflect the new state. class RemoveOperation { public: - RemoveOperation(JobScheduler* job_scheduler, - internal::FileCache* cache, + RemoveOperation(OperationObserver* observer, + JobScheduler* scheduler, internal::ResourceMetadata* metadata, - OperationObserver* observer); - virtual ~RemoveOperation(); + internal::FileCache* cache); + ~RemoveOperation(); // Perform the remove operation on the file at drive path |file_path|. // Invokes |callback| when finished with the result of the operation. // |callback| must not be null. - virtual void Remove(const base::FilePath& file_path, - bool is_recursive, - const FileOperationCallback& callback); + void Remove(const base::FilePath& file_path, + bool is_recursive, + const FileOperationCallback& callback); private: // Part of Remove(). Called after GetResourceEntryByPath() is complete. - // |callback| must not be null. - void RemoveAfterGetResourceEntry( - const FileOperationCallback& callback, - FileError error, - scoped_ptr<ResourceEntry> entry); + void RemoveAfterGetResourceEntry(const FileOperationCallback& callback, + FileError error, + scoped_ptr<ResourceEntry> entry); // Callback for DriveServiceInterface::DeleteResource. Removes the entry with // |resource_id| from the local snapshot of the filesystem and the cache. - // |callback| must not be null. - void RemoveResourceLocally( - const FileOperationCallback& callback, - const std::string& resource_id, - google_apis::GDataErrorCode status); + void RemoveResourceLocally(const FileOperationCallback& callback, + const std::string& resource_id, + google_apis::GDataErrorCode status); // Sends notification for directory changes. Notifies of directory changes, - // and runs |callback| with |error|. |callback| must not be null. - void NotifyDirectoryChanged( - const FileOperationCallback& callback, - FileError error, - const base::FilePath& directory_path); + // and runs |callback| with |error|. + void NotifyDirectoryChanged(const FileOperationCallback& callback, + FileError error, + const base::FilePath& directory_path); - JobScheduler* job_scheduler_; - internal::FileCache* cache_; - internal::ResourceMetadata* metadata_; OperationObserver* observer_; + JobScheduler* scheduler_; + internal::ResourceMetadata* metadata_; + internal::FileCache* cache_; - // WeakPtrFactory bound to the UI thread. // Note: This should remain the last member so it'll be destroyed and // invalidate the weak pointers before any other members are destroyed. base::WeakPtrFactory<RemoveOperation> weak_ptr_factory_; - DISALLOW_COPY_AND_ASSIGN(RemoveOperation); }; diff --git a/chrome/browser/chromeos/drive/file_system/search_operation.cc b/chrome/browser/chromeos/drive/file_system/search_operation.cc index ae41a1f..a7084a2 100644 --- a/chrome/browser/chromeos/drive/file_system/search_operation.cc +++ b/chrome/browser/chromeos/drive/file_system/search_operation.cc @@ -10,7 +10,6 @@ #include "base/bind.h" #include "base/bind_helpers.h" #include "base/callback.h" -#include "base/sequenced_task_runner.h" #include "base/task_runner_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/job_scheduler.h" @@ -71,10 +70,10 @@ FileError RefreshEntriesOnBlockingPool( SearchOperation::SearchOperation( base::SequencedTaskRunner* blocking_task_runner, JobScheduler* scheduler, - internal::ResourceMetadata* resource_metadata) + internal::ResourceMetadata* metadata) : blocking_task_runner_(blocking_task_runner), scheduler_(scheduler), - resource_metadata_(resource_metadata), + metadata_(metadata), weak_ptr_factory_(this) { } @@ -139,7 +138,7 @@ void SearchOperation::SearchAfterGetResourceList( blocking_task_runner_, FROM_HERE, base::Bind(&RefreshEntriesOnBlockingPool, - resource_metadata_, + metadata_, base::Passed(&resource_list), is_update_needed, result_ptr), diff --git a/chrome/browser/chromeos/drive/file_system/search_operation.h b/chrome/browser/chromeos/drive/file_system/search_operation.h index 36a7594..fe82543 100644 --- a/chrome/browser/chromeos/drive/file_system/search_operation.h +++ b/chrome/browser/chromeos/drive/file_system/search_operation.h @@ -6,21 +6,16 @@ #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_SEARCH_OPERATION_H_ #include "base/basictypes.h" -#include "base/callback_forward.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "base/sequenced_task_runner.h" #include "chrome/browser/chromeos/drive/file_errors.h" #include "chrome/browser/chromeos/drive/file_system/drive_operations.h" -#include "chrome/browser/chromeos/drive/file_system_interface.h" #include "chrome/browser/google_apis/gdata_errorcode.h" class GURL; -namespace base { -class SequencedTaskRunner; -} // namespace base - namespace google_apis { class ResourceEntry; } // namespace google_apis @@ -39,9 +34,9 @@ namespace file_system { // sending the request to the drive API. class SearchOperation { public: - SearchOperation(base::SequencedTaskRunner* blocking_task_runner_, - JobScheduler* job_scheduler, - internal::ResourceMetadata* resource_metadata); + SearchOperation(base::SequencedTaskRunner* blocking_task_runner, + JobScheduler* scheduler, + internal::ResourceMetadata* metadata); ~SearchOperation(); // Performs server side content search operation for |search_query|. @@ -72,8 +67,8 @@ class SearchOperation { FileError error); scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; - JobScheduler* scheduler_; // Not owned. - internal::ResourceMetadata* resource_metadata_; // Not owned. + JobScheduler* scheduler_; + internal::ResourceMetadata* metadata_; // Note: This should remain the last member so it'll be destroyed and // invalidate the weak pointers before any other members are destroyed. diff --git a/chrome/browser/chromeos/drive/file_system/update_operation.cc b/chrome/browser/chromeos/drive/file_system/update_operation.cc index 787c59d..ebd02e1 100644 --- a/chrome/browser/chromeos/drive/file_system/update_operation.cc +++ b/chrome/browser/chromeos/drive/file_system/update_operation.cc @@ -10,6 +10,7 @@ #include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/job_scheduler.h" #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" +#include "chrome/browser/chromeos/drive/resource_metadata.h" #include "content/public/browser/browser_thread.h" using content::BrowserThread; @@ -17,17 +18,14 @@ using content::BrowserThread; namespace drive { namespace file_system { -UpdateOperation::UpdateOperation( - internal::FileCache* cache, - internal::ResourceMetadata* metadata, - JobScheduler* scheduler, - scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, - OperationObserver* observer) - : cache_(cache), - metadata_(metadata), +UpdateOperation::UpdateOperation(OperationObserver* observer, + JobScheduler* scheduler, + internal::ResourceMetadata* metadata, + internal::FileCache* cache) + : observer_(observer), scheduler_(scheduler), - blocking_task_runner_(blocking_task_runner), - observer_(observer), + metadata_(metadata), + cache_(cache), weak_ptr_factory_(this) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } @@ -43,17 +41,15 @@ void UpdateOperation::UpdateFileByResourceId( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!callback.is_null()); - // TODO(satorux): GetResourceEntryById() is called twice for - // UpdateFileByResourceId(). crbug.com/143873 metadata_->GetResourceEntryByIdOnUIThread( resource_id, - base::Bind(&UpdateOperation::UpdateFileByEntryInfo, + base::Bind(&UpdateOperation::UpdateFileAfterGetEntryInfo, weak_ptr_factory_.GetWeakPtr(), context, callback)); } -void UpdateOperation::UpdateFileByEntryInfo( +void UpdateOperation::UpdateFileAfterGetEntryInfo( DriveClientContext context, const FileOperationCallback& callback, FileError error, @@ -67,9 +63,9 @@ void UpdateOperation::UpdateFileByEntryInfo( return; } - DCHECK(entry.get()); + DCHECK(entry); if (entry->file_info().is_directory()) { - callback.Run(FILE_ERROR_NOT_FOUND); + callback.Run(FILE_ERROR_NOT_A_FILE); return; } @@ -78,7 +74,7 @@ void UpdateOperation::UpdateFileByEntryInfo( cache_->GetFileOnUIThread( entry_ptr->resource_id(), entry_ptr->file_specific_info().file_md5(), - base::Bind(&UpdateOperation::OnGetFileCompleteForUpdateFile, + base::Bind(&UpdateOperation::UpdateFileAfterGetFile, weak_ptr_factory_.GetWeakPtr(), context, callback, @@ -86,7 +82,7 @@ void UpdateOperation::UpdateFileByEntryInfo( base::Passed(&entry))); } -void UpdateOperation::OnGetFileCompleteForUpdateFile( +void UpdateOperation::UpdateFileAfterGetFile( DriveClientContext context, const FileOperationCallback& callback, const base::FilePath& drive_file_path, @@ -108,12 +104,12 @@ void UpdateOperation::OnGetFileCompleteForUpdateFile( entry->file_specific_info().content_mime_type(), "", // etag context, - base::Bind(&UpdateOperation::OnUpdatedFileUploaded, + base::Bind(&UpdateOperation::UpdateFileAfterUpload, weak_ptr_factory_.GetWeakPtr(), callback)); } -void UpdateOperation::OnUpdatedFileUploaded( +void UpdateOperation::UpdateFileAfterUpload( const FileOperationCallback& callback, google_apis::GDataErrorCode error, scoped_ptr<google_apis::ResourceEntry> resource_entry) { @@ -128,11 +124,11 @@ void UpdateOperation::OnUpdatedFileUploaded( metadata_->RefreshEntryOnUIThread( ConvertToResourceEntry(*resource_entry), - base::Bind(&UpdateOperation::OnUpdatedFileRefreshed, + base::Bind(&UpdateOperation::UpdateFileAfterRefresh, weak_ptr_factory_.GetWeakPtr(), callback)); } -void UpdateOperation::OnUpdatedFileRefreshed( +void UpdateOperation::UpdateFileAfterRefresh( const FileOperationCallback& callback, FileError error, const base::FilePath& drive_file_path, @@ -145,7 +141,7 @@ void UpdateOperation::OnUpdatedFileRefreshed( return; } - DCHECK(entry.get()); + DCHECK(entry); DCHECK(entry->has_resource_id()); DCHECK(entry->has_file_specific_info()); DCHECK(entry->file_specific_info().has_file_md5()); diff --git a/chrome/browser/chromeos/drive/file_system/update_operation.h b/chrome/browser/chromeos/drive/file_system/update_operation.h index d144d92..9e2e940 100644 --- a/chrome/browser/chromeos/drive/file_system/update_operation.h +++ b/chrome/browser/chromeos/drive/file_system/update_operation.h @@ -9,11 +9,8 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "chrome/browser/chromeos/drive/file_system_interface.h" -#include "chrome/browser/chromeos/drive/resource_metadata.h" #include "chrome/browser/google_apis/gdata_errorcode.h" -class GURL; - namespace base { class FilePath; } // namespace base @@ -25,6 +22,7 @@ class ResourceEntry; namespace internal { class FileCache; +class ResourceMetadata; } // namespace internal namespace file_system { @@ -36,76 +34,53 @@ class OperationObserver; // metadata to reflect the new state. class UpdateOperation { public: - UpdateOperation(internal::FileCache* cache, - internal::ResourceMetadata* metadata, + UpdateOperation(OperationObserver* observer, JobScheduler* scheduler, - scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, - OperationObserver* observer); - virtual ~UpdateOperation(); + internal::ResourceMetadata* metadata, + internal::FileCache* cache); + ~UpdateOperation(); // Updates a file by the given |resource_id| on the Drive server by // uploading an updated version. Used for uploading dirty files. The file // should already be present in the cache. // - // TODO(satorux): As of now, the function only handles files with the dirty - // bit committed. We should eliminate the restriction. crbug.com/134558. - // - // Can only be called from UI thread. |callback| must not be null. - virtual void UpdateFileByResourceId( - const std::string& resource_id, - DriveClientContext context, - const FileOperationCallback& callback); + // |callback| must not be null. + void UpdateFileByResourceId(const std::string& resource_id, + DriveClientContext context, + const FileOperationCallback& callback); private: - // Part of UpdateFileByResourceId(). Called when - // ResourceMetadata::GetResourceEntryById() is complete. - // |callback| must not be null. - void UpdateFileByEntryInfo( - DriveClientContext context, - const FileOperationCallback& callback, - FileError error, - const base::FilePath& drive_file_path, - scoped_ptr<ResourceEntry> entry); + void UpdateFileAfterGetEntryInfo(DriveClientContext context, + const FileOperationCallback& callback, + FileError error, + const base::FilePath& drive_file_path, + scoped_ptr<ResourceEntry> entry); + + void UpdateFileAfterGetFile(DriveClientContext context, + const FileOperationCallback& callback, + const base::FilePath& drive_file_path, + scoped_ptr<ResourceEntry> entry, + FileError error, + const base::FilePath& cache_file_path); - // Part of UpdateFileByResourceId(). - // Called when FileCache::GetFileOnUIThread() is completed for - // UpdateFileByResourceId(). - // |callback| must not be null. - void OnGetFileCompleteForUpdateFile( - DriveClientContext context, - const FileOperationCallback& callback, - const base::FilePath& drive_file_path, - scoped_ptr<ResourceEntry> entry, - FileError error, - const base::FilePath& cache_file_path); - - // Part of UpdateFileByResourceId(). - // Called when DriveUploader::UploadUpdatedFile() is completed for - // UpdateFileByResourceId(). - // |callback| must not be null. - void OnUpdatedFileUploaded( + void UpdateFileAfterUpload( const FileOperationCallback& callback, google_apis::GDataErrorCode error, scoped_ptr<google_apis::ResourceEntry> resource_entry); - // Part of UpdateFileByResourceId(). - // |callback| must not be null. - void OnUpdatedFileRefreshed(const FileOperationCallback& callback, + void UpdateFileAfterRefresh(const FileOperationCallback& callback, FileError error, const base::FilePath& drive_file_path, scoped_ptr<ResourceEntry> entry); - internal::FileCache* cache_; - internal::ResourceMetadata* metadata_; - JobScheduler* scheduler_; - scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; OperationObserver* observer_; + JobScheduler* scheduler_; + internal::ResourceMetadata* metadata_; + internal::FileCache* cache_; - // WeakPtrFactory bound to the UI thread. // Note: This should remain the last member so it'll be destroyed and // invalidate the weak pointers before any other members are destroyed. base::WeakPtrFactory<UpdateOperation> weak_ptr_factory_; - DISALLOW_COPY_AND_ASSIGN(UpdateOperation); }; diff --git a/chrome/browser/chromeos/drive/file_system_util.h b/chrome/browser/chromeos/drive/file_system_util.h index b45820b..9dc727e 100644 --- a/chrome/browser/chromeos/drive/file_system_util.h +++ b/chrome/browser/chromeos/drive/file_system_util.h @@ -167,7 +167,7 @@ void ParseCacheFilePath(const base::FilePath& path, std::string* md5, std::string* extra_extension); -// Callback type for PrepareWritablebase::FilePathAndRun. +// Callback type for PrepareWritableFileAndRun. typedef base::Callback<void (FileError, const base::FilePath& path)> OpenFileCallback; |