Upstream version 9.38.198.0
[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/weak_ptr.h"
11 #include "chrome/browser/chromeos/drive/file_errors.h"
12
13 namespace base {
14 class FilePath;
15 class SequencedTaskRunner;
16 }  // namespace base
17
18 namespace drive {
19
20 namespace internal {
21 class ResourceMetadata;
22 }  // namespace internal
23
24 class ResourceEntry;
25
26 namespace file_system {
27
28 class OperationDelegate;
29
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
32 // metadata to reflect the new state.
33 class CreateFileOperation {
34  public:
35   CreateFileOperation(base::SequencedTaskRunner* blocking_task_runner,
36                       OperationDelegate* delegate,
37                       internal::ResourceMetadata* metadata);
38   ~CreateFileOperation();
39
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,
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
44   // the parameter is empty, the type is guessed from |file_path|.
45   //
46   // |callback| must not be null.
47   void CreateFile(const base::FilePath& file_path,
48                   bool is_exclusive,
49                   const std::string& mime_type,
50                   const FileOperationCallback& callback);
51
52  private:
53   // Part of CreateFile(). Called after the updating local state is completed.
54   void CreateFileAfterUpdateLocalState(const FileOperationCallback& callback,
55                                        const base::FilePath& file_path,
56                                        bool is_exclusive,
57                                        ResourceEntry* entry,
58                                        FileError error);
59
60   scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
61   OperationDelegate* delegate_;
62   internal::ResourceMetadata* metadata_;
63
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.
66   base::WeakPtrFactory<CreateFileOperation> weak_ptr_factory_;
67   DISALLOW_COPY_AND_ASSIGN(CreateFileOperation);
68 };
69
70 }  // namespace file_system
71 }  // namespace drive
72
73 #endif  // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_