1 // Copyright (c) 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_DIRECTORY_OPERATION_H_
6 #define COMPONENTS_DRIVE_FILE_SYSTEM_CREATE_DIRECTORY_OPERATION_H_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h"
14 #include "components/drive/file_errors.h"
18 class SequencedTaskRunner
;
27 class ResourceMetadata
;
28 } // namespace internal
30 namespace file_system
{
32 class OperationDelegate
;
34 // This class encapsulates the drive Create Directory function. It is
35 // responsible for sending the request to the drive API, then updating the
36 // local state and metadata to reflect the new state.
37 class CreateDirectoryOperation
{
39 CreateDirectoryOperation(base::SequencedTaskRunner
* blocking_task_runner
,
40 OperationDelegate
* delegate
,
41 internal::ResourceMetadata
* metadata
);
42 ~CreateDirectoryOperation();
44 // Creates a new directory at |directory_path|.
45 // If |is_exclusive| is true, an error is raised in case a directory exists
46 // already at the |directory_path|.
47 // If |is_recursive| is true, the invocation creates parent directories as
48 // needed just like mkdir -p does.
49 // Invokes |callback| when finished with the result of the operation.
50 // |callback| must not be null.
51 void CreateDirectory(const base::FilePath
& directory_path
,
54 const FileOperationCallback
& callback
);
57 // Part of CreateDirectory(). Called after UpdateLocalState().
58 void CreateDirectoryAfterUpdateLocalState(
59 const FileOperationCallback
& callback
,
60 const std::set
<std::string
>* updated_local_ids
,
61 const FileChange
* changed_directories
,
64 scoped_refptr
<base::SequencedTaskRunner
> blocking_task_runner_
;
65 OperationDelegate
* delegate_
;
66 internal::ResourceMetadata
* metadata_
;
68 base::ThreadChecker thread_checker_
;
70 // Note: This should remain the last member so it'll be destroyed and
71 // invalidate the weak pointers before any other members are destroyed.
72 base::WeakPtrFactory
<CreateDirectoryOperation
> weak_ptr_factory_
;
73 DISALLOW_COPY_AND_ASSIGN(CreateDirectoryOperation
);
76 } // namespace file_system
79 #endif // COMPONENTS_DRIVE_FILE_SYSTEM_CREATE_DIRECTORY_OPERATION_H_