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.
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UPDATE_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UPDATE_OPERATION_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/gdata_errorcode.h"
17 class SequencedTaskRunner
;
20 namespace google_apis
{
22 } // namespace google_apis
32 class ResourceMetadata
;
33 } // namespace internal
35 namespace file_system
{
37 class OperationObserver
;
39 // This class encapsulates the drive Update function. It is responsible for
40 // sending the request to the drive API, then updating the local state and
41 // metadata to reflect the new state.
42 class UpdateOperation
{
44 UpdateOperation(base::SequencedTaskRunner
* blocking_task_runner
,
45 OperationObserver
* observer
,
46 JobScheduler
* scheduler
,
47 internal::ResourceMetadata
* metadata
,
48 internal::FileCache
* cache
);
51 // Flags to specify whether the md5 checksum should be compared to the value
52 // stored in metadata. If |RUN_CONTENT_CHECK| is set, the check is run and the
53 // upload takes place only when there is a mismatch in the checksum.
54 enum ContentCheckMode
{
59 // Updates a file by the given |local_id| on the Drive server by
60 // uploading an updated version. Used for uploading dirty files. The file
61 // should already be present in the cache.
63 // |callback| must not be null.
64 void UpdateFileByLocalId(const std::string
& local_id
,
65 const ClientContext
& context
,
66 ContentCheckMode check
,
67 const FileOperationCallback
& callback
);
72 void UpdateFileAfterGetLocalState(const ClientContext
& context
,
73 const FileOperationCallback
& callback
,
74 const LocalState
* local_state
,
77 void UpdateFileAfterUpload(
78 const FileOperationCallback
& callback
,
79 const std::string
& local_id
,
80 google_apis::GDataErrorCode error
,
81 scoped_ptr
<google_apis::ResourceEntry
> resource_entry
);
83 void UpdateFileAfterUpdateLocalState(const FileOperationCallback
& callback
,
84 const base::FilePath
* drive_file_path
,
87 scoped_refptr
<base::SequencedTaskRunner
> blocking_task_runner_
;
88 OperationObserver
* observer_
;
89 JobScheduler
* scheduler_
;
90 internal::ResourceMetadata
* metadata_
;
91 internal::FileCache
* cache_
;
93 // Note: This should remain the last member so it'll be destroyed and
94 // invalidate the weak pointers before any other members are destroyed.
95 base::WeakPtrFactory
<UpdateOperation
> weak_ptr_factory_
;
96 DISALLOW_COPY_AND_ASSIGN(UpdateOperation
);
99 } // namespace file_system
102 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UPDATE_OPERATION_H_