e9e3ce4a9ba31c15beb65354c17ea50e2c9fe821
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / drive / file_system / create_file_operation.h
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/chromeos/drive/file_errors.h"
13 #include "google_apis/drive/gdata_errorcode.h"
14
15 namespace base {
16 class FilePath;
17 class SequencedTaskRunner;
18 }  // namespace base
19
20 namespace google_apis {
21 class ResourceEntry;
22 }  // namespace google_apis
23
24 namespace drive {
25
26 namespace internal {
27 class FileCache;
28 class ResourceMetadata;
29 }  // namespace internal
30
31 struct EntryInfoPairResult;
32 class JobScheduler;
33 class ResourceEntry;
34
35 namespace file_system {
36
37 class OperationObserver;
38
39 // This class encapsulates the drive CreateFile function.  It is responsible for
40 // sending the request to the drive API, then updating the local state and
41 // metadata to reflect the new state.
42 class CreateFileOperation {
43  public:
44   CreateFileOperation(base::SequencedTaskRunner* blocking_task_runner,
45                       OperationObserver* observer,
46                       JobScheduler* scheduler,
47                       internal::ResourceMetadata* metadata,
48                       internal::FileCache* cache);
49   ~CreateFileOperation();
50
51   // Creates an empty file at |file_path| in the remote server. When the file
52   // already exists at that path, the operation fails if |is_exclusive| is true,
53   // and it succeeds without doing anything if the flag is false.
54   // If |mime_type| is non-empty, it is used as the mime type of the entry. If
55   // the parameter is empty, the type is guessed from |file_path|.
56   //
57   // |callback| must not be null.
58   void CreateFile(const base::FilePath& file_path,
59                   bool is_exclusive,
60                   const std::string& mime_type,
61                   const FileOperationCallback& callback);
62
63  private:
64   // Part of CreateFile(). Called after the precondition check is completed.
65   void CreateFileAfterCheckPreCondition(const base::FilePath& file_path,
66                                         const FileOperationCallback& callback,
67                                         std::string* parent_resource_id,
68                                         std::string* mime_type,
69                                         FileError error);
70
71   // Part of CreateFile(). Called after the server side file creation is
72   // completed.
73   void CreateFileAfterUpload(
74       const FileOperationCallback& callback,
75       google_apis::GDataErrorCode error,
76       scoped_ptr<google_apis::ResourceEntry> resource_entry);
77
78   // Part of CreateFile(). Called after the updating local state is completed.
79   void CreateFileAfterUpdateLocalState(const FileOperationCallback& callback,
80                                        base::FilePath* file_path,
81                                        FileError error);
82
83   scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
84   OperationObserver* observer_;
85   JobScheduler* scheduler_;
86   internal::ResourceMetadata* metadata_;
87   internal::FileCache* cache_;
88
89   // Note: This should remain the last member so it'll be destroyed and
90   // invalidate the weak pointers before any other members are destroyed.
91   base::WeakPtrFactory<CreateFileOperation> weak_ptr_factory_;
92   DISALLOW_COPY_AND_ASSIGN(CreateFileOperation);
93 };
94
95 }  // namespace file_system
96 }  // namespace drive
97
98 #endif  // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_