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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host.h

Issue 10701085: Revert "Revert 142517 - [Sync] Refactor sync configuration logic." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 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 | Annotate | Revision Log
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_GLUE_SYNC_BACKEND_HOST_H_ 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "chrome/browser/sync/glue/backend_data_type_configurer.h" 18 #include "chrome/browser/sync/glue/backend_data_type_configurer.h"
19 #include "chrome/browser/sync/glue/chrome_extensions_activity_monitor.h" 19 #include "chrome/browser/sync/glue/chrome_extensions_activity_monitor.h"
20 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" 20 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h"
21 #include "chrome/common/net/gaia/google_service_auth_error.h" 21 #include "chrome/common/net/gaia/google_service_auth_error.h"
22 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
23 #include "sync/internal_api/public/base/model_type.h" 23 #include "sync/internal_api/public/base/model_type.h"
24 #include "sync/internal_api/public/configure_reason.h" 24 #include "sync/internal_api/public/configure_reason.h"
25 #include "sync/internal_api/public/engine/model_safe_worker.h" 25 #include "sync/internal_api/public/engine/model_safe_worker.h"
26 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" 26 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
27 #include "sync/internal_api/public/sync_manager.h" 27 #include "sync/internal_api/public/sync_manager.h"
28 #include "sync/internal_api/public/sync_manager_factory.h"
28 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" 29 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h"
29 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" 30 #include "sync/internal_api/public/util/unrecoverable_error_handler.h"
30 #include "sync/internal_api/public/util/weak_handle.h" 31 #include "sync/internal_api/public/util/weak_handle.h"
31 #include "sync/notifier/sync_notifier_factory.h" 32 #include "sync/notifier/sync_notifier_factory.h"
32 #include "sync/protocol/encryption.pb.h" 33 #include "sync/protocol/encryption.pb.h"
33 #include "sync/protocol/sync_protocol_error.h" 34 #include "sync/protocol/sync_protocol_error.h"
34 35
35 class MessageLoop; 36 class MessageLoop;
36 class Profile; 37 class Profile;
37 38
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // Optionally delete the Sync Data folder (if it's corrupt). 164 // Optionally delete the Sync Data folder (if it's corrupt).
164 // |report_unrecoverable_error_function| can be NULL. 165 // |report_unrecoverable_error_function| can be NULL.
165 // Note: |unrecoverable_error_handler| may be invoked from any thread. 166 // Note: |unrecoverable_error_handler| may be invoked from any thread.
166 void Initialize( 167 void Initialize(
167 SyncFrontend* frontend, 168 SyncFrontend* frontend,
168 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 169 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
169 const GURL& service_url, 170 const GURL& service_url,
170 syncer::ModelTypeSet initial_types, 171 syncer::ModelTypeSet initial_types,
171 const syncer::SyncCredentials& credentials, 172 const syncer::SyncCredentials& credentials,
172 bool delete_sync_data_folder, 173 bool delete_sync_data_folder,
174 syncer::SyncManagerFactory* sync_manager_factory,
173 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, 175 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
174 syncer::ReportUnrecoverableErrorFunction 176 syncer::ReportUnrecoverableErrorFunction
175 report_unrecoverable_error_function); 177 report_unrecoverable_error_function);
176 178
177 // Called from |frontend_loop| to update SyncCredentials. 179 // Called from |frontend_loop| to update SyncCredentials.
178 void UpdateCredentials(const syncer::SyncCredentials& credentials); 180 void UpdateCredentials(const syncer::SyncCredentials& credentials);
179 181
180 // This starts the SyncerThread running a Syncer object to communicate with 182 // This starts the SyncerThread running a Syncer object to communicate with
181 // sync servers. Until this is called, no changes will leave or enter this 183 // sync servers. Until this is called, no changes will leave or enter this
182 // browser from the cloud / sync servers. 184 // browser from the cloud / sync servers.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 271
270 void GetModelSafeRoutingInfo(syncer::ModelSafeRoutingInfo* out) const; 272 void GetModelSafeRoutingInfo(syncer::ModelSafeRoutingInfo* out) const;
271 273
272 protected: 274 protected:
273 // The types and functions below are protected so that test 275 // The types and functions below are protected so that test
274 // subclasses can use them. 276 // subclasses can use them.
275 // 277 //
276 // TODO(akalin): Figure out a better way for tests to hook into 278 // TODO(akalin): Figure out a better way for tests to hook into
277 // SyncBackendHost. 279 // SyncBackendHost.
278 280
279 typedef base::Callback<syncer::HttpPostProviderFactory*(void)> 281 typedef base::Callback<scoped_ptr<syncer::HttpPostProviderFactory>(void)>
280 MakeHttpBridgeFactoryFn; 282 MakeHttpBridgeFactoryFn;
281 283
282 struct DoInitializeOptions { 284 struct DoInitializeOptions {
283 DoInitializeOptions( 285 DoInitializeOptions(
284 MessageLoop* sync_loop, 286 MessageLoop* sync_loop,
285 SyncBackendRegistrar* registrar, 287 SyncBackendRegistrar* registrar,
286 const syncer::ModelSafeRoutingInfo& routing_info, 288 const syncer::ModelSafeRoutingInfo& routing_info,
287 const std::vector<syncer::ModelSafeWorker*>& workers, 289 const std::vector<syncer::ModelSafeWorker*>& workers,
288 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 290 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
289 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 291 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
290 const GURL& service_url, 292 const GURL& service_url,
291 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, 293 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn,
292 const syncer::SyncCredentials& credentials, 294 const syncer::SyncCredentials& credentials,
293 ChromeSyncNotificationBridge* chrome_sync_notification_bridge, 295 ChromeSyncNotificationBridge* chrome_sync_notification_bridge,
294 syncer::SyncNotifierFactory* sync_notifier_factory, 296 syncer::SyncNotifierFactory* sync_notifier_factory,
297 syncer::SyncManagerFactory* sync_manager_factory,
295 bool delete_sync_data_folder, 298 bool delete_sync_data_folder,
296 const std::string& restored_key_for_bootstrapping, 299 const std::string& restored_key_for_bootstrapping,
297 syncer::SyncManager::TestingMode testing_mode, 300 syncer::SyncManager::TestingMode testing_mode,
298 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, 301 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
299 syncer::ReportUnrecoverableErrorFunction 302 syncer::ReportUnrecoverableErrorFunction
300 report_unrecoverable_error_function); 303 report_unrecoverable_error_function);
301 ~DoInitializeOptions(); 304 ~DoInitializeOptions();
302 305
303 MessageLoop* sync_loop; 306 MessageLoop* sync_loop;
304 SyncBackendRegistrar* registrar; 307 SyncBackendRegistrar* registrar;
305 syncer::ModelSafeRoutingInfo routing_info; 308 syncer::ModelSafeRoutingInfo routing_info;
306 std::vector<syncer::ModelSafeWorker*> workers; 309 std::vector<syncer::ModelSafeWorker*> workers;
307 syncer::ExtensionsActivityMonitor* extensions_activity_monitor; 310 syncer::ExtensionsActivityMonitor* extensions_activity_monitor;
308 syncer::WeakHandle<syncer::JsEventHandler> event_handler; 311 syncer::WeakHandle<syncer::JsEventHandler> event_handler;
309 GURL service_url; 312 GURL service_url;
310 // Overridden by tests. 313 // Overridden by tests.
311 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn; 314 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn;
312 syncer::SyncCredentials credentials; 315 syncer::SyncCredentials credentials;
313 ChromeSyncNotificationBridge* const chrome_sync_notification_bridge; 316 ChromeSyncNotificationBridge* const chrome_sync_notification_bridge;
314 syncer::SyncNotifierFactory* const sync_notifier_factory; 317 syncer::SyncNotifierFactory* const sync_notifier_factory;
318 syncer::SyncManagerFactory* const sync_manager_factory;
315 std::string lsid; 319 std::string lsid;
316 bool delete_sync_data_folder; 320 bool delete_sync_data_folder;
317 std::string restored_key_for_bootstrapping; 321 std::string restored_key_for_bootstrapping;
318 syncer::SyncManager::TestingMode testing_mode; 322 syncer::SyncManager::TestingMode testing_mode;
319 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler; 323 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler;
320 syncer::ReportUnrecoverableErrorFunction 324 syncer::ReportUnrecoverableErrorFunction
321 report_unrecoverable_error_function; 325 report_unrecoverable_error_function;
322 }; 326 };
323 327
328 // Allow derived classes to start the sync thread early.
329 // Returns true on success, false otherwise. If the thread was already
330 // running, does nothing and returns true.
331 bool StartSyncThread();
332
333 // Getter for derived classes. May be NULL if the thread is not running.
334 MessageLoop* sync_loop() const { return sync_thread_.message_loop(); }
335
324 // Allows tests to perform alternate core initialization work. 336 // Allows tests to perform alternate core initialization work.
325 virtual void InitCore(const DoInitializeOptions& options); 337 virtual void InitCore(const DoInitializeOptions& options);
326 338
327 // Request the syncer to reconfigure with the specfied params. 339 // Request the syncer to reconfigure with the specfied params.
328 // Virtual for testing. 340 // Virtual for testing.
329 virtual void RequestConfigureSyncer( 341 virtual void RequestConfigureSyncer(
330 syncer::ConfigureReason reason, 342 syncer::ConfigureReason reason,
331 syncer::ModelTypeSet types_to_config, 343 syncer::ModelTypeSet types_to_config,
332 const syncer::ModelSafeRoutingInfo& routing_info, 344 const syncer::ModelSafeRoutingInfo& routing_info,
333 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, 345 const base::Callback<void(syncer::ModelTypeSet)>& ready_task,
334 const base::Closure& retry_callback); 346 const base::Closure& retry_callback);
335 347
336 // Called when the syncer has finished performing a configuration. 348 // Called when the syncer has finished performing a configuration.
337 void FinishConfigureDataTypesOnFrontendLoop( 349 void FinishConfigureDataTypesOnFrontendLoop(
338 const syncer::ModelTypeSet types_to_configure, 350 const syncer::ModelTypeSet types_to_configure,
339 const syncer::ModelTypeSet configured_types, 351 const syncer::ModelTypeSet configured_types,
340 const base::Callback<void(syncer::ModelTypeSet)>& ready_task); 352 const base::Callback<void(syncer::ModelTypeSet)>& ready_task);
353
354 private:
Nicolas Zea 2012/07/09 18:40:45 FYI this fell out in my rebase.
341 // The real guts of SyncBackendHost, to keep the public client API clean. 355 // The real guts of SyncBackendHost, to keep the public client API clean.
342 class Core; 356 class Core;
343 357
344 // An enum representing the steps to initializing the SyncBackendHost. 358 // An enum representing the steps to initializing the SyncBackendHost.
345 enum InitializationState { 359 enum InitializationState {
346 NOT_ATTEMPTED, 360 NOT_ATTEMPTED,
347 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the 361 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the
348 // sync thread to inform us that the sync manager 362 // sync thread to inform us that the sync manager
349 // has been created. 363 // has been created.
350 NOT_INITIALIZED, // Initialization hasn't completed, but we've 364 NOT_INITIALIZED, // Initialization hasn't completed, but we've
351 // constructed a SyncManager. 365 // constructed a SyncManager.
366 CLEANING_NIGORI, // A partially downloaded nigori was found. We
367 // perform a configuration cycle to blow it away.
352 DOWNLOADING_NIGORI, // The SyncManager is initialized, but 368 DOWNLOADING_NIGORI, // The SyncManager is initialized, but
353 // we're fetching encryption information. 369 // we're fetching encryption information.
354 REFRESHING_NIGORI, // The SyncManager is initialized, and we 370 REFRESHING_NIGORI, // The SyncManager is initialized, and we
355 // have the encryption information, but we 371 // have the encryption information, but we
356 // still need to refresh encryption. Also, we need 372 // still need to refresh encryption. Also, we need
357 // to update the device information in the nigori. 373 // to update the device information in the nigori.
358 INITIALIZED, // Initialization is complete. 374 INITIALIZED, // Initialization is complete.
359 }; 375 };
360 376
377 // InitializationComplete passes through the SyncBackendHost to forward
378 // on to |frontend_|, and so that tests can intercept here if they need to
379 // set up initial conditions.
380 void HandleInitializationCompletedOnFrontendLoop(
381 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
382 bool success);
383
361 // Checks if we have received a notice to turn on experimental datatypes 384 // Checks if we have received a notice to turn on experimental datatypes
362 // (via the nigori node) and informs the frontend if that is the case. 385 // (via the nigori node) and informs the frontend if that is the case.
363 // Note: it is illegal to call this before the backend is initialized. 386 // Note: it is illegal to call this before the backend is initialized.
364 void AddExperimentalTypes(); 387 void AddExperimentalTypes();
365 388
366 // Downloading of nigori failed and will be retried. 389 // Downloading of nigori failed and will be retried.
367 void OnNigoriDownloadRetry(); 390 void OnNigoriDownloadRetry();
368 391
369 // InitializationComplete passes through the SyncBackendHost to forward
370 // on to |frontend_|, and so that tests can intercept here if they need to
371 // set up initial conditions.
372 void HandleInitializationCompletedOnFrontendLoop(
373 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
374 bool success);
375
376 // Called from Core::OnSyncCycleCompleted to handle updating frontend 392 // Called from Core::OnSyncCycleCompleted to handle updating frontend
377 // thread components. 393 // thread components.
378 void HandleSyncCycleCompletedOnFrontendLoop( 394 void HandleSyncCycleCompletedOnFrontendLoop(
379 const syncer::sessions::SyncSessionSnapshot& snapshot); 395 const syncer::sessions::SyncSessionSnapshot& snapshot);
380 396
381 // Called when the syncer failed to perform a configuration and will 397 // Called when the syncer failed to perform a configuration and will
382 // eventually retry. FinishingConfigurationOnFrontendLoop(..) will be called 398 // eventually retry. FinishingConfigurationOnFrontendLoop(..) will be called
383 // on successful completion. 399 // on successful completion.
384 void RetryConfigurationOnFrontendLoop(const base::Closure& retry_callback); 400 void RetryConfigurationOnFrontendLoop(const base::Closure& retry_callback);
385 401
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 510
495 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. 511 // UI-thread cache of the last SyncSessionSnapshot received from syncapi.
496 syncer::sessions::SyncSessionSnapshot last_snapshot_; 512 syncer::sessions::SyncSessionSnapshot last_snapshot_;
497 513
498 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); 514 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost);
499 }; 515 };
500 516
501 } // namespace browser_sync 517 } // namespace browser_sync
502 518
503 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ 519 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/glue/sync_backend_host.cc » ('j') | chrome/browser/sync/glue/sync_backend_host.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698