1// Copyright (c) 2012 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_REMOVE_OPERATION_H_
6#define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_REMOVE_OPERATION_H_
7
8#include "base/basictypes.h"
9#include "base/memory/ref_counted.h"
10#include "base/memory/scoped_ptr.h"
11#include "base/memory/weak_ptr.h"
12#include "chrome/browser/chromeos/drive/file_errors.h"
13#include "google_apis/drive/gdata_errorcode.h"
14
15namespace base {
16class FilePath;
17class SequencedTaskRunner;
18}  // namespace base
19
20namespace drive {
21
22class ResourceEntry;
23
24namespace internal {
25class FileCache;
26class ResourceMetadata;
27}  // namespace internal
28
29namespace file_system {
30
31class OperationDelegate;
32
33// This class encapsulates the drive Remove function.  It is responsible for
34// moving the removed entry to the trash.
35class RemoveOperation {
36 public:
37  RemoveOperation(base::SequencedTaskRunner* blocking_task_runner,
38                  OperationDelegate* delegate,
39                  internal::ResourceMetadata* metadata,
40                  internal::FileCache* cache);
41  ~RemoveOperation();
42
43  // Removes the resource at |path|. If |path| is a directory and |is_recursive|
44  // is set, it recursively removes all the descendants. If |is_recursive| is
45  // not set, it succeeds only when the directory is empty.
46  //
47  // |callback| must not be null.
48  void Remove(const base::FilePath& path,
49              bool is_recursive,
50              const FileOperationCallback& callback);
51
52 private:
53  // Part of Remove(). Called after UpdateLocalState() completion.
54  void RemoveAfterUpdateLocalState(const FileOperationCallback& callback,
55                                   const std::string* local_id,
56                                   const ResourceEntry* entry,
57                                   const base::FilePath* changed_directory_path,
58                                   FileError error);
59
60  scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
61  OperationDelegate* delegate_;
62  internal::ResourceMetadata* metadata_;
63  internal::FileCache* cache_;
64
65  // Note: This should remain the last member so it'll be destroyed and
66  // invalidate the weak pointers before any other members are destroyed.
67  base::WeakPtrFactory<RemoveOperation> weak_ptr_factory_;
68  DISALLOW_COPY_AND_ASSIGN(RemoveOperation);
69};
70
71}  // namespace file_system
72}  // namespace drive
73
74#endif  // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_REMOVE_OPERATION_H_
75