move_operation.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_ 6#define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_ 7 8#include <set> 9 10#include "base/basictypes.h" 11#include "base/memory/ref_counted.h" 12#include "base/memory/scoped_ptr.h" 13#include "base/memory/weak_ptr.h" 14#include "chrome/browser/chromeos/drive/file_errors.h" 15#include "google_apis/drive/gdata_errorcode.h" 16 17namespace base { 18class FilePath; 19class SequencedTaskRunner; 20} // namespace base 21 22namespace google_apis { 23class ResourceEntry; 24} // namespace google_apis 25 26namespace drive { 27 28class ResourceEntry; 29 30namespace internal { 31class ResourceMetadata; 32} // namespace internal 33 34namespace file_system { 35 36class OperationObserver; 37 38// This class encapsulates the drive Move function. It is responsible for 39// updating the local metadata entry. 40class MoveOperation { 41 public: 42 MoveOperation(base::SequencedTaskRunner* blocking_task_runner, 43 OperationObserver* observer, 44 internal::ResourceMetadata* metadata); 45 ~MoveOperation(); 46 47 // Performs the move operation on the file at drive path |src_file_path| 48 // with a target of |dest_file_path|. 49 // If |preserve_last_modified| is set to true, this tries to preserve 50 // last modified time stamp. 51 // Invokes |callback| when finished with the result of the operation. 52 // |callback| must not be null. 53 void Move(const base::FilePath& src_file_path, 54 const base::FilePath& dest_file_path, 55 bool preserve_last_modified, 56 const FileOperationCallback& callback); 57 58 private: 59 // Part of Move(). Called after updating the local state. 60 void MoveAfterUpdateLocalState( 61 const FileOperationCallback& callback, 62 const std::set<base::FilePath>* changed_directories, 63 const std::string* local_id, 64 FileError error); 65 66 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 67 OperationObserver* observer_; 68 internal::ResourceMetadata* metadata_; 69 70 // Note: This should remain the last member so it'll be destroyed and 71 // invalidate the weak pointers before any other members are destroyed. 72 base::WeakPtrFactory<MoveOperation> weak_ptr_factory_; 73 DISALLOW_COPY_AND_ASSIGN(MoveOperation); 74}; 75 76} // namespace file_system 77} // namespace drive 78 79#endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_ 80