OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_MOVE_OPERATION_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_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/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "chrome/browser/chromeos/drive/file_errors.h" | 12 #include "chrome/browser/chromeos/drive/file_errors.h" |
13 #include "chrome/browser/google_apis/gdata_errorcode.h" | 13 #include "chrome/browser/google_apis/gdata_errorcode.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class FilePath; | 16 class FilePath; |
17 class SequencedTaskRunner; | 17 class SequencedTaskRunner; |
18 } // namespace base | 18 } // namespace base |
19 | 19 |
20 namespace google_apis { | 20 namespace google_apis { |
21 class ResourceEntry; | 21 class ResourceEntry; |
22 } // namespace google_apis | 22 } // namespace google_apis |
23 | 23 |
24 namespace drive { | 24 namespace drive { |
25 | 25 |
26 class JobScheduler; | |
27 class ResourceEntry; | 26 class ResourceEntry; |
28 | 27 |
29 namespace internal { | 28 namespace internal { |
30 class ResourceMetadata; | 29 class ResourceMetadata; |
31 } // namespace internal | 30 } // namespace internal |
32 | 31 |
33 namespace file_system { | 32 namespace file_system { |
34 | 33 |
35 class OperationObserver; | 34 class OperationObserver; |
36 | 35 |
37 // This class encapsulates the drive Move function. It is responsible for | 36 // This class encapsulates the drive Move function. It is responsible for |
38 // sending the request to the drive API, then updating the local state and | 37 // updating the local metadata entry. |
39 // metadata to reflect the new state. | |
40 class MoveOperation { | 38 class MoveOperation { |
41 public: | 39 public: |
42 MoveOperation(base::SequencedTaskRunner* blocking_task_runner, | 40 MoveOperation(base::SequencedTaskRunner* blocking_task_runner, |
43 OperationObserver* observer, | 41 OperationObserver* observer, |
44 JobScheduler* scheduler, | |
45 internal::ResourceMetadata* metadata); | 42 internal::ResourceMetadata* metadata); |
46 ~MoveOperation(); | 43 ~MoveOperation(); |
47 | 44 |
48 // Performs the move operation on the file at drive path |src_file_path| | 45 // Performs the move operation on the file at drive path |src_file_path| |
49 // with a target of |dest_file_path|. | 46 // with a target of |dest_file_path|. |
50 // If |preserve_last_modified| is set to true, this tries to preserve | 47 // If |preserve_last_modified| is set to true, this tries to preserve |
51 // last modified time stamp. | 48 // last modified time stamp. |
52 // Invokes |callback| when finished with the result of the operation. | 49 // Invokes |callback| when finished with the result of the operation. |
53 // |callback| must not be null. | 50 // |callback| must not be null. |
54 void Move(const base::FilePath& src_file_path, | 51 void Move(const base::FilePath& src_file_path, |
55 const base::FilePath& dest_file_path, | 52 const base::FilePath& dest_file_path, |
56 bool preserve_last_modified, | 53 bool preserve_last_modified, |
57 const FileOperationCallback& callback); | 54 const FileOperationCallback& callback); |
58 | 55 |
59 private: | 56 private: |
60 // Params of Move(). | 57 // Part of Move(). Called after updating the local state. |
61 struct MoveParams; | 58 void MoveAfterUpdateLocalState(const base::FilePath& src_file_path, |
62 | 59 const base::FilePath& dest_file_path, |
63 // Part of Move(). Called after local metadata look up. | 60 const FileOperationCallback& callback, |
64 void MoveAfterPrepare(const MoveParams& params, | 61 const std::string* local_id, |
65 scoped_ptr<ResourceEntry> src_entry, | 62 FileError error); |
66 scoped_ptr<ResourceEntry> src_parent_entry, | |
67 scoped_ptr<ResourceEntry> dest_parent_entry, | |
68 FileError error); | |
69 | |
70 // Part of Move(). Called after UpdateResource is completed. | |
71 void MoveAfterUpdateResource( | |
72 const MoveParams& params, | |
73 google_apis::GDataErrorCode status, | |
74 scoped_ptr<google_apis::ResourceEntry> resource_entry); | |
75 | |
76 // Part of Move(). Called after ResourceMetadata::RefreshEntry is completed. | |
77 void MoveAfterRefreshEntry(const MoveParams& params, FileError error); | |
78 | 63 |
79 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 64 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
80 OperationObserver* observer_; | 65 OperationObserver* observer_; |
81 JobScheduler* scheduler_; | |
82 internal::ResourceMetadata* metadata_; | 66 internal::ResourceMetadata* metadata_; |
83 | 67 |
84 // Note: This should remain the last member so it'll be destroyed and | 68 // Note: This should remain the last member so it'll be destroyed and |
85 // invalidate the weak pointers before any other members are destroyed. | 69 // invalidate the weak pointers before any other members are destroyed. |
86 base::WeakPtrFactory<MoveOperation> weak_ptr_factory_; | 70 base::WeakPtrFactory<MoveOperation> weak_ptr_factory_; |
87 DISALLOW_COPY_AND_ASSIGN(MoveOperation); | 71 DISALLOW_COPY_AND_ASSIGN(MoveOperation); |
88 }; | 72 }; |
89 | 73 |
90 } // namespace file_system | 74 } // namespace file_system |
91 } // namespace drive | 75 } // namespace drive |
92 | 76 |
93 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_ | 77 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_ |
OLD | NEW |