| 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/internal_api/sync_manager.h" | 5 #include "chrome/browser/sync/internal_api/sync_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/command_line.h" |
| 11 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 12 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "chrome/browser/sync/engine/all_status.h" | 15 #include "chrome/browser/sync/engine/all_status.h" |
| 15 #include "chrome/browser/sync/engine/change_reorder_buffer.h" | 16 #include "chrome/browser/sync/engine/change_reorder_buffer.h" |
| 16 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 17 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 17 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" | 18 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" |
| 18 #include "chrome/browser/sync/engine/nigori_util.h" | 19 #include "chrome/browser/sync/engine/nigori_util.h" |
| 19 #include "chrome/browser/sync/engine/syncapi_internal.h" | 20 #include "chrome/browser/sync/engine/syncapi_internal.h" |
| 20 #include "chrome/browser/sync/engine/syncer_types.h" | 21 #include "chrome/browser/sync/engine/syncer_types.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 #include "chrome/browser/sync/js/js_transaction_observer.h" | 35 #include "chrome/browser/sync/js/js_transaction_observer.h" |
| 35 #include "chrome/browser/sync/notifier/sync_notifier.h" | 36 #include "chrome/browser/sync/notifier/sync_notifier.h" |
| 36 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" | 37 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" |
| 37 #include "chrome/browser/sync/protocol/proto_value_conversions.h" | 38 #include "chrome/browser/sync/protocol/proto_value_conversions.h" |
| 38 #include "chrome/browser/sync/syncable/directory_change_delegate.h" | 39 #include "chrome/browser/sync/syncable/directory_change_delegate.h" |
| 39 #include "chrome/browser/sync/syncable/directory_manager.h" | 40 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 40 #include "chrome/browser/sync/syncable/model_type.h" | 41 #include "chrome/browser/sync/syncable/model_type.h" |
| 41 #include "chrome/browser/sync/syncable/syncable.h" | 42 #include "chrome/browser/sync/syncable/syncable.h" |
| 42 #include "chrome/browser/sync/util/cryptographer.h" | 43 #include "chrome/browser/sync/util/cryptographer.h" |
| 43 #include "chrome/browser/sync/weak_handle.h" | 44 #include "chrome/browser/sync/weak_handle.h" |
| 45 #include "chrome/common/chrome_switches.h" |
| 44 #include "net/base/network_change_notifier.h" | 46 #include "net/base/network_change_notifier.h" |
| 45 | 47 |
| 46 using std::string; | 48 using std::string; |
| 47 using std::vector; | 49 using std::vector; |
| 48 | 50 |
| 49 using base::TimeDelta; | 51 using base::TimeDelta; |
| 50 using browser_sync::AllStatus; | 52 using browser_sync::AllStatus; |
| 51 using browser_sync::Cryptographer; | 53 using browser_sync::Cryptographer; |
| 52 using browser_sync::JsArgList; | 54 using browser_sync::JsArgList; |
| 53 using browser_sync::JsBackend; | 55 using browser_sync::JsBackend; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // and the sync DB is open. True if successful, false if something | 230 // and the sync DB is open. True if successful, false if something |
| 229 // went wrong. | 231 // went wrong. |
| 230 bool SignIn(const SyncCredentials& credentials); | 232 bool SignIn(const SyncCredentials& credentials); |
| 231 | 233 |
| 232 // Update tokens that we're using in Sync. Email must stay the same. | 234 // Update tokens that we're using in Sync. Email must stay the same. |
| 233 void UpdateCredentials(const SyncCredentials& credentials); | 235 void UpdateCredentials(const SyncCredentials& credentials); |
| 234 | 236 |
| 235 // Called when the user disables or enables a sync type. | 237 // Called when the user disables or enables a sync type. |
| 236 void UpdateEnabledTypes(); | 238 void UpdateEnabledTypes(); |
| 237 | 239 |
| 240 // Conditionally sets the flag in the Nigori node which instructs other |
| 241 // clients to start syncing tabs. |
| 242 void MaybeSetSyncTabsInNigoriNode(const syncable::ModelTypeSet enabled_types); |
| 243 |
| 238 // Tell the sync engine to start the syncing process. | 244 // Tell the sync engine to start the syncing process. |
| 239 void StartSyncingNormally(); | 245 void StartSyncingNormally(); |
| 240 | 246 |
| 241 // Whether or not the Nigori node is encrypted using an explicit passphrase. | 247 // Whether or not the Nigori node is encrypted using an explicit passphrase. |
| 242 bool IsUsingExplicitPassphrase(); | 248 bool IsUsingExplicitPassphrase(); |
| 243 | 249 |
| 244 // Update the Cryptographer from the current nigori node. | 250 // Update the Cryptographer from the current nigori node. |
| 245 // Note: opens a transaction and can trigger an ON_PASSPHRASE_REQUIRED, so | 251 // Note: opens a transaction and can trigger an ON_PASSPHRASE_REQUIRED, so |
| 246 // should only be called after syncapi is fully initialized. | 252 // should only be called after syncapi is fully initialized. |
| 247 // Returns true if cryptographer is ready, false otherwise. | 253 // Returns true if cryptographer is ready, false otherwise. |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 } | 655 } |
| 650 | 656 |
| 651 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) { | 657 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) { |
| 652 data_->UpdateCredentials(credentials); | 658 data_->UpdateCredentials(credentials); |
| 653 } | 659 } |
| 654 | 660 |
| 655 void SyncManager::UpdateEnabledTypes() { | 661 void SyncManager::UpdateEnabledTypes() { |
| 656 data_->UpdateEnabledTypes(); | 662 data_->UpdateEnabledTypes(); |
| 657 } | 663 } |
| 658 | 664 |
| 665 void SyncManager::MaybeSetSyncTabsInNigoriNode( |
| 666 const syncable::ModelTypeSet enabled_types) { |
| 667 data_->MaybeSetSyncTabsInNigoriNode(enabled_types); |
| 668 } |
| 669 |
| 659 bool SyncManager::InitialSyncEndedForAllEnabledTypes() { | 670 bool SyncManager::InitialSyncEndedForAllEnabledTypes() { |
| 660 return data_->InitialSyncEndedForAllEnabledTypes(); | 671 return data_->InitialSyncEndedForAllEnabledTypes(); |
| 661 } | 672 } |
| 662 | 673 |
| 663 void SyncManager::StartSyncingNormally() { | 674 void SyncManager::StartSyncingNormally() { |
| 664 data_->StartSyncingNormally(); | 675 data_->StartSyncingNormally(); |
| 665 } | 676 } |
| 666 | 677 |
| 667 void SyncManager::SetPassphrase(const std::string& passphrase, | 678 void SyncManager::SetPassphrase(const std::string& passphrase, |
| 668 bool is_explicit) { | 679 bool is_explicit) { |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 void SyncManager::SyncInternal::UpdateEnabledTypes() { | 946 void SyncManager::SyncInternal::UpdateEnabledTypes() { |
| 936 DCHECK(thread_checker_.CalledOnValidThread()); | 947 DCHECK(thread_checker_.CalledOnValidThread()); |
| 937 ModelSafeRoutingInfo routes; | 948 ModelSafeRoutingInfo routes; |
| 938 registrar_->GetModelSafeRoutingInfo(&routes); | 949 registrar_->GetModelSafeRoutingInfo(&routes); |
| 939 syncable::ModelTypeSet enabled_types; | 950 syncable::ModelTypeSet enabled_types; |
| 940 for (ModelSafeRoutingInfo::const_iterator it = routes.begin(); | 951 for (ModelSafeRoutingInfo::const_iterator it = routes.begin(); |
| 941 it != routes.end(); ++it) { | 952 it != routes.end(); ++it) { |
| 942 enabled_types.insert(it->first); | 953 enabled_types.insert(it->first); |
| 943 } | 954 } |
| 944 sync_notifier_->UpdateEnabledTypes(enabled_types); | 955 sync_notifier_->UpdateEnabledTypes(enabled_types); |
| 956 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 957 switches::kEnableSyncSessionsForOtherClients)) { |
| 958 MaybeSetSyncTabsInNigoriNode(enabled_types); |
| 959 } |
| 960 } |
| 961 |
| 962 void SyncManager::SyncInternal::MaybeSetSyncTabsInNigoriNode( |
| 963 const syncable::ModelTypeSet enabled_types) { |
| 964 if (enabled_types.count(syncable::SESSIONS) > 0) { |
| 965 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 966 WriteNode node(&trans); |
| 967 if (!node.InitByTagLookup(kNigoriTag)) { |
| 968 NOTREACHED() << "Unable to set 'sync_tabs' bit because Nigori node not " |
| 969 << "found."; |
| 970 return; |
| 971 } |
| 972 |
| 973 sync_pb::NigoriSpecifics specifics(node.GetNigoriSpecifics()); |
| 974 specifics.set_sync_tabs(true); |
| 975 node.SetNigoriSpecifics(specifics); |
| 976 } |
| 945 } | 977 } |
| 946 | 978 |
| 947 void SyncManager::SyncInternal::RaiseAuthNeededEvent() { | 979 void SyncManager::SyncInternal::RaiseAuthNeededEvent() { |
| 948 ObserverList<SyncManager::Observer> temp_obs_list; | 980 ObserverList<SyncManager::Observer> temp_obs_list; |
| 949 CopyObservers(&temp_obs_list); | 981 CopyObservers(&temp_obs_list); |
| 950 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, | 982 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
| 951 OnAuthError(AuthError(AuthError::INVALID_GAIA_CREDENTIALS))); | 983 OnAuthError(AuthError(AuthError::INVALID_GAIA_CREDENTIALS))); |
| 952 } | 984 } |
| 953 | 985 |
| 954 void SyncManager::SyncInternal::SetPassphrase( | 986 void SyncManager::SyncInternal::SetPassphrase( |
| (...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2053 | 2085 |
| 2054 for (syncable::ModelTypeSet::const_iterator i = types.begin(); | 2086 for (syncable::ModelTypeSet::const_iterator i = types.begin(); |
| 2055 i != types.end(); ++i) { | 2087 i != types.end(); ++i) { |
| 2056 if (!lookup->initial_sync_ended_for_type(*i)) | 2088 if (!lookup->initial_sync_ended_for_type(*i)) |
| 2057 return false; | 2089 return false; |
| 2058 } | 2090 } |
| 2059 return true; | 2091 return true; |
| 2060 } | 2092 } |
| 2061 | 2093 |
| 2062 } // namespace sync_api | 2094 } // namespace sync_api |
| OLD | NEW |