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. 4 5#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_DIRECTORY_OPERATION_H_ 6#define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_DIRECTORY_OPERATION_H_ 7 8#include <set> 9 10#include "base/basictypes.h" 11#include "base/memory/ref_counted.h" 12#include "base/memory/weak_ptr.h" 13#include "chrome/browser/chromeos/drive/file_errors.h" 14 15namespace base { 16class FilePath; 17class SequencedTaskRunner; 18} // namespace base 19 20namespace drive { 21 22class FileChange; 23class ResourceEntry; 24 25namespace internal { 26class ResourceMetadata; 27} // namespace internal 28 29namespace file_system { 30 31class OperationDelegate; 32 33// This class encapsulates the drive Create Directory function. It is 34// responsible for sending the request to the drive API, then updating the 35// local state and metadata to reflect the new state. 36class CreateDirectoryOperation { 37 public: 38 CreateDirectoryOperation(base::SequencedTaskRunner* blocking_task_runner, 39 OperationDelegate* delegate, 40 internal::ResourceMetadata* metadata); 41 ~CreateDirectoryOperation(); 42 43 // Creates a new directory at |directory_path|. 44 // If |is_exclusive| is true, an error is raised in case a directory exists 45 // already at the |directory_path|. 46 // If |is_recursive| is true, the invocation creates parent directories as 47 // needed just like mkdir -p does. 48 // Invokes |callback| when finished with the result of the operation. 49 // |callback| must not be null. 50 void CreateDirectory(const base::FilePath& directory_path, 51 bool is_exclusive, 52 bool is_recursive, 53 const FileOperationCallback& callback); 54 55 private: 56 // Part of CreateDirectory(). Called after UpdateLocalState(). 57 void CreateDirectoryAfterUpdateLocalState( 58 const FileOperationCallback& callback, 59 const std::set<std::string>* updated_local_ids, 60 const FileChange* changed_directories, 61 FileError error); 62 63 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 64 OperationDelegate* delegate_; 65 internal::ResourceMetadata* metadata_; 66 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<CreateDirectoryOperation> weak_ptr_factory_; 70 DISALLOW_COPY_AND_ASSIGN(CreateDirectoryOperation); 71}; 72 73} // namespace file_system 74} // namespace drive 75 76#endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CREATE_DIRECTORY_OPERATION_H_ 77