| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "chrome/browser/chromeos/drive/file_errors.h" | 11 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 class FilePath; | 14 class FilePath; |
| 15 class SequencedTaskRunner; | 15 class SequencedTaskRunner; |
| 16 } // namespace base | 16 } // namespace base |
| 17 | 17 |
| 18 namespace drive { | 18 namespace drive { |
| 19 | 19 |
| 20 namespace internal { | 20 namespace internal { |
| 21 class ResourceMetadata; | 21 class ResourceMetadata; |
| 22 } // namespace internal | 22 } // namespace internal |
| 23 | 23 |
| 24 class ResourceEntry; | 24 class ResourceEntry; |
| 25 | 25 |
| 26 namespace file_system { | 26 namespace file_system { |
| 27 | 27 |
| 28 class OperationObserver; | 28 class OperationDelegate; |
| 29 | 29 |
| 30 // This class encapsulates the drive CreateFile function. It is responsible for | 30 // This class encapsulates the drive CreateFile function. It is responsible for |
| 31 // sending the request to the drive API, then updating the local state and | 31 // sending the request to the drive API, then updating the local state and |
| 32 // metadata to reflect the new state. | 32 // metadata to reflect the new state. |
| 33 class CreateFileOperation { | 33 class CreateFileOperation { |
| 34 public: | 34 public: |
| 35 CreateFileOperation(base::SequencedTaskRunner* blocking_task_runner, | 35 CreateFileOperation(base::SequencedTaskRunner* blocking_task_runner, |
| 36 OperationObserver* observer, | 36 OperationDelegate* delegate, |
| 37 internal::ResourceMetadata* metadata); | 37 internal::ResourceMetadata* metadata); |
| 38 ~CreateFileOperation(); | 38 ~CreateFileOperation(); |
| 39 | 39 |
| 40 // Creates an empty file at |file_path|. When the file | 40 // Creates an empty file at |file_path|. When the file |
| 41 // already exists at that path, the operation fails if |is_exclusive| is true, | 41 // already exists at that path, the operation fails if |is_exclusive| is true, |
| 42 // and it succeeds without doing anything if the flag is false. | 42 // and it succeeds without doing anything if the flag is false. |
| 43 // If |mime_type| is non-empty, it is used as the mime type of the entry. If | 43 // If |mime_type| is non-empty, it is used as the mime type of the entry. If |
| 44 // the parameter is empty, the type is guessed from |file_path|. | 44 // the parameter is empty, the type is guessed from |file_path|. |
| 45 // | 45 // |
| 46 // |callback| must not be null. | 46 // |callback| must not be null. |
| 47 void CreateFile(const base::FilePath& file_path, | 47 void CreateFile(const base::FilePath& file_path, |
| 48 bool is_exclusive, | 48 bool is_exclusive, |
| 49 const std::string& mime_type, | 49 const std::string& mime_type, |
| 50 const FileOperationCallback& callback); | 50 const FileOperationCallback& callback); |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 // Part of CreateFile(). Called after the updating local state is completed. | 53 // Part of CreateFile(). Called after the updating local state is completed. |
| 54 void CreateFileAfterUpdateLocalState(const FileOperationCallback& callback, | 54 void CreateFileAfterUpdateLocalState(const FileOperationCallback& callback, |
| 55 const base::FilePath& file_path, | 55 const base::FilePath& file_path, |
| 56 bool is_exclusive, | 56 bool is_exclusive, |
| 57 ResourceEntry* entry, | 57 ResourceEntry* entry, |
| 58 FileError error); | 58 FileError error); |
| 59 | 59 |
| 60 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 60 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 61 OperationObserver* observer_; | 61 OperationDelegate* delegate_; |
| 62 internal::ResourceMetadata* metadata_; | 62 internal::ResourceMetadata* metadata_; |
| 63 | 63 |
| 64 // Note: This should remain the last member so it'll be destroyed and | 64 // Note: This should remain the last member so it'll be destroyed and |
| 65 // invalidate the weak pointers before any other members are destroyed. | 65 // invalidate the weak pointers before any other members are destroyed. |
| 66 base::WeakPtrFactory<CreateFileOperation> weak_ptr_factory_; | 66 base::WeakPtrFactory<CreateFileOperation> weak_ptr_factory_; |
| 67 DISALLOW_COPY_AND_ASSIGN(CreateFileOperation); | 67 DISALLOW_COPY_AND_ASSIGN(CreateFileOperation); |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 } // namespace file_system | 70 } // namespace file_system |
| 71 } // namespace drive | 71 } // namespace drive |
| 72 | 72 |
| 73 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_ | 73 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_ |
| OLD | NEW |