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() {} | |
kinuko
2012/11/30 06:26:50
I prefer leaving this pure virtual
nhiroki
2012/11/30 08:27:41
Done.
| |
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 |
67 class Observer { | |
68 public: | |
69 Observer() {} | |
70 virtual ~Observer() {} | |
71 virtual void OnAuthenticated(); | |
72 }; | |
kinuko
2012/11/30 06:26:50
Not used?
nhiroki
2012/11/30 08:27:41
Done.
| |
73 | |
55 explicit DriveFileSyncClient(Profile* profile); | 74 explicit DriveFileSyncClient(Profile* profile); |
56 virtual ~DriveFileSyncClient(); | 75 virtual ~DriveFileSyncClient(); |
57 | 76 |
77 void AddObserver(DriveFileSyncClientObserver* observer); | |
78 void RemoveObserver(DriveFileSyncClientObserver* observer); | |
79 | |
58 static scoped_ptr<DriveFileSyncClient> CreateForTesting( | 80 static scoped_ptr<DriveFileSyncClient> CreateForTesting( |
59 Profile* profile, | 81 Profile* profile, |
60 scoped_ptr<google_apis::DriveServiceInterface> drive_service, | 82 scoped_ptr<google_apis::DriveServiceInterface> drive_service, |
61 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader); | 83 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader); |
62 | 84 |
63 // Fetches Resource ID of the directory where we should place all files to | 85 // Fetches Resource ID of the directory where we should place all files to |
64 // sync. Upon completion, invokes |callback|. | 86 // sync. Upon completion, invokes |callback|. |
65 // If the directory does not exist on the server this also creates | 87 // If the directory does not exist on the server this also creates |
66 // the directory. | 88 // the directory. |
67 void GetDriveDirectoryForSyncRoot(const ResourceIdCallback& callback); | 89 void GetDriveDirectoryForSyncRoot(const ResourceIdCallback& callback); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 | 160 |
139 // Deletes the file identified by |resource_id|. | 161 // Deletes the file identified by |resource_id|. |
140 // |remote_file_md5| represents the expected hash value of the file to be | 162 // |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 | 163 // deleted from Drive. If |remote_file_md5| is different from the actual |
142 // value, cancels the deletion and invokes |callback| with | 164 // value, cancels the deletion and invokes |callback| with |
143 // GDataErrorCode::HTTP_CONFLICT immediately. | 165 // GDataErrorCode::HTTP_CONFLICT immediately. |
144 void DeleteFile(const std::string& resource_id, | 166 void DeleteFile(const std::string& resource_id, |
145 const std::string& remote_file_md5, | 167 const std::string& remote_file_md5, |
146 const GDataErrorCallback& callback); | 168 const GDataErrorCallback& callback); |
147 | 169 |
170 // DriveServiceObserver override. | |
171 virtual void OnReadyToPerformOperations() OVERRIDE; | |
172 | |
148 private: | 173 private: |
149 friend class DriveFileSyncClientTest; | 174 friend class DriveFileSyncClientTest; |
150 friend class DriveFileSyncServiceTest; | 175 friend class DriveFileSyncServiceTest; |
151 | 176 |
152 // Constructor for test use. | 177 // Constructor for test use. |
153 DriveFileSyncClient( | 178 DriveFileSyncClient( |
154 Profile* profile, | 179 Profile* profile, |
155 scoped_ptr<google_apis::DriveServiceInterface> drive_service, | 180 scoped_ptr<google_apis::DriveServiceInterface> drive_service, |
156 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader); | 181 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader); |
157 | 182 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 scoped_ptr<google_apis::DocumentEntry> entry); | 251 scoped_ptr<google_apis::DocumentEntry> entry); |
227 | 252 |
228 void DidDeleteFile(const GDataErrorCallback& callback, | 253 void DidDeleteFile(const GDataErrorCallback& callback, |
229 google_apis::GDataErrorCode error); | 254 google_apis::GDataErrorCode error); |
230 | 255 |
231 static std::string FormatTitleQuery(const std::string& title); | 256 static std::string FormatTitleQuery(const std::string& title); |
232 | 257 |
233 scoped_ptr<google_apis::DriveServiceInterface> drive_service_; | 258 scoped_ptr<google_apis::DriveServiceInterface> drive_service_; |
234 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader_; | 259 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader_; |
235 | 260 |
261 ObserverList<DriveFileSyncClientObserver> observers_; | |
262 | |
236 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncClient); | 263 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncClient); |
237 }; | 264 }; |
238 | 265 |
239 } // namespace sync_file_system | 266 } // namespace sync_file_system |
240 | 267 |
241 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_CLIENT_H_ | 268 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_CLIENT_H_ |
OLD | NEW |