| 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 "sync/internal_api/sync_manager_impl.h" | 5 #include "sync/internal_api/sync_manager_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | |
| 13 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 14 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 15 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 16 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 17 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 18 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
| 19 #include "base/values.h" | 18 #include "base/values.h" |
| 20 #include "sync/engine/sync_scheduler.h" | 19 #include "sync/engine/sync_scheduler.h" |
| 21 #include "sync/engine/syncer_types.h" | 20 #include "sync/engine/syncer_types.h" |
| 22 #include "sync/internal_api/change_reorder_buffer.h" | 21 #include "sync/internal_api/change_reorder_buffer.h" |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 ExtensionsActivityMonitor* extensions_activity_monitor, | 362 ExtensionsActivityMonitor* extensions_activity_monitor, |
| 364 SyncManager::ChangeDelegate* change_delegate, | 363 SyncManager::ChangeDelegate* change_delegate, |
| 365 const SyncCredentials& credentials, | 364 const SyncCredentials& credentials, |
| 366 scoped_ptr<Invalidator> invalidator, | 365 scoped_ptr<Invalidator> invalidator, |
| 367 const std::string& invalidator_client_id, | 366 const std::string& invalidator_client_id, |
| 368 const std::string& restored_key_for_bootstrapping, | 367 const std::string& restored_key_for_bootstrapping, |
| 369 const std::string& restored_keystore_key_for_bootstrapping, | 368 const std::string& restored_keystore_key_for_bootstrapping, |
| 370 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 369 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
| 371 Encryptor* encryptor, | 370 Encryptor* encryptor, |
| 372 UnrecoverableErrorHandler* unrecoverable_error_handler, | 371 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 373 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { | 372 ReportUnrecoverableErrorFunction report_unrecoverable_error_function, |
| 373 bool use_oauth2_token) { |
| 374 CHECK(!initialized_); | 374 CHECK(!initialized_); |
| 375 DCHECK(thread_checker_.CalledOnValidThread()); | 375 DCHECK(thread_checker_.CalledOnValidThread()); |
| 376 DCHECK(post_factory.get()); | 376 DCHECK(post_factory.get()); |
| 377 DCHECK(!credentials.email.empty()); | 377 DCHECK(!credentials.email.empty()); |
| 378 DCHECK(!credentials.sync_token.empty()); | 378 DCHECK(!credentials.sync_token.empty()); |
| 379 DVLOG(1) << "SyncManager starting Init..."; | 379 DVLOG(1) << "SyncManager starting Init..."; |
| 380 | 380 |
| 381 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); | 381 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); |
| 382 | 382 |
| 383 change_delegate_ = change_delegate; | 383 change_delegate_ = change_delegate; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 OnInitializationComplete( | 430 OnInitializationComplete( |
| 431 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 431 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
| 432 MakeWeakHandle( | 432 MakeWeakHandle( |
| 433 debug_info_event_listener_.GetWeakPtr()), | 433 debug_info_event_listener_.GetWeakPtr()), |
| 434 false, ModelTypeSet())); | 434 false, ModelTypeSet())); |
| 435 LOG(ERROR) << "Sync manager initialization failed!"; | 435 LOG(ERROR) << "Sync manager initialization failed!"; |
| 436 return; | 436 return; |
| 437 } | 437 } |
| 438 | 438 |
| 439 connection_manager_.reset(new SyncAPIServerConnectionManager( | 439 connection_manager_.reset(new SyncAPIServerConnectionManager( |
| 440 sync_server_and_path, port, use_ssl, post_factory.release())); | 440 sync_server_and_path, port, use_ssl, use_oauth2_token, |
| 441 post_factory.release())); |
| 441 connection_manager_->set_client_id(directory()->cache_guid()); | 442 connection_manager_->set_client_id(directory()->cache_guid()); |
| 442 connection_manager_->AddListener(this); | 443 connection_manager_->AddListener(this); |
| 443 | 444 |
| 444 std::string sync_id = directory()->cache_guid(); | 445 std::string sync_id = directory()->cache_guid(); |
| 445 | 446 |
| 446 allstatus_.SetSyncId(sync_id); | 447 allstatus_.SetSyncId(sync_id); |
| 447 allstatus_.SetInvalidatorClientId(invalidator_client_id); | 448 allstatus_.SetInvalidatorClientId(invalidator_client_id); |
| 448 | 449 |
| 449 DVLOG(1) << "Setting sync client ID: " << sync_id; | 450 DVLOG(1) << "Setting sync client ID: " << sync_id; |
| 450 DVLOG(1) << "Setting invalidator client ID: " << invalidator_client_id; | 451 DVLOG(1) << "Setting invalidator client ID: " << invalidator_client_id; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 to_unapply); | 619 to_unapply); |
| 619 } | 620 } |
| 620 | 621 |
| 621 void SyncManagerImpl::UpdateCredentials(const SyncCredentials& credentials) { | 622 void SyncManagerImpl::UpdateCredentials(const SyncCredentials& credentials) { |
| 622 DCHECK(thread_checker_.CalledOnValidThread()); | 623 DCHECK(thread_checker_.CalledOnValidThread()); |
| 623 DCHECK(initialized_); | 624 DCHECK(initialized_); |
| 624 DCHECK(!credentials.email.empty()); | 625 DCHECK(!credentials.email.empty()); |
| 625 DCHECK(!credentials.sync_token.empty()); | 626 DCHECK(!credentials.sync_token.empty()); |
| 626 | 627 |
| 627 observing_network_connectivity_changes_ = true; | 628 observing_network_connectivity_changes_ = true; |
| 628 if (!connection_manager_->SetAuthToken(credentials.sync_token, | 629 if (!connection_manager_->SetAuthToken(credentials.sync_token)) |
| 629 credentials.sync_token_time)) | |
| 630 return; // Auth token is known to be invalid, so exit early. | 630 return; // Auth token is known to be invalid, so exit early. |
| 631 | 631 |
| 632 invalidator_->UpdateCredentials(credentials.email, credentials.sync_token); | 632 invalidator_->UpdateCredentials(credentials.email, credentials.sync_token); |
| 633 scheduler_->OnCredentialsUpdated(); | 633 scheduler_->OnCredentialsUpdated(); |
| 634 | 634 |
| 635 // TODO(zea): pass the credential age to the debug info event listener. | 635 // TODO(zea): pass the credential age to the debug info event listener. |
| 636 } | 636 } |
| 637 | 637 |
| 638 void SyncManagerImpl::UpdateEnabledTypes(ModelTypeSet enabled_types) { | 638 void SyncManagerImpl::UpdateEnabledTypes(ModelTypeSet enabled_types) { |
| 639 DCHECK(thread_checker_.CalledOnValidThread()); | 639 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1417 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1417 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1418 return kDefaultNudgeDelayMilliseconds; | 1418 return kDefaultNudgeDelayMilliseconds; |
| 1419 } | 1419 } |
| 1420 | 1420 |
| 1421 // static. | 1421 // static. |
| 1422 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1422 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1423 return kPreferencesNudgeDelayMilliseconds; | 1423 return kPreferencesNudgeDelayMilliseconds; |
| 1424 } | 1424 } |
| 1425 | 1425 |
| 1426 } // namespace syncer | 1426 } // namespace syncer |
| OLD | NEW |