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

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

Issue 10704214: [Sync] Refactor sync manager into interface. (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 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/sync/glue/sync_backend_host.h" 7 #include "chrome/browser/sync/glue/sync_backend_host.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 26 matching lines...) Expand all
37 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
38 #include "content/public/common/content_client.h" 38 #include "content/public/common/content_client.h"
39 #include "jingle/notifier/base/notification_method.h" 39 #include "jingle/notifier/base/notification_method.h"
40 #include "jingle/notifier/base/notifier_options.h" 40 #include "jingle/notifier/base/notifier_options.h"
41 #include "net/base/host_port_pair.h" 41 #include "net/base/host_port_pair.h"
42 #include "net/url_request/url_request_context_getter.h" 42 #include "net/url_request/url_request_context_getter.h"
43 #include "sync/internal_api/public/base_transaction.h" 43 #include "sync/internal_api/public/base_transaction.h"
44 #include "sync/internal_api/public/engine/model_safe_worker.h" 44 #include "sync/internal_api/public/engine/model_safe_worker.h"
45 #include "sync/internal_api/public/http_bridge.h" 45 #include "sync/internal_api/public/http_bridge.h"
46 #include "sync/internal_api/public/read_transaction.h" 46 #include "sync/internal_api/public/read_transaction.h"
47 #include "sync/internal_api/public/sync_manager_factory.h"
47 #include "sync/internal_api/public/util/experiments.h" 48 #include "sync/internal_api/public/util/experiments.h"
48 #include "sync/notifier/sync_notifier.h" 49 #include "sync/notifier/sync_notifier.h"
49 #include "sync/protocol/encryption.pb.h" 50 #include "sync/protocol/encryption.pb.h"
50 #include "sync/protocol/sync.pb.h" 51 #include "sync/protocol/sync.pb.h"
51 #include "sync/util/nigori.h" 52 #include "sync/util/nigori.h"
52 53
53 static const int kSaveChangesIntervalSeconds = 10; 54 static const int kSaveChangesIntervalSeconds = 10;
54 static const FilePath::CharType kSyncDataFolderName[] = 55 static const FilePath::CharType kSyncDataFolderName[] =
55 FILE_PATH_LITERAL("Sync Data"); 56 FILE_PATH_LITERAL("Sync Data");
56 57
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 return user_agent; 346 return user_agent;
346 } 347 }
347 348
348 user_agent += version_info.Version(); 349 user_agent += version_info.Version();
349 user_agent += " (" + version_info.LastChange() + ")"; 350 user_agent += " (" + version_info.LastChange() + ")";
350 if (!version_info.IsOfficialBuild()) 351 if (!version_info.IsOfficialBuild())
351 user_agent += "-devel"; 352 user_agent += "-devel";
352 return user_agent; 353 return user_agent;
353 } 354 }
354 355
355 syncer::HttpPostProviderFactory* MakeHttpBridgeFactory( 356 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory(
356 const scoped_refptr<net::URLRequestContextGetter>& getter) { 357 const scoped_refptr<net::URLRequestContextGetter>& getter) {
357 return new syncer::HttpBridgeFactory(getter, MakeUserAgentForSyncApi()); 358 return scoped_ptr<syncer::HttpPostProviderFactory>(
359 new syncer::HttpBridgeFactory(getter, MakeUserAgentForSyncApi()));
358 } 360 }
359 361
360 } // namespace 362 } // namespace
361 363
362 void SyncBackendHost::Initialize( 364 void SyncBackendHost::Initialize(
363 SyncFrontend* frontend, 365 SyncFrontend* frontend,
364 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 366 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
365 const GURL& sync_service_url, 367 const GURL& sync_service_url,
366 syncer::ModelTypeSet initial_types, 368 syncer::ModelTypeSet initial_types,
367 const SyncCredentials& credentials, 369 const SyncCredentials& credentials,
368 bool delete_sync_data_folder, 370 bool delete_sync_data_folder,
371 syncer::SyncManagerFactory* sync_manager_factory,
369 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, 372 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
370 syncer::ReportUnrecoverableErrorFunction 373 syncer::ReportUnrecoverableErrorFunction
371 report_unrecoverable_error_function) { 374 report_unrecoverable_error_function) {
372 if (!sync_thread_.Start()) 375 if (!sync_thread_.Start())
373 return; 376 return;
374 377
375 frontend_ = frontend; 378 frontend_ = frontend;
376 DCHECK(frontend); 379 DCHECK(frontend);
377 380
378 syncer::ModelTypeSet initial_types_with_nigori(initial_types); 381 syncer::ModelTypeSet initial_types_with_nigori(initial_types);
(...skipping 18 matching lines...) Expand all
397 routing_info, 400 routing_info,
398 workers, 401 workers,
399 &extensions_activity_monitor_, 402 &extensions_activity_monitor_,
400 event_handler, 403 event_handler,
401 sync_service_url, 404 sync_service_url,
402 base::Bind(&MakeHttpBridgeFactory, 405 base::Bind(&MakeHttpBridgeFactory,
403 make_scoped_refptr(profile_->GetRequestContext())), 406 make_scoped_refptr(profile_->GetRequestContext())),
404 credentials, 407 credentials,
405 &chrome_sync_notification_bridge_, 408 &chrome_sync_notification_bridge_,
406 &sync_notifier_factory_, 409 &sync_notifier_factory_,
410 sync_manager_factory,
407 delete_sync_data_folder, 411 delete_sync_data_folder,
408 sync_prefs_->GetEncryptionBootstrapToken(), 412 sync_prefs_->GetEncryptionBootstrapToken(),
409 syncer::SyncManager::NON_TEST, 413 syncer::SyncManager::NON_TEST,
410 unrecoverable_error_handler, 414 unrecoverable_error_handler,
411 report_unrecoverable_error_function)); 415 report_unrecoverable_error_function));
412 } 416 }
413 417
414 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { 418 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) {
415 sync_thread_.message_loop()->PostTask(FROM_HERE, 419 sync_thread_.message_loop()->PostTask(FROM_HERE,
416 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), 420 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(),
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 syncer::ModelTypeSet types_to_add_with_nigori = types_to_add; 595 syncer::ModelTypeSet types_to_add_with_nigori = types_to_add;
592 syncer::ModelTypeSet types_to_remove_with_nigori = types_to_remove; 596 syncer::ModelTypeSet types_to_remove_with_nigori = types_to_remove;
593 if (nigori_state == WITH_NIGORI) { 597 if (nigori_state == WITH_NIGORI) {
594 types_to_add_with_nigori.Put(syncer::NIGORI); 598 types_to_add_with_nigori.Put(syncer::NIGORI);
595 types_to_remove_with_nigori.Remove(syncer::NIGORI); 599 types_to_remove_with_nigori.Remove(syncer::NIGORI);
596 } else { 600 } else {
597 types_to_add_with_nigori.Remove(syncer::NIGORI); 601 types_to_add_with_nigori.Remove(syncer::NIGORI);
598 types_to_remove_with_nigori.Put(syncer::NIGORI); 602 types_to_remove_with_nigori.Put(syncer::NIGORI);
599 } 603 }
600 // Only one configure is allowed at a time (DataTypeManager handles user 604 // Only one configure is allowed at a time (DataTypeManager handles user
601 // changes that happen while the syncer is reconfiguraing, and will only 605 // changes that happen while the syncer is reconfiguring, and will only
602 // trigger another call to ConfigureDataTypes once the current reconfiguration 606 // trigger another call to ConfigureDataTypes once the current reconfiguration
603 // completes). 607 // completes).
604 DCHECK_GT(initialization_state_, NOT_INITIALIZED); 608 DCHECK_GT(initialization_state_, NOT_INITIALIZED);
605 609
606 // The new set of enabled types is types_to_add_with_nigori + the 610 // The new set of enabled types is types_to_add_with_nigori + the
607 // previously enabled types (on restart, the preferred types are already 611 // previously enabled types (on restart, the preferred types are already
608 // enabled) - types_to_remove_with_nigori. After reconfiguring the registrar, 612 // enabled) - types_to_remove_with_nigori. After reconfiguring the registrar,
609 // the new routing info will reflect the set of enabled types. 613 // the new routing info will reflect the set of enabled types.
610 syncer::ModelSafeRoutingInfo routing_info; 614 syncer::ModelSafeRoutingInfo routing_info;
611 registrar_->ConfigureDataTypes(types_to_add_with_nigori, 615 registrar_->ConfigureDataTypes(types_to_add_with_nigori,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 SyncBackendRegistrar* registrar, 769 SyncBackendRegistrar* registrar,
766 const syncer::ModelSafeRoutingInfo& routing_info, 770 const syncer::ModelSafeRoutingInfo& routing_info,
767 const std::vector<syncer::ModelSafeWorker*>& workers, 771 const std::vector<syncer::ModelSafeWorker*>& workers,
768 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 772 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
769 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 773 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
770 const GURL& service_url, 774 const GURL& service_url,
771 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, 775 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn,
772 const syncer::SyncCredentials& credentials, 776 const syncer::SyncCredentials& credentials,
773 ChromeSyncNotificationBridge* chrome_sync_notification_bridge, 777 ChromeSyncNotificationBridge* chrome_sync_notification_bridge,
774 syncer::SyncNotifierFactory* sync_notifier_factory, 778 syncer::SyncNotifierFactory* sync_notifier_factory,
779 syncer::SyncManagerFactory* sync_manager_factory,
775 bool delete_sync_data_folder, 780 bool delete_sync_data_folder,
776 const std::string& restored_key_for_bootstrapping, 781 const std::string& restored_key_for_bootstrapping,
777 syncer::SyncManager::TestingMode testing_mode, 782 syncer::SyncManager::TestingMode testing_mode,
778 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, 783 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
779 syncer::ReportUnrecoverableErrorFunction 784 syncer::ReportUnrecoverableErrorFunction
780 report_unrecoverable_error_function) 785 report_unrecoverable_error_function)
781 : sync_loop(sync_loop), 786 : sync_loop(sync_loop),
782 registrar(registrar), 787 registrar(registrar),
783 routing_info(routing_info), 788 routing_info(routing_info),
784 workers(workers), 789 workers(workers),
785 extensions_activity_monitor(extensions_activity_monitor), 790 extensions_activity_monitor(extensions_activity_monitor),
786 event_handler(event_handler), 791 event_handler(event_handler),
787 service_url(service_url), 792 service_url(service_url),
788 make_http_bridge_factory_fn(make_http_bridge_factory_fn), 793 make_http_bridge_factory_fn(make_http_bridge_factory_fn),
789 credentials(credentials), 794 credentials(credentials),
790 chrome_sync_notification_bridge(chrome_sync_notification_bridge), 795 chrome_sync_notification_bridge(chrome_sync_notification_bridge),
791 sync_notifier_factory(sync_notifier_factory), 796 sync_notifier_factory(sync_notifier_factory),
797 sync_manager_factory(sync_manager_factory),
792 delete_sync_data_folder(delete_sync_data_folder), 798 delete_sync_data_folder(delete_sync_data_folder),
793 restored_key_for_bootstrapping(restored_key_for_bootstrapping), 799 restored_key_for_bootstrapping(restored_key_for_bootstrapping),
794 testing_mode(testing_mode), 800 testing_mode(testing_mode),
795 unrecoverable_error_handler(unrecoverable_error_handler), 801 unrecoverable_error_handler(unrecoverable_error_handler),
796 report_unrecoverable_error_function( 802 report_unrecoverable_error_function(
797 report_unrecoverable_error_function) { 803 report_unrecoverable_error_function) {
798 } 804 }
799 805
800 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} 806 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {}
801 807
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 954
949 // Make sure that the directory exists before initializing the backend. 955 // Make sure that the directory exists before initializing the backend.
950 // If it already exists, this will do no harm. 956 // If it already exists, this will do no harm.
951 bool success = file_util::CreateDirectory(sync_data_folder_path_); 957 bool success = file_util::CreateDirectory(sync_data_folder_path_);
952 DCHECK(success); 958 DCHECK(success);
953 959
954 DCHECK(!registrar_); 960 DCHECK(!registrar_);
955 registrar_ = options.registrar; 961 registrar_ = options.registrar;
956 DCHECK(registrar_); 962 DCHECK(registrar_);
957 963
958 sync_manager_.reset(new syncer::SyncManager(name_)); 964 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_);
959 sync_manager_->AddObserver(this); 965 sync_manager_->AddObserver(this);
960 success = sync_manager_->Init( 966 success = sync_manager_->Init(
961 sync_data_folder_path_, 967 sync_data_folder_path_,
962 options.event_handler, 968 options.event_handler,
963 options.service_url.host() + options.service_url.path(), 969 options.service_url.host() + options.service_url.path(),
964 options.service_url.EffectiveIntPort(), 970 options.service_url.EffectiveIntPort(),
965 options.service_url.SchemeIsSecure(), 971 options.service_url.SchemeIsSecure(),
966 BrowserThread::GetBlockingPool(), 972 BrowserThread::GetBlockingPool(),
967 options.make_http_bridge_factory_fn.Run(), 973 options.make_http_bridge_factory_fn.Run().Pass(),
tim (not reviewing) 2012/07/17 16:11:54 Ah ha.. I was wondering how this worked since Pass
968 options.routing_info, 974 options.routing_info,
969 options.workers, 975 options.workers,
970 options.extensions_activity_monitor, 976 options.extensions_activity_monitor,
971 options.registrar /* as SyncManager::ChangeDelegate */, 977 options.registrar /* as SyncManager::ChangeDelegate */,
972 options.credentials, 978 options.credentials,
973 new BridgedSyncNotifier( 979 scoped_ptr<syncer::SyncNotifier>(new BridgedSyncNotifier(
974 options.chrome_sync_notification_bridge, 980 options.chrome_sync_notification_bridge,
975 options.sync_notifier_factory->CreateSyncNotifier()), 981 options.sync_notifier_factory->CreateSyncNotifier())),
976 options.restored_key_for_bootstrapping, 982 options.restored_key_for_bootstrapping,
977 options.testing_mode, 983 options.testing_mode,
978 &encryptor_, 984 &encryptor_,
979 options.unrecoverable_error_handler, 985 options.unrecoverable_error_handler,
980 options.report_unrecoverable_error_function); 986 options.report_unrecoverable_error_function);
981 LOG_IF(ERROR, !success) << "Syncapi initialization failed!"; 987 LOG_IF(ERROR, !success) << "Syncapi initialization failed!";
982 988
983 // Now check the command line to see if we need to simulate an 989 // Now check the command line to see if we need to simulate an
984 // unrecoverable error for testing purpose. Note the error is thrown 990 // unrecoverable error for testing purpose. Note the error is thrown
985 // only if the initialization succeeded. Also it makes sense to use this 991 // only if the initialization succeeded. Also it makes sense to use this
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 FROM_HERE, 1367 FROM_HERE,
1362 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, 1368 base::Bind(&SyncBackendHost::Core::DoRefreshNigori,
1363 core_.get(), sync_thread_done_callback)); 1369 core_.get(), sync_thread_done_callback));
1364 } 1370 }
1365 1371
1366 #undef SDVLOG 1372 #undef SDVLOG
1367 1373
1368 #undef SLOG 1374 #undef SLOG
1369 1375
1370 } // namespace browser_sync 1376 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | chrome/browser/sync/glue/sync_backend_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698