Skip to content

Commit

Permalink
Add logic to flip Nigori bit to instruct other clients to sync tabs.
Browse files Browse the repository at this point in the history
For reference, see: http://codereview.chromium.org/7669073/

BUG=
TEST=


Review URL: http://codereview.chromium.org/7767013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99317 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
yfriedman@chromium.org committed Sep 2, 2011
1 parent ef5746e commit 8de8745
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chrome/browser/sync/internal_api/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down
35 changes: 35 additions & 0 deletions chrome/browser/sync/internal_api/sync_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/sync/internal_api/sync_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
22 changes: 22 additions & 0 deletions chrome/browser/sync/internal_api/syncapi_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions chrome/common/chrome_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
1 change: 1 addition & 0 deletions chrome/common/chrome_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down

0 comments on commit 8de8745

Please sign in to comment.