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"
15 class SequencedTaskRunner
;
21 class ResourceMetadata
;
22 } // namespace internal
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
{
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
,
49 const std::string
& mime_type
,
50 const FileOperationCallback
& callback
);
53 // Part of CreateFile(). Called after the updating local state is completed.
54 void CreateFileAfterUpdateLocalState(const FileOperationCallback
& callback
,
55 const base::FilePath
& file_path
,
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
73 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_FILE_OPERATION_H_