BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / components / drive / file_system / create_file_operation.h
blobb43132f45592e25967682f374bf9ffe3fd39f5e1
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.
5 #ifndef COMPONENTS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_
6 #define COMPONENTS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/threading/thread_checker.h"
12 #include "components/drive/file_errors.h"
14 namespace base {
15 class FilePath;
16 class SequencedTaskRunner;
17 } // namespace base
19 namespace drive {
21 namespace internal {
22 class ResourceMetadata;
23 } // namespace internal
25 class ResourceEntry;
27 namespace file_system {
29 class OperationDelegate;
31 // This class encapsulates the drive CreateFile function. It is responsible for
32 // sending the request to the drive API, then updating the local state and
33 // metadata to reflect the new state.
34 class CreateFileOperation {
35 public:
36 CreateFileOperation(base::SequencedTaskRunner* blocking_task_runner,
37 OperationDelegate* delegate,
38 internal::ResourceMetadata* metadata);
39 ~CreateFileOperation();
41 // Creates an empty file at |file_path|. When the file
42 // already exists at that path, the operation fails if |is_exclusive| is true,
43 // and it succeeds without doing anything if the flag is false.
44 // If |mime_type| is non-empty, it is used as the mime type of the entry. If
45 // the parameter is empty, the type is guessed from |file_path|.
47 // |callback| must not be null.
48 void CreateFile(const base::FilePath& file_path,
49 bool is_exclusive,
50 const std::string& mime_type,
51 const FileOperationCallback& callback);
53 private:
54 // Part of CreateFile(). Called after the updating local state is completed.
55 void CreateFileAfterUpdateLocalState(const FileOperationCallback& callback,
56 const base::FilePath& file_path,
57 bool is_exclusive,
58 ResourceEntry* entry,
59 FileError error);
61 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
62 OperationDelegate* delegate_;
63 internal::ResourceMetadata* metadata_;
65 base::ThreadChecker thread_checker_;
67 // Note: This should remain the last member so it'll be destroyed and
68 // invalidate the weak pointers before any other members are destroyed.
69 base::WeakPtrFactory<CreateFileOperation> weak_ptr_factory_;
70 DISALLOW_COPY_AND_ASSIGN(CreateFileOperation);
73 } // namespace file_system
74 } // namespace drive
76 #endif // COMPONENTS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_