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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 158 |
144 // Deletes the file identified by |resource_id|. | 159 // Deletes the file identified by |resource_id|. |
145 // |remote_file_md5| represents the expected hash value of the file to be | 160 // |remote_file_md5| represents the expected hash value of the file to be |
146 // deleted from Drive. If |remote_file_md5| is different from the actual | 161 // deleted from Drive. If |remote_file_md5| is different from the actual |
147 // value, cancels the deletion and invokes |callback| with | 162 // value, cancels the deletion and invokes |callback| with |
148 // GDataErrorCode::HTTP_CONFLICT immediately. | 163 // GDataErrorCode::HTTP_CONFLICT immediately. |
149 void DeleteFile(const std::string& resource_id, | 164 void DeleteFile(const std::string& resource_id, |
150 const std::string& remote_file_md5, | 165 const std::string& remote_file_md5, |
151 const GDataErrorCallback& callback); | 166 const GDataErrorCallback& callback); |
152 | 167 |
| 168 // DriveServiceObserver override. |
| 169 virtual void OnReadyToPerformOperations() OVERRIDE; |
| 170 |
153 private: | 171 private: |
154 friend class DriveFileSyncClientTest; | 172 friend class DriveFileSyncClientTest; |
155 friend class DriveFileSyncServiceTest; | 173 friend class DriveFileSyncServiceTest; |
156 | 174 |
157 // Constructor for test use. | 175 // Constructor for test use. |
158 DriveFileSyncClient( | 176 DriveFileSyncClient( |
159 Profile* profile, | 177 Profile* profile, |
160 scoped_ptr<google_apis::DriveServiceInterface> drive_service, | 178 scoped_ptr<google_apis::DriveServiceInterface> drive_service, |
161 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader); | 179 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader); |
162 | 180 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 scoped_ptr<google_apis::DocumentEntry> entry); | 249 scoped_ptr<google_apis::DocumentEntry> entry); |
232 | 250 |
233 void DidDeleteFile(const GDataErrorCallback& callback, | 251 void DidDeleteFile(const GDataErrorCallback& callback, |
234 google_apis::GDataErrorCode error); | 252 google_apis::GDataErrorCode error); |
235 | 253 |
236 static std::string FormatTitleQuery(const std::string& title); | 254 static std::string FormatTitleQuery(const std::string& title); |
237 | 255 |
238 scoped_ptr<google_apis::DriveServiceInterface> drive_service_; | 256 scoped_ptr<google_apis::DriveServiceInterface> drive_service_; |
239 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader_; | 257 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader_; |
240 | 258 |
| 259 ObserverList<DriveFileSyncClientObserver> observers_; |
| 260 |
241 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncClient); | 261 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncClient); |
242 }; | 262 }; |
243 | 263 |
244 } // namespace sync_file_system | 264 } // namespace sync_file_system |
245 | 265 |
246 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_CLIENT_H_ | 266 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_CLIENT_H_ |
OLD | NEW |