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_SYNC_REMOVE_PERFORMER_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_REMOVE_PERFORMER_H_
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/drive_api_error_codes.h"
16 class SequencedTaskRunner
;
19 namespace google_apis
{
29 namespace file_system
{
30 class OperationDelegate
;
31 } // namespace file_system
35 class EntryRevertPerformer
;
36 class ResourceMetadata
;
38 // This class encapsulates the drive Remove function. It is responsible for
39 // sending the request to the drive API, then updating the local state and
40 // metadata to reflect the new state.
41 class RemovePerformer
{
43 RemovePerformer(base::SequencedTaskRunner
* blocking_task_runner
,
44 file_system::OperationDelegate
* delegate
,
45 JobScheduler
* scheduler
,
46 ResourceMetadata
* metadata
);
49 // Removes the resource.
51 // |callback| must not be null.
52 void Remove(const std::string
& local_id
,
53 const ClientContext
& context
,
54 const FileOperationCallback
& callback
);
57 // Part of Remove(). Called after GetResourceEntry() completion.
58 void RemoveAfterGetResourceEntry(const ClientContext
& context
,
59 const FileOperationCallback
& callback
,
60 const ResourceEntry
* entry
,
63 // Requests the server to move the specified resource to the trash.
64 void TrashResource(const ClientContext
& context
,
65 const FileOperationCallback
& callback
,
66 const std::string
& resource_id
,
67 const std::string
& local_id
);
69 // Part of TrashResource(). Called after server-side removal is done.
70 void TrashResourceAfterUpdateRemoteState(
71 const ClientContext
& context
,
72 const FileOperationCallback
& callback
,
73 const std::string
& local_id
,
74 google_apis::DriveApiErrorCode status
);
76 // Requests the server to detach the specified resource from its parent.
77 void UnparentResource(const ClientContext
& context
,
78 const FileOperationCallback
& callback
,
79 const std::string
& resource_id
,
80 const std::string
& local_id
);
82 // Part of UnparentResource().
83 void UnparentResourceAfterGetFileResource(
84 const ClientContext
& context
,
85 const FileOperationCallback
& callback
,
86 const std::string
& local_id
,
87 google_apis::DriveApiErrorCode status
,
88 scoped_ptr
<google_apis::FileResource
> file_resource
);
90 // Part of UnparentResource().
91 void UnparentResourceAfterUpdateRemoteState(
92 const FileOperationCallback
& callback
,
93 const std::string
& local_id
,
94 google_apis::DriveApiErrorCode status
);
96 scoped_refptr
<base::SequencedTaskRunner
> blocking_task_runner_
;
97 file_system::OperationDelegate
* delegate_
;
98 JobScheduler
* scheduler_
;
99 ResourceMetadata
* metadata_
;
100 scoped_ptr
<EntryRevertPerformer
> entry_revert_performer_
;
102 // Note: This should remain the last member so it'll be destroyed and
103 // invalidate the weak pointers before any other members are destroyed.
104 base::WeakPtrFactory
<RemovePerformer
> weak_ptr_factory_
;
105 DISALLOW_COPY_AND_ASSIGN(RemovePerformer
);
108 } // namespace internal
111 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_REMOVE_PERFORMER_H_