OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/profile_sync_service.h" | 5 #include "chrome/browser/sync/profile_sync_service.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
16 #include "base/string16.h" | 16 #include "base/string16.h" |
17 #include "base/string_number_conversions.h" | |
18 #include "base/string_util.h" | |
19 #include "base/task.h" | 17 #include "base/task.h" |
20 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
21 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
22 #include "chrome/browser/browser_signin.h" | 20 #include "chrome/browser/browser_signin.h" |
23 #include "chrome/browser/history/history_types.h" | 21 #include "chrome/browser/history/history_types.h" |
24 #include "chrome/browser/net/gaia/token_service.h" | 22 #include "chrome/browser/net/gaia/token_service.h" |
25 #include "chrome/browser/platform_util.h" | 23 #include "chrome/browser/platform_util.h" |
26 #include "chrome/browser/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
27 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h" | 26 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h" |
29 #include "chrome/browser/sync/glue/change_processor.h" | 27 #include "chrome/browser/sync/glue/change_processor.h" |
30 #include "chrome/browser/sync/glue/data_type_controller.h" | 28 #include "chrome/browser/sync/glue/data_type_controller.h" |
31 #include "chrome/browser/sync/glue/data_type_manager.h" | 29 #include "chrome/browser/sync/glue/data_type_manager.h" |
32 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 30 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
33 #include "chrome/browser/sync/js_arg_list.h" | 31 #include "chrome/browser/sync/js_arg_list.h" |
34 #include "chrome/browser/sync/profile_sync_factory.h" | 32 #include "chrome/browser/sync/profile_sync_factory.h" |
35 #include "chrome/browser/sync/signin_manager.h" | 33 #include "chrome/browser/sync/signin_manager.h" |
36 #include "chrome/browser/sync/token_migrator.h" | 34 #include "chrome/browser/sync/token_migrator.h" |
37 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
38 #include "chrome/common/net/gaia/gaia_constants.h" | 36 #include "chrome/common/net/gaia/gaia_constants.h" |
39 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
40 #include "chrome/common/time_format.h" | 38 #include "chrome/common/time_format.h" |
41 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
42 #include "content/common/notification_details.h" | 40 #include "content/common/notification_details.h" |
43 #include "content/common/notification_source.h" | 41 #include "content/common/notification_source.h" |
44 #include "content/common/notification_type.h" | 42 #include "content/common/notification_type.h" |
45 #include "grit/chromium_strings.h" | 43 #include "grit/chromium_strings.h" |
46 #include "grit/generated_resources.h" | 44 #include "grit/generated_resources.h" |
47 #include "jingle/notifier/communicator/const_communicator.h" | |
48 #include "net/base/cookie_monster.h" | 45 #include "net/base/cookie_monster.h" |
49 #include "ui/base/l10n/l10n_util.h" | 46 #include "ui/base/l10n/l10n_util.h" |
50 | 47 |
51 using browser_sync::ChangeProcessor; | 48 using browser_sync::ChangeProcessor; |
52 using browser_sync::DataTypeController; | 49 using browser_sync::DataTypeController; |
53 using browser_sync::DataTypeManager; | 50 using browser_sync::DataTypeManager; |
54 using browser_sync::SyncBackendHost; | 51 using browser_sync::SyncBackendHost; |
55 using sync_api::SyncCredentials; | 52 using sync_api::SyncCredentials; |
56 | 53 |
57 typedef GoogleServiceAuthError AuthError; | 54 typedef GoogleServiceAuthError AuthError; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 252 } |
256 | 253 |
257 void ProfileSyncService::GetDataTypeControllerStates( | 254 void ProfileSyncService::GetDataTypeControllerStates( |
258 browser_sync::DataTypeController::StateMap* state_map) const { | 255 browser_sync::DataTypeController::StateMap* state_map) const { |
259 for (browser_sync::DataTypeController::TypeMap::const_iterator iter = | 256 for (browser_sync::DataTypeController::TypeMap::const_iterator iter = |
260 data_type_controllers_.begin(); iter != data_type_controllers_.end(); | 257 data_type_controllers_.begin(); iter != data_type_controllers_.end(); |
261 ++iter) | 258 ++iter) |
262 (*state_map)[iter->first] = iter->second.get()->state(); | 259 (*state_map)[iter->first] = iter->second.get()->state(); |
263 } | 260 } |
264 | 261 |
265 namespace { | |
266 | |
267 // TODO(akalin): Figure out whether this should be a method of | |
268 // HostPortPair. | |
269 net::HostPortPair StringToHostPortPair(const std::string& host_port_str, | |
270 uint16 default_port) { | |
271 std::string::size_type colon_index = host_port_str.find(':'); | |
272 if (colon_index == std::string::npos) { | |
273 return net::HostPortPair(host_port_str, default_port); | |
274 } | |
275 | |
276 std::string host = host_port_str.substr(0, colon_index); | |
277 std::string port_str = host_port_str.substr(colon_index + 1); | |
278 int port = default_port; | |
279 if (!base::StringToInt(port_str, &port) || | |
280 (port <= 0) || (port > kuint16max)) { | |
281 LOG(WARNING) << "Could not parse valid port from " << port_str | |
282 << "; using port " << default_port; | |
283 return net::HostPortPair(host, default_port); | |
284 } | |
285 | |
286 return net::HostPortPair(host, port); | |
287 } | |
288 | |
289 } // namespace | |
290 | |
291 void ProfileSyncService::InitSettings() { | 262 void ProfileSyncService::InitSettings() { |
292 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 263 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
293 | 264 |
294 // Override the sync server URL from the command-line, if sync server | 265 // Override the sync server URL from the command-line, if sync server |
295 // command-line argument exists. | 266 // command-line argument exists. |
296 if (command_line.HasSwitch(switches::kSyncServiceURL)) { | 267 if (command_line.HasSwitch(switches::kSyncServiceURL)) { |
297 std::string value(command_line.GetSwitchValueASCII( | 268 std::string value(command_line.GetSwitchValueASCII( |
298 switches::kSyncServiceURL)); | 269 switches::kSyncServiceURL)); |
299 if (!value.empty()) { | 270 if (!value.empty()) { |
300 GURL custom_sync_url(value); | 271 GURL custom_sync_url(value); |
301 if (custom_sync_url.is_valid()) { | 272 if (custom_sync_url.is_valid()) { |
302 sync_service_url_ = custom_sync_url; | 273 sync_service_url_ = custom_sync_url; |
303 } else { | 274 } else { |
304 LOG(WARNING) << "The following sync URL specified at the command-line " | 275 LOG(WARNING) << "The following sync URL specified at the command-line " |
305 << "is invalid: " << value; | 276 << "is invalid: " << value; |
306 } | 277 } |
307 } | 278 } |
308 } | 279 } |
309 | |
310 // Override the notification server host from the command-line, if provided. | |
311 if (command_line.HasSwitch(switches::kSyncNotificationHost)) { | |
312 std::string value(command_line.GetSwitchValueASCII( | |
313 switches::kSyncNotificationHost)); | |
314 if (!value.empty()) { | |
315 notifier_options_.xmpp_host_port = | |
316 StringToHostPortPair(value, notifier::kDefaultXmppPort); | |
317 } | |
318 VLOG(1) << "Using " << notifier_options_.xmpp_host_port.ToString() | |
319 << " for test sync notification server."; | |
320 } | |
321 | |
322 notifier_options_.try_ssltcp_first = | |
323 command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp); | |
324 if (notifier_options_.try_ssltcp_first) | |
325 VLOG(1) << "Trying SSL/TCP port before XMPP port for notifications."; | |
326 | |
327 notifier_options_.invalidate_xmpp_login = | |
328 command_line.HasSwitch(switches::kSyncInvalidateXmppLogin); | |
329 if (notifier_options_.invalidate_xmpp_login) { | |
330 VLOG(1) << "Invalidating sync XMPP login."; | |
331 } | |
332 | |
333 notifier_options_.allow_insecure_connection = | |
334 command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection); | |
335 if (notifier_options_.allow_insecure_connection) { | |
336 VLOG(1) << "Allowing insecure XMPP connections."; | |
337 } | |
338 | |
339 if (command_line.HasSwitch(switches::kSyncNotificationMethod)) { | |
340 const std::string notification_method_str( | |
341 command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod)); | |
342 notifier_options_.notification_method = | |
343 notifier::StringToNotificationMethod(notification_method_str); | |
344 } | |
345 } | 280 } |
346 | 281 |
347 void ProfileSyncService::RegisterPreferences() { | 282 void ProfileSyncService::RegisterPreferences() { |
348 PrefService* pref_service = profile_->GetPrefs(); | 283 PrefService* pref_service = profile_->GetPrefs(); |
349 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime)) | 284 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime)) |
350 return; | 285 return; |
351 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0); | 286 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0); |
352 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, false); | 287 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, false); |
353 pref_service->RegisterBooleanPref(prefs::kSyncSuppressStart, false); | 288 pref_service->RegisterBooleanPref(prefs::kSyncSuppressStart, false); |
354 pref_service->RegisterBooleanPref(prefs::kSyncCredentialsMigrated, false); | 289 pref_service->RegisterBooleanPref(prefs::kSyncCredentialsMigrated, false); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 GetPreferredDataTypes(&types); | 352 GetPreferredDataTypes(&types); |
418 } | 353 } |
419 | 354 |
420 SyncCredentials credentials = GetCredentials(); | 355 SyncCredentials credentials = GetCredentials(); |
421 | 356 |
422 backend_->Initialize(this, | 357 backend_->Initialize(this, |
423 sync_service_url_, | 358 sync_service_url_, |
424 types, | 359 types, |
425 profile_->GetRequestContext(), | 360 profile_->GetRequestContext(), |
426 credentials, | 361 credentials, |
427 delete_sync_data_folder, | 362 delete_sync_data_folder); |
428 notifier_options_); | |
429 } | 363 } |
430 | 364 |
431 void ProfileSyncService::CreateBackend() { | 365 void ProfileSyncService::CreateBackend() { |
432 backend_.reset(new SyncBackendHost(profile_)); | 366 backend_.reset(new SyncBackendHost(profile_)); |
433 } | 367 } |
434 | 368 |
435 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { | 369 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { |
436 return !encrypted_types_.empty(); | 370 return !encrypted_types_.empty(); |
437 } | 371 } |
438 | 372 |
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 // is initialized, all enabled data types are consistent with one | 1286 // is initialized, all enabled data types are consistent with one |
1353 // another, and no unrecoverable error has transpired. | 1287 // another, and no unrecoverable error has transpired. |
1354 if (unrecoverable_error_detected_) | 1288 if (unrecoverable_error_detected_) |
1355 return false; | 1289 return false; |
1356 | 1290 |
1357 if (!data_type_manager_.get()) | 1291 if (!data_type_manager_.get()) |
1358 return false; | 1292 return false; |
1359 | 1293 |
1360 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1294 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
1361 } | 1295 } |
OLD | NEW |