| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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_SYNC_CONTENT_UPDATE_PERFORMER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_CONTENT_UPDATE_PERFORMER_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 // This class encapsulates the drive Update function. It is responsible for | |
| 38 // sending the request to the drive API, then updating the local state and | |
| 39 // metadata to reflect the new state. | |
| 40 class ContentUpdatePerformer { | |
| 41 public: | |
| 42 ContentUpdatePerformer(base::SequencedTaskRunner* blocking_task_runner, | |
| 43 JobScheduler* scheduler, | |
| 44 internal::ResourceMetadata* metadata, | |
| 45 internal::FileCache* cache); | |
| 46 ~ContentUpdatePerformer(); | |
| 47 | |
| 48 // Updates a file by the given |local_id| on the Drive server by | |
| 49 // uploading an updated version. Used for uploading dirty files. The file | |
| 50 // should already be present in the cache. | |
| 51 // | |
| 52 // |callback| must not be null. | |
| 53 void UpdateFileByLocalId(const std::string& local_id, | |
| 54 const ClientContext& context, | |
| 55 const FileOperationCallback& callback); | |
| 56 | |
| 57 struct LocalState; | |
| 58 | |
| 59 private: | |
| 60 void UpdateFileAfterGetLocalState(const ClientContext& context, | |
| 61 const FileOperationCallback& callback, | |
| 62 const LocalState* local_state, | |
| 63 FileError error); | |
| 64 | |
| 65 void UpdateFileAfterUpload( | |
| 66 const FileOperationCallback& callback, | |
| 67 const std::string& local_id, | |
| 68 google_apis::GDataErrorCode error, | |
| 69 scoped_ptr<google_apis::ResourceEntry> resource_entry); | |
| 70 | |
| 71 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | |
| 72 JobScheduler* scheduler_; | |
| 73 internal::ResourceMetadata* metadata_; | |
| 74 internal::FileCache* cache_; | |
| 75 | |
| 76 // Note: This should remain the last member so it'll be destroyed and | |
| 77 // invalidate the weak pointers before any other members are destroyed. | |
| 78 base::WeakPtrFactory<ContentUpdatePerformer> weak_ptr_factory_; | |
| 79 DISALLOW_COPY_AND_ASSIGN(ContentUpdatePerformer); | |
| 80 }; | |
| 81 | |
| 82 } // namespace file_system | |
| 83 } // namespace drive | |
| 84 | |
| 85 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_CONTENT_UPDATE_PERFORMER_H_ | |
| OLD | NEW |