Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_client.h

Issue 11414253: DriveFileSyncService listens to OnAuthenticated event to recover from unavailable state (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/sync_file_system/drive_file_sync_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
153 static std::string OriginToDirectoryTitle(const GURL& origin); 168 static std::string OriginToDirectoryTitle(const GURL& origin);
154 static GURL DirectoryTitleToOrigin(const std::string& title); 169 static GURL DirectoryTitleToOrigin(const std::string& title);
155 170
171 // DriveServiceObserver overrides.
172 virtual void OnReadyToPerformOperations() OVERRIDE;
173
156 private: 174 private:
157 friend class DriveFileSyncClientTest; 175 friend class DriveFileSyncClientTest;
158 friend class DriveFileSyncServiceTest; 176 friend class DriveFileSyncServiceTest;
159 177
160 // Constructor for test use. 178 // Constructor for test use.
161 DriveFileSyncClient( 179 DriveFileSyncClient(
162 Profile* profile, 180 Profile* profile,
163 scoped_ptr<google_apis::DriveServiceInterface> drive_service, 181 scoped_ptr<google_apis::DriveServiceInterface> drive_service,
164 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader); 182 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader);
165 183
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 scoped_ptr<google_apis::DocumentEntry> entry); 252 scoped_ptr<google_apis::DocumentEntry> entry);
235 253
236 void DidDeleteFile(const GDataErrorCallback& callback, 254 void DidDeleteFile(const GDataErrorCallback& callback,
237 google_apis::GDataErrorCode error); 255 google_apis::GDataErrorCode error);
238 256
239 static std::string FormatTitleQuery(const std::string& title); 257 static std::string FormatTitleQuery(const std::string& title);
240 258
241 scoped_ptr<google_apis::DriveServiceInterface> drive_service_; 259 scoped_ptr<google_apis::DriveServiceInterface> drive_service_;
242 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader_; 260 scoped_ptr<google_apis::DriveUploaderInterface> drive_uploader_;
243 261
262 ObserverList<DriveFileSyncClientObserver> observers_;
263
244 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncClient); 264 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncClient);
245 }; 265 };
246 266
247 } // namespace sync_file_system 267 } // namespace sync_file_system
248 268
249 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_CLIENT_H_ 269 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_FILE_SYNC_CLIENT_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync_file_system/drive_file_sync_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698