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

Side by Side Diff: chrome/browser/sync/internal_api/sync_manager.cc

Issue 7767013: Add logic to flip Nigori bit to instruct other clients to sync tabs. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fix CHECK on startup Created 9 years, 3 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) 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 14 matching lines...) Expand all
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/model_type_payload_map.h" 42 #include "chrome/browser/sync/syncable/model_type_payload_map.h"
42 #include "chrome/browser/sync/syncable/syncable.h" 43 #include "chrome/browser/sync/syncable/syncable.h"
43 #include "chrome/browser/sync/util/cryptographer.h" 44 #include "chrome/browser/sync/util/cryptographer.h"
44 #include "chrome/browser/sync/weak_handle.h" 45 #include "chrome/browser/sync/weak_handle.h"
46 #include "chrome/common/chrome_switches.h"
45 #include "net/base/network_change_notifier.h" 47 #include "net/base/network_change_notifier.h"
46 48
47 using std::string; 49 using std::string;
48 using std::vector; 50 using std::vector;
49 51
50 using base::TimeDelta; 52 using base::TimeDelta;
51 using browser_sync::AllStatus; 53 using browser_sync::AllStatus;
52 using browser_sync::Cryptographer; 54 using browser_sync::Cryptographer;
53 using browser_sync::JsArgList; 55 using browser_sync::JsArgList;
54 using browser_sync::JsBackend; 56 using browser_sync::JsBackend;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // and the sync DB is open. True if successful, false if something 231 // and the sync DB is open. True if successful, false if something
230 // went wrong. 232 // went wrong.
231 bool SignIn(const SyncCredentials& credentials); 233 bool SignIn(const SyncCredentials& credentials);
232 234
233 // Update tokens that we're using in Sync. Email must stay the same. 235 // Update tokens that we're using in Sync. Email must stay the same.
234 void UpdateCredentials(const SyncCredentials& credentials); 236 void UpdateCredentials(const SyncCredentials& credentials);
235 237
236 // Called when the user disables or enables a sync type. 238 // Called when the user disables or enables a sync type.
237 void UpdateEnabledTypes(); 239 void UpdateEnabledTypes();
238 240
241 // Conditionally sets the flag in the Nigori node which instructs other
242 // clients to start syncing tabs.
243 void MaybeSetSyncTabsInNigoriNode(const syncable::ModelTypeSet enabled_types);
244
239 // Tell the sync engine to start the syncing process. 245 // Tell the sync engine to start the syncing process.
240 void StartSyncingNormally(); 246 void StartSyncingNormally();
241 247
242 // Whether or not the Nigori node is encrypted using an explicit passphrase. 248 // Whether or not the Nigori node is encrypted using an explicit passphrase.
243 bool IsUsingExplicitPassphrase(); 249 bool IsUsingExplicitPassphrase();
244 250
245 // Update the Cryptographer from the current nigori node. 251 // Update the Cryptographer from the current nigori node.
246 // Note: opens a transaction and can trigger an ON_PASSPHRASE_REQUIRED, so 252 // Note: opens a transaction and can trigger an ON_PASSPHRASE_REQUIRED, so
247 // should only be called after syncapi is fully initialized. 253 // should only be called after syncapi is fully initialized.
248 // Returns true if cryptographer is ready, false otherwise. 254 // Returns true if cryptographer is ready, false otherwise.
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 } 656 }
651 657
652 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) { 658 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) {
653 data_->UpdateCredentials(credentials); 659 data_->UpdateCredentials(credentials);
654 } 660 }
655 661
656 void SyncManager::UpdateEnabledTypes() { 662 void SyncManager::UpdateEnabledTypes() {
657 data_->UpdateEnabledTypes(); 663 data_->UpdateEnabledTypes();
658 } 664 }
659 665
666 void SyncManager::MaybeSetSyncTabsInNigoriNode(
667 const syncable::ModelTypeSet enabled_types) {
668 data_->MaybeSetSyncTabsInNigoriNode(enabled_types);
669 }
670
660 bool SyncManager::InitialSyncEndedForAllEnabledTypes() { 671 bool SyncManager::InitialSyncEndedForAllEnabledTypes() {
661 return data_->InitialSyncEndedForAllEnabledTypes(); 672 return data_->InitialSyncEndedForAllEnabledTypes();
662 } 673 }
663 674
664 void SyncManager::StartSyncingNormally() { 675 void SyncManager::StartSyncingNormally() {
665 data_->StartSyncingNormally(); 676 data_->StartSyncingNormally();
666 } 677 }
667 678
668 void SyncManager::SetPassphrase(const std::string& passphrase, 679 void SyncManager::SetPassphrase(const std::string& passphrase,
669 bool is_explicit) { 680 bool is_explicit) {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 void SyncManager::SyncInternal::UpdateEnabledTypes() { 947 void SyncManager::SyncInternal::UpdateEnabledTypes() {
937 DCHECK(thread_checker_.CalledOnValidThread()); 948 DCHECK(thread_checker_.CalledOnValidThread());
938 ModelSafeRoutingInfo routes; 949 ModelSafeRoutingInfo routes;
939 registrar_->GetModelSafeRoutingInfo(&routes); 950 registrar_->GetModelSafeRoutingInfo(&routes);
940 syncable::ModelTypeSet enabled_types; 951 syncable::ModelTypeSet enabled_types;
941 for (ModelSafeRoutingInfo::const_iterator it = routes.begin(); 952 for (ModelSafeRoutingInfo::const_iterator it = routes.begin();
942 it != routes.end(); ++it) { 953 it != routes.end(); ++it) {
943 enabled_types.insert(it->first); 954 enabled_types.insert(it->first);
944 } 955 }
945 sync_notifier_->UpdateEnabledTypes(enabled_types); 956 sync_notifier_->UpdateEnabledTypes(enabled_types);
957 if (CommandLine::ForCurrentProcess()->HasSwitch(
958 switches::kEnableSyncSessionsForOtherClients)) {
959 MaybeSetSyncTabsInNigoriNode(enabled_types);
960 }
961 }
962
963 void SyncManager::SyncInternal::MaybeSetSyncTabsInNigoriNode(
964 const syncable::ModelTypeSet enabled_types) {
965 // The initialized_ check is to ensure that we don't CHECK in GetUserShare
966 // when this is called on start-up. It's ok to ignore that case, since
967 // presumably this would've run when the user originally enabled sessions.
968 if (initialized_ && enabled_types.count(syncable::SESSIONS) > 0) {
969 WriteTransaction trans(FROM_HERE, GetUserShare());
970 WriteNode node(&trans);
971 if (!node.InitByTagLookup(kNigoriTag)) {
972 NOTREACHED() << "Unable to set 'sync_tabs' bit because Nigori node not "
973 << "found.";
974 return;
975 }
976
977 sync_pb::NigoriSpecifics specifics(node.GetNigoriSpecifics());
978 specifics.set_sync_tabs(true);
979 node.SetNigoriSpecifics(specifics);
980 }
946 } 981 }
947 982
948 void SyncManager::SyncInternal::RaiseAuthNeededEvent() { 983 void SyncManager::SyncInternal::RaiseAuthNeededEvent() {
949 ObserverList<SyncManager::Observer> temp_obs_list; 984 ObserverList<SyncManager::Observer> temp_obs_list;
950 CopyObservers(&temp_obs_list); 985 CopyObservers(&temp_obs_list);
951 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, 986 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list,
952 OnAuthError(AuthError(AuthError::INVALID_GAIA_CREDENTIALS))); 987 OnAuthError(AuthError(AuthError::INVALID_GAIA_CREDENTIALS)));
953 } 988 }
954 989
955 void SyncManager::SyncInternal::SetPassphrase( 990 void SyncManager::SyncInternal::SetPassphrase(
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 2093
2059 for (syncable::ModelTypeSet::const_iterator i = types.begin(); 2094 for (syncable::ModelTypeSet::const_iterator i = types.begin();
2060 i != types.end(); ++i) { 2095 i != types.end(); ++i) {
2061 if (!lookup->initial_sync_ended_for_type(*i)) 2096 if (!lookup->initial_sync_ended_for_type(*i))
2062 return false; 2097 return false;
2063 } 2098 }
2064 return true; 2099 return true;
2065 } 2100 }
2066 2101
2067 } // namespace sync_api 2102 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/sync_manager.h ('k') | chrome/browser/sync/internal_api/syncapi_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698