summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/drive/file_system/drive_operations.h
blob: 453377a8c52e6367521028e750b8236a4a05eba9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DRIVE_OPERATIONS_H_
#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;
}  // namespace base

namespace drive {

class FileSystemInterface;
class JobScheduler;

namespace internal {
class FileCache;
}  // namespace internal

namespace file_system {

class CopyOperation;
class CreateDirectoryOperation;
class CreateFileOperation;
class MoveOperation;
class OperationObserver;
class RemoveOperation;
class UpdateOperation;
class SearchOperation;

// Callback for DriveOperations::Search.
// On success, |error| is FILE_ERROR_OK, and remaining arguments are valid to
// use. if |is_update_needed| is true, some mismatch is found between
// the result from the server and local metadata, so the caller should update
// the resource metadata.
// |next_feed| is the URL to fetch the remaining result from the server. Maybe
// empty if there is no more results.
// On error, |error| is set to other than FILE_ERROR_OK, and the caller
// shouldn't use remaining arguments.
typedef base::Callback<void(FileError error,
                            bool is_update_needed,
                            const GURL& next_feed,
                            scoped_ptr<std::vector<SearchResultInfo> > result)>
    SearchOperationCallback;

// Passes notifications from Drive operations back to the file system.
class DriveOperations {
 public:
  DriveOperations();
  ~DriveOperations();

  // Allocates the operation objects and initializes the operation pointers.
  void Init(JobScheduler* job_scheduler,
            FileSystemInterface* file_system,
            internal::FileCache* cache,
            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);

  // Wrapper function for create_directory_operation_.
  // |callback| must not be null.
  void CreateDirectory(const base::FilePath& directory_path,
                       bool is_exclusive,
                       bool is_recursive,
                       const FileOperationCallback& callback);

  // Wrapper function for create_file_operation_.
  // |callback| must not be null.
  void CreateFile(const base::FilePath& remote_file_path,
                  bool is_exclusive,
                  const FileOperationCallback& callback);

  // Wrapper function for copy_operation_.
  // |callback| must not be null.
  void Copy(const base::FilePath& src_file_path,
            const base::FilePath& dest_file_path,
            const FileOperationCallback& callback);

  // Wrapper function for copy_operation_.
  // |callback| must not be null.
  void TransferFileFromRemoteToLocal(const base::FilePath& remote_src_file_path,
                                     const base::FilePath& local_dest_file_path,
                                     const FileOperationCallback& callback);

  // Wrapper function for copy_operation_.
  // |callback| must not be null.
  void TransferFileFromLocalToRemote(
      const base::FilePath& local_src_file_path,
      const base::FilePath& remote_dest_file_path,
      const FileOperationCallback& callback);

  // Wrapper function for move_operation_.
  // |callback| must not be null.
  void Move(const base::FilePath& src_file_path,
            const base::FilePath& dest_file_path,
            const FileOperationCallback& callback);

  // Wrapper function for remove_operation_.
  // |callback| must not be null.
  void Remove(const base::FilePath& file_path,
              bool is_recursive,
              const FileOperationCallback& callback);

  // Wrapper function for update_operation_.
  // |callback| must not be null.
  void UpdateFileByResourceId(const std::string& resource_id,
                              DriveClientContext context,
                              const FileOperationCallback& callback);

  // Wrapper function for search_operation_.
  // |callback| must not be null.
  void Search(const std::string& search_query,
              const GURL& next_feed,
              const SearchOperationCallback& callback);

 private:
  scoped_ptr<CopyOperation> copy_operation_;
  scoped_ptr<CreateDirectoryOperation> create_directory_operation_;
  scoped_ptr<CreateFileOperation> create_file_operation_;
  scoped_ptr<MoveOperation> move_operation_;
  scoped_ptr<RemoveOperation> remove_operation_;
  scoped_ptr<UpdateOperation> update_operation_;
  scoped_ptr<SearchOperation> search_operation_;
};

}  // namespace file_system
}  // namespace drive

#endif  // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_DRIVE_OPERATIONS_H_