1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_REMOVE_PERFORMER_H_
#define CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_REMOVE_PERFORMER_H_
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/chromeos/drive/file_errors.h"
#include "google_apis/drive/gdata_errorcode.h"
namespace base {
class SequencedTaskRunner;
}
namespace google_apis {
class FileResource;
}
namespace drive {
class JobScheduler;
class ResourceEntry;
struct ClientContext;
namespace file_system {
class OperationObserver;
} // namespace file_system
namespace internal {
class EntryRevertPerformer;
class ResourceMetadata;
// This class encapsulates the drive Remove function. It is responsible for
// sending the request to the drive API, then updating the local state and
// metadata to reflect the new state.
class RemovePerformer {
public:
RemovePerformer(base::SequencedTaskRunner* blocking_task_runner,
file_system::OperationObserver* observer,
JobScheduler* scheduler,
ResourceMetadata* metadata);
~RemovePerformer();
// Removes the resource.
//
// |callback| must not be null.
void Remove(const std::string& local_id,
const ClientContext& context,
const FileOperationCallback& callback);
private:
// Part of Remove(). Called after GetResourceEntry() completion.
void RemoveAfterGetResourceEntry(const ClientContext& context,
const FileOperationCallback& callback,
const ResourceEntry* entry,
FileError error);
// Requests the server to move the specified resource to the trash.
void TrashResource(const ClientContext& context,
const FileOperationCallback& callback,
const std::string& resource_id,
const std::string& local_id);
// Part of TrashResource(). Called after server-side removal is done.
void TrashResourceAfterUpdateRemoteState(
const ClientContext& context,
const FileOperationCallback& callback,
const std::string& local_id,
google_apis::GDataErrorCode status);
// Requests the server to detach the specified resource from its parent.
void UnparentResource(const ClientContext& context,
const FileOperationCallback& callback,
const std::string& resource_id,
const std::string& local_id);
// Part of UnparentResource().
void UnparentResourceAfterGetFileResource(
const ClientContext& context,
const FileOperationCallback& callback,
const std::string& local_id,
google_apis::GDataErrorCode status,
scoped_ptr<google_apis::FileResource> file_resource);
// Part of UnparentResource().
void UnparentResourceAfterUpdateRemoteState(
const FileOperationCallback& callback,
const std::string& local_id,
google_apis::GDataErrorCode status);
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
file_system::OperationObserver* observer_;
JobScheduler* scheduler_;
ResourceMetadata* metadata_;
scoped_ptr<EntryRevertPerformer> entry_revert_performer_;
// Note: This should remain the last member so it'll be destroyed and
// invalidate the weak pointers before any other members are destroyed.
base::WeakPtrFactory<RemovePerformer> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(RemovePerformer);
};
} // namespace internal
} // namespace drive
#endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_REMOVE_PERFORMER_H_
|