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

Side by Side Diff: chrome/browser/sync/profile_sync_service.h

Issue 1128012: Rewrite DTM to support dynamic data type configuration (Closed)
Patch Set: Address review comments and fix a leak. Created 10 years, 9 months 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_PROFILE_SYNC_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_
6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <map> 9 #include <map>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/observer_list.h" 12 #include "base/observer_list.h"
13 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "chrome/browser/google_service_auth_error.h" 15 #include "chrome/browser/google_service_auth_error.h"
16 #include "chrome/browser/profile.h" 16 #include "chrome/browser/profile.h"
17 #include "chrome/browser/sync/glue/data_type_controller.h" 17 #include "chrome/browser/sync/glue/data_type_controller.h"
18 #include "chrome/browser/sync/glue/data_type_manager.h" 18 #include "chrome/browser/sync/glue/data_type_manager.h"
19 #include "chrome/browser/sync/glue/sync_backend_host.h" 19 #include "chrome/browser/sync/glue/sync_backend_host.h"
20 #include "chrome/browser/sync/notification_method.h" 20 #include "chrome/browser/sync/notification_method.h"
21 #include "chrome/browser/sync/sync_setup_wizard.h" 21 #include "chrome/browser/sync/sync_setup_wizard.h"
22 #include "chrome/browser/sync/syncable/model_type.h" 22 #include "chrome/browser/sync/syncable/model_type.h"
23 #include "chrome/browser/sync/unrecoverable_error_handler.h" 23 #include "chrome/browser/sync/unrecoverable_error_handler.h"
24 #include "chrome/common/notification_observer.h"
25 #include "chrome/common/notification_registrar.h"
24 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
25 #include "testing/gtest/include/gtest/gtest_prod.h" 27 #include "testing/gtest/include/gtest/gtest_prod.h"
26 28
29 class NotificationDetails;
30 class NotificationSource;
31 class NotificationType;
32
27 // Various UI components such as the New Tab page can be driven by observing 33 // Various UI components such as the New Tab page can be driven by observing
28 // the ProfileSyncService through this interface. 34 // the ProfileSyncService through this interface.
29 class ProfileSyncServiceObserver { 35 class ProfileSyncServiceObserver {
30 public: 36 public:
31 // When one of the following events occurs, OnStateChanged() is called. 37 // When one of the following events occurs, OnStateChanged() is called.
32 // Observers should query the service to determine what happened. 38 // Observers should query the service to determine what happened.
33 // - We initialized successfully. 39 // - We initialized successfully.
34 // - There was an authentication error and the user needs to reauthenticate. 40 // - There was an authentication error and the user needs to reauthenticate.
35 // - The sync servers are unavailable at this time. 41 // - The sync servers are unavailable at this time.
36 // - Credentials are now in flight for authentication. 42 // - Credentials are now in flight for authentication.
37 virtual void OnStateChanged() = 0; 43 virtual void OnStateChanged() = 0;
38 protected: 44 protected:
39 virtual ~ProfileSyncServiceObserver() { } 45 virtual ~ProfileSyncServiceObserver() { }
40 }; 46 };
41 47
42 // ProfileSyncService is the layer between browser subsystems like bookmarks, 48 // ProfileSyncService is the layer between browser subsystems like bookmarks,
43 // and the sync backend. 49 // and the sync backend.
44 class ProfileSyncService : public browser_sync::SyncFrontend, 50 class ProfileSyncService : public browser_sync::SyncFrontend,
45 public browser_sync::UnrecoverableErrorHandler { 51 public browser_sync::UnrecoverableErrorHandler,
52 public NotificationObserver {
46 public: 53 public:
47 typedef ProfileSyncServiceObserver Observer; 54 typedef ProfileSyncServiceObserver Observer;
48 typedef browser_sync::SyncBackendHost::Status Status; 55 typedef browser_sync::SyncBackendHost::Status Status;
49 56
50 enum SyncEventCodes { 57 enum SyncEventCodes {
51 MIN_SYNC_EVENT_CODE = 0, 58 MIN_SYNC_EVENT_CODE = 0,
52 59
53 // Events starting the sync service. 60 // Events starting the sync service.
54 START_FROM_NTP = 1, // Sync was started from the ad in NTP 61 START_FROM_NTP = 1, // Sync was started from the ad in NTP
55 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu. 62 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 202
196 browser_sync::SyncBackendHost* backend() { return backend_.get(); } 203 browser_sync::SyncBackendHost* backend() { return backend_.get(); }
197 204
198 virtual void ActivateDataType( 205 virtual void ActivateDataType(
199 browser_sync::DataTypeController* data_type_controller, 206 browser_sync::DataTypeController* data_type_controller,
200 browser_sync::ChangeProcessor* change_processor); 207 browser_sync::ChangeProcessor* change_processor);
201 virtual void DeactivateDataType( 208 virtual void DeactivateDataType(
202 browser_sync::DataTypeController* data_type_controller, 209 browser_sync::DataTypeController* data_type_controller,
203 browser_sync::ChangeProcessor* change_processor); 210 browser_sync::ChangeProcessor* change_processor);
204 211
212 // NotificationObserver implementation.
213 virtual void Observe(NotificationType type,
214 const NotificationSource& source,
215 const NotificationDetails& details);
216
205 protected: 217 protected:
206 // Call this after any of the subsystems being synced (the bookmark 218 // Call this after any of the subsystems being synced (the bookmark
207 // model and the sync backend) finishes its initialization. When everything 219 // model and the sync backend) finishes its initialization. When everything
208 // is ready, this function will bootstrap the subsystems so that they are 220 // is ready, this function will bootstrap the subsystems so that they are
209 // initially in sync, and start forwarding changes between the two models. 221 // initially in sync, and start forwarding changes between the two models.
210 void StartProcessingChangesIfReady(); 222 void StartProcessingChangesIfReady();
211 223
212 // Returns whether processing changes is allowed. Check this before doing 224 // Returns whether processing changes is allowed. Check this before doing
213 // any model-modifying operations. 225 // any model-modifying operations.
214 bool ShouldPushChanges(); 226 bool ShouldPushChanges();
215 227
216 // Starts up the backend sync components. 228 // Starts up the backend sync components.
217 void StartUp(); 229 void StartUp();
218 // Shuts down the backend sync components. 230 // Shuts down the backend sync components.
219 // |sync_disabled| indicates if syncing is being disabled or not. 231 // |sync_disabled| indicates if syncing is being disabled or not.
220 void Shutdown(bool sync_disabled); 232 void Shutdown(bool sync_disabled);
221 233
222 // Methods to register and remove preferences. 234 // Methods to register and remove preferences.
223 void RegisterPreferences(); 235 void RegisterPreferences();
224 void ClearPreferences(); 236 void ClearPreferences();
225 237
226 void DataTypeManagerStartCallback(
227 browser_sync::DataTypeManager::StartResult result);
228
229 // Tests need to override this. If |delete_sync_data_folder| is true, then 238 // Tests need to override this. If |delete_sync_data_folder| is true, then
230 // this method will delete all previous "Sync Data" folders. (useful if the 239 // this method will delete all previous "Sync Data" folders. (useful if the
231 // folder is partial/corrupt) 240 // folder is partial/corrupt)
232 virtual void InitializeBackend(bool delete_sync_data_folder); 241 virtual void InitializeBackend(bool delete_sync_data_folder);
233 242
234 // We keep track of the last auth error observed so we can cover up the first 243 // We keep track of the last auth error observed so we can cover up the first
235 // "expected" auth failure from observers. 244 // "expected" auth failure from observers.
236 // TODO(timsteele): Same as expecting_first_run_auth_needed_event_. Remove 245 // TODO(timsteele): Same as expecting_first_run_auth_needed_event_. Remove
237 // this! 246 // this!
238 GoogleServiceAuthError last_auth_error_; 247 GoogleServiceAuthError last_auth_error_;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // As its name suggests, this should NOT be used for anything other than UI. 318 // As its name suggests, this should NOT be used for anything other than UI.
310 bool is_auth_in_progress_; 319 bool is_auth_in_progress_;
311 320
312 SyncSetupWizard wizard_; 321 SyncSetupWizard wizard_;
313 322
314 // True if an unrecoverable error (e.g. violation of an assumed invariant) 323 // True if an unrecoverable error (e.g. violation of an assumed invariant)
315 // occurred during syncer operation. This value should be checked before 324 // occurred during syncer operation. This value should be checked before
316 // doing any work that might corrupt things further. 325 // doing any work that might corrupt things further.
317 bool unrecoverable_error_detected_; 326 bool unrecoverable_error_detected_;
318 327
319 // True if at least one of the data types started up was started for
320 // the first time. TODO(sync): Remove this when we have full
321 // support for starting multiple data types.
322 bool startup_had_first_time_;
323
324 // Which peer-to-peer notification method to use. 328 // Which peer-to-peer notification method to use.
325 browser_sync::NotificationMethod notification_method_; 329 browser_sync::NotificationMethod notification_method_;
326 330
327 // Manages the start and stop of the various data types. 331 // Manages the start and stop of the various data types.
328 scoped_ptr<browser_sync::DataTypeManager> data_type_manager_; 332 scoped_ptr<browser_sync::DataTypeManager> data_type_manager_;
329 333
330 ObserverList<Observer> observers_; 334 ObserverList<Observer> observers_;
331 335
336 NotificationRegistrar registrar_;
337
332 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); 338 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService);
333 }; 339 };
334 340
335 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ 341 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/data_type_manager_mock.h ('k') | chrome/browser/sync/profile_sync_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698