Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / file_system / create_file_operation.h
blobd515ac793e671699207fb3913b39d20e8a94fc2f
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 CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_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 "chrome/browser/chromeos/drive/file_errors.h"
13 namespace base {
14 class FilePath;
15 class SequencedTaskRunner;
16 } // namespace base
18 namespace drive {
20 namespace internal {
21 class ResourceMetadata;
22 } // namespace internal
24 class ResourceEntry;
26 namespace file_system {
28 class OperationDelegate;
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();
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|.
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);
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);
60 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
61 OperationDelegate* delegate_;
62 internal::ResourceMetadata* metadata_;
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);
70 } // namespace file_system
71 } // namespace drive
73 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_