| 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 #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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" | 19 #include "base/threading/sequenced_worker_pool.h" |
| 20 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
| 21 #include "base/timer.h" | 21 #include "base/timer.h" |
| 22 #include "base/tracked_objects.h" | 22 #include "base/tracked_objects.h" |
| 23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/signin/token_service.h" | 25 #include "chrome/browser/signin/token_service.h" |
| 26 #include "chrome/browser/sync/glue/bridged_sync_notifier.h" | 26 #include "chrome/browser/sync/glue/bridged_sync_notifier.h" |
| 27 #include "chrome/browser/sync/glue/change_processor.h" | 27 #include "chrome/browser/sync/glue/change_processor.h" |
| 28 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 28 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
| 29 #include "chrome/browser/sync/glue/http_bridge.h" | |
| 30 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 29 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
| 31 #include "chrome/browser/sync/invalidations/invalidator_storage.h" | 30 #include "chrome/browser/sync/invalidations/invalidator_storage.h" |
| 32 #include "chrome/browser/sync/sync_prefs.h" | 31 #include "chrome/browser/sync/sync_prefs.h" |
| 33 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
| 34 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/chrome_version_info.h" | 34 #include "chrome/common/chrome_version_info.h" |
| 36 #include "chrome/common/net/gaia/gaia_constants.h" | 35 #include "chrome/common/net/gaia/gaia_constants.h" |
| 37 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 39 #include "content/public/common/content_client.h" | 38 #include "content/public/common/content_client.h" |
| 40 #include "jingle/notifier/base/notification_method.h" | 39 #include "jingle/notifier/base/notification_method.h" |
| 41 #include "jingle/notifier/base/notifier_options.h" | 40 #include "jingle/notifier/base/notifier_options.h" |
| 42 #include "net/base/host_port_pair.h" | 41 #include "net/base/host_port_pair.h" |
| 43 #include "net/url_request/url_request_context_getter.h" | 42 #include "net/url_request/url_request_context_getter.h" |
| 44 #include "sync/internal_api/public/base_transaction.h" | 43 #include "sync/internal_api/public/base_transaction.h" |
| 45 #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" |
| 46 #include "sync/internal_api/public/read_transaction.h" | 46 #include "sync/internal_api/public/read_transaction.h" |
| 47 #include "sync/internal_api/public/util/experiments.h" | 47 #include "sync/internal_api/public/util/experiments.h" |
| 48 #include "sync/notifier/sync_notifier.h" | 48 #include "sync/notifier/sync_notifier.h" |
| 49 #include "sync/protocol/encryption.pb.h" | 49 #include "sync/protocol/encryption.pb.h" |
| 50 #include "sync/protocol/sync.pb.h" | 50 #include "sync/protocol/sync.pb.h" |
| 51 #include "sync/util/nigori.h" | 51 #include "sync/util/nigori.h" |
| 52 | 52 |
| 53 static const int kSaveChangesIntervalSeconds = 10; | 53 static const int kSaveChangesIntervalSeconds = 10; |
| 54 static const FilePath::CharType kSyncDataFolderName[] = | 54 static const FilePath::CharType kSyncDataFolderName[] = |
| 55 FILE_PATH_LITERAL("Sync Data"); | 55 FILE_PATH_LITERAL("Sync Data"); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 frontend_(NULL) { | 316 frontend_(NULL) { |
| 317 } | 317 } |
| 318 | 318 |
| 319 SyncBackendHost::~SyncBackendHost() { | 319 SyncBackendHost::~SyncBackendHost() { |
| 320 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; | 320 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
| 321 DCHECK(!registrar_.get()); | 321 DCHECK(!registrar_.get()); |
| 322 } | 322 } |
| 323 | 323 |
| 324 namespace { | 324 namespace { |
| 325 | 325 |
| 326 // Helper to construct a user agent string (ASCII) suitable for use by |
| 327 // the syncapi for any HTTP communication. This string is used by the sync |
| 328 // backend for classifying client types when calculating statistics. |
| 329 std::string MakeUserAgentForSyncApi() { |
| 330 std::string user_agent; |
| 331 user_agent = "Chrome "; |
| 332 #if defined(OS_WIN) |
| 333 user_agent += "WIN "; |
| 334 #elif defined(OS_CHROMEOS) |
| 335 user_agent += "CROS "; |
| 336 #elif defined(OS_LINUX) |
| 337 user_agent += "LINUX "; |
| 338 #elif defined(OS_FREEBSD) |
| 339 user_agent += "FREEBSD "; |
| 340 #elif defined(OS_OPENBSD) |
| 341 user_agent += "OPENBSD "; |
| 342 #elif defined(OS_MACOSX) |
| 343 user_agent += "MAC "; |
| 344 #endif |
| 345 chrome::VersionInfo version_info; |
| 346 if (!version_info.is_valid()) { |
| 347 DLOG(ERROR) << "Unable to create chrome::VersionInfo object"; |
| 348 return user_agent; |
| 349 } |
| 350 |
| 351 user_agent += version_info.Version(); |
| 352 user_agent += " (" + version_info.LastChange() + ")"; |
| 353 if (!version_info.IsOfficialBuild()) |
| 354 user_agent += "-devel"; |
| 355 return user_agent; |
| 356 } |
| 357 |
| 326 csync::HttpPostProviderFactory* MakeHttpBridgeFactory( | 358 csync::HttpPostProviderFactory* MakeHttpBridgeFactory( |
| 327 const scoped_refptr<net::URLRequestContextGetter>& getter) { | 359 const scoped_refptr<net::URLRequestContextGetter>& getter) { |
| 328 return new HttpBridgeFactory(getter); | 360 return new HttpBridgeFactory(getter, MakeUserAgentForSyncApi()); |
| 329 } | 361 } |
| 330 | 362 |
| 331 } // namespace | 363 } // namespace |
| 332 | 364 |
| 333 void SyncBackendHost::Initialize( | 365 void SyncBackendHost::Initialize( |
| 334 SyncFrontend* frontend, | 366 SyncFrontend* frontend, |
| 335 const csync::WeakHandle<csync::JsEventHandler>& event_handler, | 367 const csync::WeakHandle<csync::JsEventHandler>& event_handler, |
| 336 const GURL& sync_service_url, | 368 const GURL& sync_service_url, |
| 337 syncable::ModelTypeSet initial_types, | 369 syncable::ModelTypeSet initial_types, |
| 338 const SyncCredentials& credentials, | 370 const SyncCredentials& credentials, |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 const csync::SyncProtocolError& sync_error) { | 1037 const csync::SyncProtocolError& sync_error) { |
| 1006 if (!sync_loop_) | 1038 if (!sync_loop_) |
| 1007 return; | 1039 return; |
| 1008 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1040 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1009 host_.Call( | 1041 host_.Call( |
| 1010 FROM_HERE, | 1042 FROM_HERE, |
| 1011 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, | 1043 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, |
| 1012 sync_error); | 1044 sync_error); |
| 1013 } | 1045 } |
| 1014 | 1046 |
| 1015 // Helper to construct a user agent string (ASCII) suitable for use by | |
| 1016 // the syncapi for any HTTP communication. This string is used by the sync | |
| 1017 // backend for classifying client types when calculating statistics. | |
| 1018 std::string MakeUserAgentForSyncApi() { | |
| 1019 std::string user_agent; | |
| 1020 user_agent = "Chrome "; | |
| 1021 #if defined(OS_WIN) | |
| 1022 user_agent += "WIN "; | |
| 1023 #elif defined(OS_CHROMEOS) | |
| 1024 user_agent += "CROS "; | |
| 1025 #elif defined(OS_LINUX) | |
| 1026 user_agent += "LINUX "; | |
| 1027 #elif defined(OS_FREEBSD) | |
| 1028 user_agent += "FREEBSD "; | |
| 1029 #elif defined(OS_OPENBSD) | |
| 1030 user_agent += "OPENBSD "; | |
| 1031 #elif defined(OS_MACOSX) | |
| 1032 user_agent += "MAC "; | |
| 1033 #endif | |
| 1034 chrome::VersionInfo version_info; | |
| 1035 if (!version_info.is_valid()) { | |
| 1036 DLOG(ERROR) << "Unable to create chrome::VersionInfo object"; | |
| 1037 return user_agent; | |
| 1038 } | |
| 1039 | |
| 1040 user_agent += version_info.Version(); | |
| 1041 user_agent += " (" + version_info.LastChange() + ")"; | |
| 1042 if (!version_info.IsOfficialBuild()) | |
| 1043 user_agent += "-devel"; | |
| 1044 return user_agent; | |
| 1045 } | |
| 1046 | |
| 1047 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { | 1047 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { |
| 1048 DCHECK(!sync_loop_); | 1048 DCHECK(!sync_loop_); |
| 1049 sync_loop_ = options.sync_loop; | 1049 sync_loop_ = options.sync_loop; |
| 1050 DCHECK(sync_loop_); | 1050 DCHECK(sync_loop_); |
| 1051 | 1051 |
| 1052 // Blow away the partial or corrupt sync data folder before doing any more | 1052 // Blow away the partial or corrupt sync data folder before doing any more |
| 1053 // initialization, if necessary. | 1053 // initialization, if necessary. |
| 1054 if (options.delete_sync_data_folder) { | 1054 if (options.delete_sync_data_folder) { |
| 1055 DeleteSyncDataFolder(); | 1055 DeleteSyncDataFolder(); |
| 1056 } | 1056 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1071 options.event_handler, | 1071 options.event_handler, |
| 1072 options.service_url.host() + options.service_url.path(), | 1072 options.service_url.host() + options.service_url.path(), |
| 1073 options.service_url.EffectiveIntPort(), | 1073 options.service_url.EffectiveIntPort(), |
| 1074 options.service_url.SchemeIsSecure(), | 1074 options.service_url.SchemeIsSecure(), |
| 1075 BrowserThread::GetBlockingPool(), | 1075 BrowserThread::GetBlockingPool(), |
| 1076 options.make_http_bridge_factory_fn.Run(), | 1076 options.make_http_bridge_factory_fn.Run(), |
| 1077 options.routing_info, | 1077 options.routing_info, |
| 1078 options.workers, | 1078 options.workers, |
| 1079 options.extensions_activity_monitor, | 1079 options.extensions_activity_monitor, |
| 1080 options.registrar /* as SyncManager::ChangeDelegate */, | 1080 options.registrar /* as SyncManager::ChangeDelegate */, |
| 1081 MakeUserAgentForSyncApi(), | |
| 1082 options.credentials, | 1081 options.credentials, |
| 1083 new BridgedSyncNotifier( | 1082 new BridgedSyncNotifier( |
| 1084 options.chrome_sync_notification_bridge, | 1083 options.chrome_sync_notification_bridge, |
| 1085 options.sync_notifier_factory->CreateSyncNotifier()), | 1084 options.sync_notifier_factory->CreateSyncNotifier()), |
| 1086 options.restored_key_for_bootstrapping, | 1085 options.restored_key_for_bootstrapping, |
| 1087 options.testing_mode, | 1086 options.testing_mode, |
| 1088 &encryptor_, | 1087 &encryptor_, |
| 1089 options.unrecoverable_error_handler, | 1088 options.unrecoverable_error_handler, |
| 1090 options.report_unrecoverable_error_function); | 1089 options.report_unrecoverable_error_function); |
| 1091 LOG_IF(ERROR, !success) << "Syncapi initialization failed!"; | 1090 LOG_IF(ERROR, !success) << "Syncapi initialization failed!"; |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 FROM_HERE, | 1425 FROM_HERE, |
| 1427 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, | 1426 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, |
| 1428 core_.get(), sync_thread_done_callback)); | 1427 core_.get(), sync_thread_done_callback)); |
| 1429 } | 1428 } |
| 1430 | 1429 |
| 1431 #undef SDVLOG | 1430 #undef SDVLOG |
| 1432 | 1431 |
| 1433 #undef SLOG | 1432 #undef SLOG |
| 1434 | 1433 |
| 1435 } // namespace browser_sync | 1434 } // namespace browser_sync |
| OLD | NEW |