| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_CLIENT_H_ |
| 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_CLIENT_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_CLIENT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/observer_list.h" |
| 13 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
| 14 #include "chrome/browser/google_apis/drive_service_interface.h" | 15 #include "chrome/browser/google_apis/drive_service_interface.h" |
| 15 #include "chrome/browser/google_apis/drive_upload_error.h" | 16 #include "chrome/browser/google_apis/drive_upload_error.h" |
| 16 #include "chrome/browser/google_apis/gdata_errorcode.h" | 17 #include "chrome/browser/google_apis/gdata_errorcode.h" |
| 17 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 18 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
| 18 | 19 |
| 19 class GURL; | 20 class GURL; |
| 20 class Profile; | 21 class Profile; |
| 21 | 22 |
| 22 namespace google_apis { | 23 namespace google_apis { |
| 23 class DriveUploaderInterface; | 24 class DriveUploaderInterface; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace sync_file_system { | 27 namespace sync_file_system { |
| 27 | 28 |
| 29 class DriveFileSyncClientObserver { |
| 30 public: |
| 31 DriveFileSyncClientObserver() {} |
| 32 virtual ~DriveFileSyncClientObserver() {} |
| 33 virtual void OnAuthenticated() = 0; |
| 34 |
| 35 private: |
| 36 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncClientObserver); |
| 37 }; |
| 38 |
| 28 // This class is responsible for talking to the Drive service to get and put | 39 // This class is responsible for talking to the Drive service to get and put |
| 29 // Drive directories, files and metadata. | 40 // Drive directories, files and metadata. |
| 30 // This class is owned by DriveFileSyncService. | 41 // This class is owned by DriveFileSyncService. |
| 31 class DriveFileSyncClient : public base::NonThreadSafe, | 42 class DriveFileSyncClient : public google_apis::DriveServiceObserver, |
| 43 public base::NonThreadSafe, |
| 32 public base::SupportsWeakPtr<DriveFileSyncClient> { | 44 public base::SupportsWeakPtr<DriveFileSyncClient> { |
| 33 public: | 45 public: |
| 34 typedef base::Callback<void(google_apis::GDataErrorCode error)> | 46 typedef base::Callback<void(google_apis::GDataErrorCode error)> |
| 35 GDataErrorCallback; | 47 GDataErrorCallback; |
| 36 typedef base::Callback<void(google_apis::GDataErrorCode error, | 48 typedef base::Callback<void(google_apis::GDataErrorCode error, |
| 37 const std::string& file_md5)> | 49 const std::string& file_md5)> |
| 38 DownloadFileCallback; | 50 DownloadFileCallback; |
| 39 typedef base::Callback<void(google_apis::GDataErrorCode error, | 51 typedef base::Callback<void(google_apis::GDataErrorCode error, |
| 40 const std::string& resource_id, | 52 const std::string& resource_id, |
| 41 const std::string& file_md5)> | 53 const std::string& file_md5)> |
| 42 UploadFileCallback; | 54 UploadFileCallback; |
| 43 typedef base::Callback<void(google_apis::GDataErrorCode error, | 55 typedef base::Callback<void(google_apis::GDataErrorCode error, |
| 44 const std::string& resource_id)> | 56 const std::string& resource_id)> |
| 45 ResourceIdCallback; | 57 ResourceIdCallback; |
| 46 typedef base::Callback<void(google_apis::GDataErrorCode error, | 58 typedef base::Callback<void(google_apis::GDataErrorCode error, |
| 47 int64 changestamp)> ChangeStampCallback; | 59 int64 changestamp)> ChangeStampCallback; |
| 48 typedef base::Callback<void(google_apis::GDataErrorCode error, | 60 typedef base::Callback<void(google_apis::GDataErrorCode error, |
| 49 scoped_ptr<google_apis::DocumentFeed> feed)> | 61 scoped_ptr<google_apis::DocumentFeed> feed)> |
| 50 DocumentFeedCallback; | 62 DocumentFeedCallback; |
| 51 typedef base::Callback<void(google_apis::GDataErrorCode error, | 63 typedef base::Callback<void(google_apis::GDataErrorCode error, |
| 52 scoped_ptr<google_apis::DocumentEntry> entry)> | 64 scoped_ptr<google_apis::DocumentEntry> entry)> |
| 53 DocumentEntryCallback; | 65 DocumentEntryCallback; |
| 54 | 66 |
| 55 explicit DriveFileSyncClient(Profile* profile); | 67 explicit DriveFileSyncClient(Profile* profile); |
| 56 virtual ~DriveFileSyncClient(); | 68 virtual ~DriveFileSyncClient(); |
| 57 | 69 |
| 70 void AddObserver(DriveFileSyncClientObserver* observer); |
| 71 void RemoveObserver(DriveFileSyncClientObserver* observer); |
| 72 |
| 58 static scoped_ptr<DriveFileSyncClient> CreateForTesting( | 73 static scoped_ptr<DriveFileSyncClient> CreateForTesting( |
| 59 Profile* profile, | 74 Profile* profile, |
| 60 scoped_ptr<google_apis::DriveServiceInterface> drive_service, | 75 scoped_ptr<google_apis::DriveServiceInterface> drive_service, |
| 61 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader); | 76 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader); |
| 62 | 77 |
| 63 // Fetches Resource ID of the directory where we should place all files to | 78 // Fetches Resource ID of the directory where we should place all files to |
| 64 // sync. Upon completion, invokes |callback|. | 79 // sync. Upon completion, invokes |callback|. |
| 65 // If the directory does not exist on the server this also creates | 80 // If the directory does not exist on the server this also creates |
| 66 // the directory. | 81 // the directory. |
| 67 void GetDriveDirectoryForSyncRoot(const ResourceIdCallback& callback); | 82 void GetDriveDirectoryForSyncRoot(const ResourceIdCallback& callback); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 153 |
| 139 // Deletes the file identified by |resource_id|. | 154 // Deletes the file identified by |resource_id|. |
| 140 // |remote_file_md5| represents the expected hash value of the file to be | 155 // |remote_file_md5| represents the expected hash value of the file to be |
| 141 // deleted from Drive. If |remote_file_md5| is different from the actual | 156 // deleted from Drive. If |remote_file_md5| is different from the actual |
| 142 // value, cancels the deletion and invokes |callback| with | 157 // value, cancels the deletion and invokes |callback| with |
| 143 // GDataErrorCode::HTTP_CONFLICT immediately. | 158 // GDataErrorCode::HTTP_CONFLICT immediately. |
| 144 void DeleteFile(const std::string& resource_id, | 159 void DeleteFile(const std::string& resource_id, |
| 145 const std::string& remote_file_md5, | 160 const std::string& remote_file_md5, |
| 146 const GDataErrorCallback& callback); | 161 const GDataErrorCallback& callback); |
| 147 | 162 |
| 163 // DriveServiceObserver override. |
| 164 virtual void OnReadyToPerformOperations() OVERRIDE; |
| 165 |
| 148 private: | 166 private: |
| 149 friend class DriveFileSyncClientTest; | 167 friend class DriveFileSyncClientTest; |
| 150 friend class DriveFileSyncServiceTest; | 168 friend class DriveFileSyncServiceTest; |
| 151 | 169 |
| 152 // Constructor for test use. | 170 // Constructor for test use. |
| 153 DriveFileSyncClient( | 171 DriveFileSyncClient( |
| 154 Profile* profile, | 172 Profile* profile, |
| 155 scoped_ptr<google_apis::DriveServiceInterface> drive_service, | 173 scoped_ptr<google_apis::DriveServiceInterface> drive_service, |
| 156 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader); | 174 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader); |
| 157 | 175 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 scoped_ptr<google_apis::DocumentEntry> entry); | 244 scoped_ptr<google_apis::DocumentEntry> entry); |
| 227 | 245 |
| 228 void DidDeleteFile(const GDataErrorCallback& callback, | 246 void DidDeleteFile(const GDataErrorCallback& callback, |
| 229 google_apis::GDataErrorCode error); | 247 google_apis::GDataErrorCode error); |
| 230 | 248 |
| 231 static std::string FormatTitleQuery(const std::string& title); | 249 static std::string FormatTitleQuery(const std::string& title); |
| 232 | 250 |
| 233 scoped_ptr<google_apis::DriveServiceInterface> drive_service_; | 251 scoped_ptr<google_apis::DriveServiceInterface> drive_service_; |
| 234 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader_; | 252 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader_; |
| 235 | 253 |
| 254 ObserverList<DriveFileSyncClientObserver> observers_; |
| 255 |
| 236 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncClient); | 256 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncClient); |
| 237 }; | 257 }; |
| 238 | 258 |
| 239 } // namespace sync_file_system | 259 } // namespace sync_file_system |
| 240 | 260 |
| 241 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_CLIENT_H_ | 261 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_CLIENT_H_ |
| OLD | NEW |