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_UPDATE_OPERATION_H_ 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UPDATE_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 15 namespace base { 16 class FilePath; 17 class SequencedTaskRunner; 18 } // namespace base 19 20 namespace google_apis { 21 class ResourceEntry; 22 } // namespace google_apis 23 24 namespace drive { 25 26 class JobScheduler; 27 class ResourceEntry; 28 struct ClientContext; 29 30 namespace internal { 31 class FileCache; 32 class ResourceMetadata; 33 } // namespace internal 34 35 namespace file_system { 36 37 class OperationObserver; 38 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 { 43 public: 44 UpdateOperation(base::SequencedTaskRunner* blocking_task_runner, 45 OperationObserver* observer, 46 JobScheduler* scheduler, 47 internal::ResourceMetadata* metadata, 48 internal::FileCache* cache); 49 ~UpdateOperation(); 50 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 { 55 NO_CONTENT_CHECK, 56 RUN_CONTENT_CHECK, 57 }; 58 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. 62 // 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); 68 69 struct LocalState; 70 71 private: 72 void UpdateFileAfterGetLocalState(const ClientContext& context, 73 const FileOperationCallback& callback, 74 const LocalState* local_state, 75 FileError error); 76 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); 82 83 void UpdateFileAfterUpdateLocalState(const FileOperationCallback& callback, 84 const base::FilePath* drive_file_path, 85 FileError error); 86 87 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 88 OperationObserver* observer_; 89 JobScheduler* scheduler_; 90 internal::ResourceMetadata* metadata_; 91 internal::FileCache* cache_; 92 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); 97 }; 98 99 } // namespace file_system 100 } // namespace drive 101 102 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UPDATE_OPERATION_H_ 103