summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/sync/internal_api/DEPS3
-rw-r--r--chrome/browser/sync/internal_api/sync_manager.cc35
-rw-r--r--chrome/browser/sync/internal_api/sync_manager.h4
-rw-r--r--chrome/browser/sync/internal_api/syncapi_unittest.cc22
-rw-r--r--chrome/common/chrome_switches.cc4
-rw-r--r--chrome/common/chrome_switches.h1
6 files changed, 69 insertions, 0 deletions
diff --git a/chrome/browser/sync/internal_api/DEPS b/chrome/browser/sync/internal_api/DEPS
index 7b8b578..a393f32 100644
--- a/chrome/browser/sync/internal_api/DEPS
+++ b/chrome/browser/sync/internal_api/DEPS
@@ -7,6 +7,9 @@ include_rules = [
"-chrome/browser/sync/api",
"-chrome/browser/sync/glue",
+ # Some functionality depends on command-line swithces
+ "+chrome/common/chrome_switches.h",
+
# unittests need this for mac osx keychain overriding
"+chrome/browser/password_manager/encryptor.h",
diff --git a/chrome/browser/sync/internal_api/sync_manager.cc b/chrome/browser/sync/internal_api/sync_manager.cc
index b2924b3..3669e68 100644
--- a/chrome/browser/sync/internal_api/sync_manager.cc
+++ b/chrome/browser/sync/internal_api/sync_manager.cc
@@ -8,6 +8,7 @@
#include <vector>
#include "base/base64.h"
+#include "base/command_line.h"
#include "base/json/json_writer.h"
#include "base/string_number_conversions.h"
#include "base/values.h"
@@ -44,6 +45,7 @@
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/sync/util/cryptographer.h"
#include "chrome/browser/sync/weak_handle.h"
+#include "chrome/common/chrome_switches.h"
#include "net/base/network_change_notifier.h"
using std::string;
@@ -257,6 +259,10 @@ class SyncManager::SyncInternal
// Called when the user disables or enables a sync type.
void UpdateEnabledTypes();
+ // Conditionally sets the flag in the Nigori node which instructs other
+ // clients to start syncing tabs.
+ void MaybeSetSyncTabsInNigoriNode(const syncable::ModelTypeSet enabled_types);
+
// Tell the sync engine to start the syncing process.
void StartSyncingNormally();
@@ -678,6 +684,11 @@ void SyncManager::UpdateEnabledTypes() {
data_->UpdateEnabledTypes();
}
+void SyncManager::MaybeSetSyncTabsInNigoriNode(
+ const syncable::ModelTypeSet enabled_types) {
+ data_->MaybeSetSyncTabsInNigoriNode(enabled_types);
+}
+
bool SyncManager::InitialSyncEndedForAllEnabledTypes() {
return data_->InitialSyncEndedForAllEnabledTypes();
}
@@ -965,6 +976,30 @@ void SyncManager::SyncInternal::UpdateEnabledTypes() {
enabled_types.insert(it->first);
}
sync_notifier_->UpdateEnabledTypes(enabled_types);
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableSyncSessionsForOtherClients)) {
+ MaybeSetSyncTabsInNigoriNode(enabled_types);
+ }
+}
+
+void SyncManager::SyncInternal::MaybeSetSyncTabsInNigoriNode(
+ const syncable::ModelTypeSet enabled_types) {
+ // The initialized_ check is to ensure that we don't CHECK in GetUserShare
+ // when this is called on start-up. It's ok to ignore that case, since
+ // presumably this would've run when the user originally enabled sessions.
+ if (initialized_ && enabled_types.count(syncable::SESSIONS) > 0) {
+ WriteTransaction trans(FROM_HERE, GetUserShare());
+ WriteNode node(&trans);
+ if (!node.InitByTagLookup(kNigoriTag)) {
+ NOTREACHED() << "Unable to set 'sync_tabs' bit because Nigori node not "
+ << "found.";
+ return;
+ }
+
+ sync_pb::NigoriSpecifics specifics(node.GetNigoriSpecifics());
+ specifics.set_sync_tabs(true);
+ node.SetNigoriSpecifics(specifics);
+ }
}
void SyncManager::SyncInternal::RaiseAuthNeededEvent() {
diff --git a/chrome/browser/sync/internal_api/sync_manager.h b/chrome/browser/sync/internal_api/sync_manager.h
index 98eeaa4..3f1f627 100644
--- a/chrome/browser/sync/internal_api/sync_manager.h
+++ b/chrome/browser/sync/internal_api/sync_manager.h
@@ -434,6 +434,10 @@ class SyncManager {
// Called when the user disables or enables a sync type.
void UpdateEnabledTypes();
+ // Conditionally sets the flag in the Nigori node which instructs other
+ // clients to start syncing tabs.
+ void MaybeSetSyncTabsInNigoriNode(const syncable::ModelTypeSet enabled_types);
+
// Put the syncer in normal mode ready to perform nudges and polls.
void StartSyncingNormally();
diff --git a/chrome/browser/sync/internal_api/syncapi_unittest.cc b/chrome/browser/sync/internal_api/syncapi_unittest.cc
index 721e31f..4ee77b7 100644
--- a/chrome/browser/sync/internal_api/syncapi_unittest.cc
+++ b/chrome/browser/sync/internal_api/syncapi_unittest.cc
@@ -916,6 +916,28 @@ TEST_F(SyncManagerTest, UpdateEnabledTypes) {
EXPECT_EQ(2, update_enabled_types_call_count_);
}
+TEST_F(SyncManagerTest, DoNotSyncTabsInNigoriNode) {
+ syncable::ModelTypeSet encrypted_types;
+ encrypted_types.insert(syncable::TYPED_URLS);
+ sync_manager_.MaybeSetSyncTabsInNigoriNode(encrypted_types);
+
+ ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
+ ReadNode node(&trans);
+ ASSERT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI)));
+ EXPECT_FALSE(node.GetNigoriSpecifics().sync_tabs());
+}
+
+TEST_F(SyncManagerTest, SyncTabsInNigoriNode) {
+ syncable::ModelTypeSet encrypted_types;
+ encrypted_types.insert(syncable::SESSIONS);
+ sync_manager_.MaybeSetSyncTabsInNigoriNode(encrypted_types);
+
+ ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
+ ReadNode node(&trans);
+ ASSERT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI)));
+ EXPECT_TRUE(node.GetNigoriSpecifics().sync_tabs());
+}
+
TEST_F(SyncManagerTest, ProcessJsMessage) {
const JsArgList kNoArgs;
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index dfab776..63aa4f7 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -537,6 +537,10 @@ const char kEnableSyncSearchEngines[] = "enable-sync-search-engines";
// Enable syncing browser sessions.
const char kEnableSyncSessions[] = "enable-sync-sessions";
+// Enable syncing browser sessions for other synced clients.
+const char kEnableSyncSessionsForOtherClients[] =
+ "enable-sync-sessions-for-other-clients";
+
// Enables context menu for selecting groups of tabs.
const char kEnableTabGroupsContextMenu[] = "enable-tab-groups-context-menu";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 72768bc..997aabe 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -155,6 +155,7 @@ extern const char kEnableSSLCachedInfo[];
extern const char kEnableSyncOAuth[];
extern const char kEnableSyncSearchEngines[];
extern const char kEnableSyncSessions[];
+extern const char kEnableSyncSessionsForOtherClients[];
extern const char kEnableSyncedBookmarksFolder[];
extern const char kEnableTabGroupsContextMenu[];
extern const char kEnableTcpFastOpen[];