Skip to content

Commit

Permalink
Add Sync data type for managed users.
Browse files Browse the repository at this point in the history
TBR=atwilson@chromium.org
BUG=228833

Review URL: https://chromiumcodereview.appspot.com/15177003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202026 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
bauerb@chromium.org committed May 24, 2013
1 parent d5e04ce commit 42e8903
Show file tree
Hide file tree
Showing 21 changed files with 120 additions and 7 deletions.
3 changes: 3 additions & 0 deletions chrome/browser/sync/glue/model_association_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ static const syncer::ModelType kStartOrder[] = {
syncer::EXPERIMENTS, // Listed for completeness.
syncer::PROXY_TABS, // Listed for completeness.
syncer::BOOKMARKS, // UI thread datatypes.
syncer::MANAGED_USERS, // Syncing managed users on initial login might
// block creating a new managed user, so we
// want to do it early.
syncer::PREFERENCES,
syncer::PRIORITY_PREFERENCES,
syncer::EXTENSIONS,
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/sync/profile_sync_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ const browser_sync::user_selectable_type::UserSelectableSyncType
browser_sync::user_selectable_type::PROXY_TABS
};

COMPILE_ASSERT(27 == syncer::MODEL_TYPE_COUNT, UpdateCustomConfigHistogram);
COMPILE_ASSERT(28 == syncer::MODEL_TYPE_COUNT, UpdateCustomConfigHistogram);

if (!sync_everything) {
const syncer::ModelTypeSet current_types = GetPreferredDataTypes();
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/sync/sync_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ const char* SyncPrefs::GetPrefNameForDataType(syncer::ModelType data_type) {
return prefs::kSyncTabs;
case syncer::PRIORITY_PREFERENCES:
return prefs::kSyncPriorityPreferences;
case syncer::MANAGED_USERS:
return prefs::kSyncManagedUsers;
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/webui/sync_setup_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const char* kDataTypeNames[] = {
"tabs"
};

COMPILE_ASSERT(27 == syncer::MODEL_TYPE_COUNT,
COMPILE_ASSERT(28 == syncer::MODEL_TYPE_COUNT,
update_kDataTypeNames_to_match_UserSelectableTypes);

typedef std::map<syncer::ModelType, const char*> ModelTypeNameMap;
Expand Down
1 change: 1 addition & 0 deletions chrome/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,7 @@ const char kSyncFaviconImages[] = "sync.favicon_images";
const char kSyncFaviconTracking[] = "sync.favicon_tracking";
const char kSyncHistoryDeleteDirectives[] = "sync.history_delete_directives";
const char kSyncManagedUserSettings[] = "sync.managed_user_settings";
const char kSyncManagedUsers[] = "sync.managed_users";
const char kSyncPasswords[] = "sync.passwords";
const char kSyncPreferences[] = "sync.preferences";
const char kSyncPriorityPreferences[] = "sync.priority_preferences";
Expand Down
1 change: 1 addition & 0 deletions chrome/common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ extern const char kSyncFaviconImages[];
extern const char kSyncFaviconTracking[];
extern const char kSyncHistoryDeleteDirectives[];
extern const char kSyncManagedUserSettings[];
extern const char kSyncManagedUsers[];
extern const char kSyncPasswords[];
extern const char kSyncPreferences[];
extern const char kSyncPriorityPreferences[];
Expand Down
5 changes: 5 additions & 0 deletions sync/internal_api/base_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ const sync_pb::ManagedUserSettingSpecifics&
return GetEntitySpecifics().managed_user_setting();
}

const sync_pb::ManagedUserSpecifics& BaseNode::GetManagedUserSpecifics() const {
DCHECK_EQ(GetModelType(), MANAGED_USERS);
return GetEntitySpecifics().managed_user();
}

const sync_pb::DeviceInfoSpecifics& BaseNode::GetDeviceInfoSpecifics() const {
DCHECK_EQ(GetModelType(), DEVICE_INFO);
return GetEntitySpecifics().device_info();
Expand Down
4 changes: 4 additions & 0 deletions sync/internal_api/public/base/model_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ enum ModelType {
PRIORITY_PREFERENCES,
// Managed user settings.
MANAGED_USER_SETTINGS,
// Managed users. Every managed user is a profile that is configured remotely
// by this user and can have restrictions applied. MANAGED_USERS and
// MANAGED_USER_SETTINGS can not be encrypted.
MANAGED_USERS,

// ---- Proxy types ----
// Proxy types are excluded from the sync protocol, but are still considered
Expand Down
4 changes: 4 additions & 0 deletions sync/internal_api/public/base_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ class SYNC_EXPORT BaseNode {
const sync_pb::ManagedUserSettingSpecifics&
GetManagedUserSettingSpecifics() const;

// Getter specific to the MANAGED_USERS datatype. Returns protobuf data.
// Can only be called if GetModelType() == MANAGED_USERS.
const sync_pb::ManagedUserSpecifics& GetManagedUserSpecifics() const;

// Getter specific to the DEVICE_INFO datatype. Returns protobuf
// data. Can only be called if GetModelType() == DEVICE_INFO.
const sync_pb::DeviceInfoSpecifics& GetDeviceInfoSpecifics() const;
Expand Down
4 changes: 4 additions & 0 deletions sync/internal_api/public/write_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ class SYNC_EXPORT WriteNode : public BaseNode {
void SetManagedUserSettingSpecifics(
const sync_pb::ManagedUserSettingSpecifics& specifics);

// Set the managed user setting specifics (name and value).
// Should only be called if GetModelType() == MANAGED_USERS.
void SetManagedUserSpecifics(const sync_pb::ManagedUserSpecifics& specifics);

// Set the device info specifics.
// Should only be called if GetModelType() == DEVICE_INFO.
void SetDeviceInfoSpecifics(const sync_pb::DeviceInfoSpecifics& specifics);
Expand Down
7 changes: 7 additions & 0 deletions sync/internal_api/write_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ void WriteNode::SetManagedUserSettingSpecifics(
SetEntitySpecifics(entity_specifics);
}

void WriteNode::SetManagedUserSpecifics(
const sync_pb::ManagedUserSpecifics& new_value) {
sync_pb::EntitySpecifics entity_specifics;
entity_specifics.mutable_managed_user()->CopyFrom(new_value);
SetEntitySpecifics(entity_specifics);
}

void WriteNode::SetDeviceInfoSpecifics(
const sync_pb::DeviceInfoSpecifics& new_value) {
sync_pb::EntitySpecifics entity_specifics;
Expand Down
26 changes: 26 additions & 0 deletions sync/protocol/managed_user_specifics.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Sync protocol datatype extension for managed user settings.

// Update proto_value_conversions{.h,.cc,_unittest.cc} if you change
// any fields in this file.

syntax = "proto2";

option optimize_for = LITE_RUNTIME;
option retain_unknown_fields = true;

package sync_pb;

// Properties of managed user sync objects.
message ManagedUserSpecifics {
// A randomly-generated identifier for the managed user.
optional string id = 1;
// The human-visible name of the managed user
optional string name = 2;
// This flag is set by the server to acknowledge that it has committed a
// newly created managed user.
optional bool acknowledged = 3 [default = false];
}
10 changes: 10 additions & 0 deletions sync/protocol/proto_value_conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,15 @@ base::DictionaryValue* ManagedUserSettingSpecificsToValue(
return value;
}

base::DictionaryValue* ManagedUserSpecificsToValue(
const sync_pb::ManagedUserSpecifics& proto) {
base::DictionaryValue* value = new base::DictionaryValue();
SET_STR(id);
SET_STR(name);
SET_BOOL(acknowledged);
return value;
}

base::DictionaryValue* NigoriSpecificsToValue(
const sync_pb::NigoriSpecifics& proto) {
base::DictionaryValue* value = new base::DictionaryValue();
Expand Down Expand Up @@ -552,6 +561,7 @@ base::DictionaryValue* EntitySpecificsToValue(
SET_FIELD(favicon_tracking, FaviconTrackingSpecificsToValue);
SET_FIELD(history_delete_directive, HistoryDeleteDirectiveSpecificsToValue);
SET_FIELD(managed_user_setting, ManagedUserSettingSpecificsToValue);
SET_FIELD(managed_user, ManagedUserSpecificsToValue);
SET_FIELD(nigori, NigoriSpecificsToValue);
SET_FIELD(password, PasswordSpecificsToValue);
SET_FIELD(preference, PreferenceSpecificsToValue);
Expand Down
4 changes: 4 additions & 0 deletions sync/protocol/proto_value_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class GlobalIdDirective;
class HistoryDeleteDirectiveSpecifics;
class KeystoreEncryptionFlagsSpecifics;
class ManagedUserSettingSpecifics;
class ManagedUserSpecifics;
class NigoriSpecifics;
class PasswordSpecifics;
class PasswordSpecificsData;
Expand Down Expand Up @@ -170,6 +171,9 @@ SYNC_EXPORT base::DictionaryValue* HistoryDeleteDirectiveSpecificsToValue(
SYNC_EXPORT_PRIVATE base::DictionaryValue* ManagedUserSettingSpecificsToValue(
const sync_pb::ManagedUserSettingSpecifics& managed_user_setting_specifics);

SYNC_EXPORT_PRIVATE base::DictionaryValue* ManagedUserSpecificsToValue(
const sync_pb::ManagedUserSpecifics& managed_user_specifics);

SYNC_EXPORT_PRIVATE base::DictionaryValue* NigoriSpecificsToValue(
const sync_pb::NigoriSpecifics& nigori_specifics);

Expand Down
7 changes: 6 additions & 1 deletion sync/protocol/proto_value_conversions_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) {
// If this number changes, that means we added or removed a data
// type. Don't forget to add a unit test for {New
// type}SpecificsToValue below.
EXPECT_EQ(27, MODEL_TYPE_COUNT);
EXPECT_EQ(28, MODEL_TYPE_COUNT);

// We'd also like to check if we changed any field in our messages.
// However, that's hard to do: sizeof could work, but it's
Expand Down Expand Up @@ -178,6 +178,10 @@ TEST_F(ProtoValueConversionsTest, ManagedUserSettingSpecificsToValue) {
TestSpecificsToValue(ManagedUserSettingSpecificsToValue);
}

TEST_F(ProtoValueConversionsTest, ManagedUserSpecificsToValue) {
TestSpecificsToValue(ManagedUserSpecificsToValue);
}

TEST_F(ProtoValueConversionsTest, NigoriSpecificsToValue) {
TestSpecificsToValue(NigoriSpecificsToValue);
}
Expand Down Expand Up @@ -237,6 +241,7 @@ TEST_F(ProtoValueConversionsTest, EntitySpecificsToValue) {
SET_FIELD(favicon_tracking);
SET_FIELD(history_delete_directive);
SET_FIELD(managed_user_setting);
SET_FIELD(managed_user);
SET_FIELD(nigori);
SET_FIELD(password);
SET_FIELD(preference);
Expand Down
2 changes: 2 additions & 0 deletions sync/protocol/sync.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import "get_updates_caller_info.proto";
import "history_delete_directive_specifics.proto";
import "nigori_specifics.proto";
import "managed_user_setting_specifics.proto";
import "managed_user_specifics.proto";
import "password_specifics.proto";
import "preference_specifics.proto";
import "priority_preference_specifics.proto";
Expand Down Expand Up @@ -116,6 +117,7 @@ message EntitySpecifics {
optional FaviconTrackingSpecifics favicon_tracking = 181534;
optional FaviconImageSpecifics favicon_image = 182019;
optional ManagedUserSettingSpecifics managed_user_setting = 186662;
optional ManagedUserSpecifics managed_user = 194582;
}

message SyncEntity {
Expand Down
1 change: 1 addition & 0 deletions sync/sync_proto.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'protocol/history_delete_directive_specifics.proto',
'protocol/nigori_specifics.proto',
'protocol/managed_user_setting_specifics.proto',
'protocol/managed_user_specifics.proto',
'protocol/password_specifics.proto',
'protocol/preference_specifics.proto',
'protocol/priority_preference_specifics.proto',
Expand Down
25 changes: 25 additions & 0 deletions sync/syncable/model_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ void AddDefaultFieldValue(ModelType datatype,
case MANAGED_USER_SETTINGS:
specifics->mutable_managed_user_setting();
break;
case MANAGED_USERS:
specifics->mutable_managed_user();
break;
default:
NOTREACHED() << "No known extension for model type.";
}
Expand Down Expand Up @@ -192,6 +195,8 @@ int GetSpecificsFieldNumberFromModelType(ModelType model_type) {
return sync_pb::EntitySpecifics::kFaviconTrackingFieldNumber;
case MANAGED_USER_SETTINGS:
return sync_pb::EntitySpecifics::kManagedUserSettingFieldNumber;
case MANAGED_USERS:
return sync_pb::EntitySpecifics::kManagedUserFieldNumber;
default:
NOTREACHED() << "No known extension for model type.";
return 0;
Expand Down Expand Up @@ -311,6 +316,9 @@ ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics) {
if (specifics.has_managed_user_setting())
return MANAGED_USER_SETTINGS;

if (specifics.has_managed_user())
return MANAGED_USERS;

return UNSPECIFIED;
}

Expand Down Expand Up @@ -362,6 +370,8 @@ ModelTypeSet EncryptableUserTypes() {
encryptable_user_types.RemoveAll(PriorityUserTypes());
// Managed user settings are not encrypted since they are set server-side.
encryptable_user_types.Remove(MANAGED_USER_SETTINGS);
// Managed users are not encrypted since they are managed server-side.
encryptable_user_types.Remove(MANAGED_USERS);
// Proxy types have no sync representation and are therefore not encrypted.
// Note however that proxy types map to one or more protocol types, which
// may or may not be encrypted themselves.
Expand Down Expand Up @@ -452,6 +462,8 @@ const char* ModelTypeToString(ModelType model_type) {
return "Favicon Tracking";
case MANAGED_USER_SETTINGS:
return "Managed User Settings";
case MANAGED_USERS:
return "Managed Users";
case PROXY_TABS:
return "Tabs";
default:
Expand Down Expand Up @@ -521,6 +533,8 @@ int ModelTypeToHistogramInt(ModelType model_type) {
return 25;
case MANAGED_USER_SETTINGS:
return 26;
case MANAGED_USERS:
return 27;
// Silence a compiler warning.
case MODEL_TYPE_COUNT:
return 0;
Expand Down Expand Up @@ -604,6 +618,8 @@ ModelType ModelTypeFromString(const std::string& model_type_string) {
return FAVICON_TRACKING;
else if (model_type_string == "Managed User Settings")
return MANAGED_USER_SETTINGS;
else if (model_type_string == "Managed Users")
return MANAGED_USERS;
else if (model_type_string == "Tabs")
return PROXY_TABS;
else
Expand Down Expand Up @@ -694,6 +710,8 @@ std::string ModelTypeToRootTag(ModelType type) {
return "google_chrome_favicon_tracking";
case MANAGED_USER_SETTINGS:
return "google_chrome_managed_user_settings";
case MANAGED_USERS:
return "google_chrome_managed_users";
case PROXY_TABS:
return std::string();
default:
Expand Down Expand Up @@ -732,6 +750,7 @@ const char kDictionaryNotificationType[] = "DICTIONARY";
const char kFaviconImageNotificationType[] = "FAVICON_IMAGE";
const char kFaviconTrackingNotificationType[] = "FAVICON_TRACKING";
const char kManagedUserSettingNotificationType[] = "MANAGED_USER_SETTING";
const char kManagedUserNotificationType[] = "MANAGED_USER";
} // namespace

bool RealModelTypeToNotificationType(ModelType model_type,
Expand Down Expand Up @@ -809,6 +828,9 @@ bool RealModelTypeToNotificationType(ModelType model_type,
case MANAGED_USER_SETTINGS:
*notification_type = kManagedUserSettingNotificationType;
return true;
case MANAGED_USERS:
*notification_type = kManagedUserNotificationType;
return true;
default:
break;
}
Expand Down Expand Up @@ -890,6 +912,9 @@ bool NotificationTypeToRealModelType(const std::string& notification_type,
} else if (notification_type == kManagedUserSettingNotificationType) {
*model_type = MANAGED_USER_SETTINGS;
return true;
} else if (notification_type == kManagedUserNotificationType) {
*model_type = MANAGED_USERS;
return true;
}
*model_type = UNSPECIFIED;
return false;
Expand Down
4 changes: 2 additions & 2 deletions sync/syncable/nigori_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void UpdateNigoriFromEncryptedTypes(ModelTypeSet encrypted_types,
bool encrypt_everything,
sync_pb::NigoriSpecifics* nigori) {
nigori->set_encrypt_everything(encrypt_everything);
COMPILE_ASSERT(27 == MODEL_TYPE_COUNT, UpdateEncryptedTypes);
COMPILE_ASSERT(28 == MODEL_TYPE_COUNT, UpdateEncryptedTypes);
nigori->set_encrypt_bookmarks(
encrypted_types.Has(BOOKMARKS));
nigori->set_encrypt_preferences(
Expand Down Expand Up @@ -276,7 +276,7 @@ ModelTypeSet GetEncryptedTypesFromNigori(
return ModelTypeSet::All();

ModelTypeSet encrypted_types;
COMPILE_ASSERT(27 == MODEL_TYPE_COUNT, UpdateEncryptedTypes);
COMPILE_ASSERT(28 == MODEL_TYPE_COUNT, UpdateEncryptedTypes);
if (nigori.encrypt_bookmarks())
encrypted_types.Put(BOOKMARKS);
if (nigori.encrypt_preferences())
Expand Down
8 changes: 7 additions & 1 deletion sync/tools/testserver/chromiumsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import favicon_tracking_specifics_pb2
import history_delete_directive_specifics_pb2
import managed_user_setting_specifics_pb2
import managed_user_specifics_pb2
import nigori_specifics_pb2
import password_specifics_pb2
import preference_specifics_pb2
Expand Down Expand Up @@ -62,6 +63,7 @@
EXTENSIONS,
HISTORY_DELETE_DIRECTIVE,
MANAGED_USER_SETTING,
MANAGED_USER,
NIGORI,
PASSWORD,
PREFERENCE,
Expand All @@ -73,7 +75,7 @@
TYPED_URL,
EXTENSION_SETTINGS,
FAVICON_IMAGES,
FAVICON_TRACKING) = range(25)
FAVICON_TRACKING) = range(26)

# An enumeration on the frequency at which the server should send errors
# to the client. This would be specified by the url that triggers the error.
Expand Down Expand Up @@ -105,6 +107,7 @@
FAVICON_TRACKING: SYNC_TYPE_FIELDS['favicon_tracking'],
HISTORY_DELETE_DIRECTIVE: SYNC_TYPE_FIELDS['history_delete_directive'],
MANAGED_USER_SETTING: SYNC_TYPE_FIELDS['managed_user_setting'],
MANAGED_USER: SYNC_TYPE_FIELDS['managed_user'],
NIGORI: SYNC_TYPE_FIELDS['nigori'],
PASSWORD: SYNC_TYPE_FIELDS['password'],
PREFERENCE: SYNC_TYPE_FIELDS['preference'],
Expand Down Expand Up @@ -497,6 +500,9 @@ class SyncDataModel(object):
PermanentItem('google_chrome_managed_user_settings',
name='Managed User Settings',
parent_tag=ROOT_ID, sync_type=MANAGED_USER_SETTING),
PermanentItem('google_chrome_managed_users',
name='Managed Users',
parent_tag=ROOT_ID, sync_type=MANAGED_USER),
PermanentItem('google_chrome_nigori', name='Nigori',
parent_tag=ROOT_ID, sync_type=NIGORI),
PermanentItem('google_chrome_passwords', name='Passwords',
Expand Down
Loading

0 comments on commit 42e8903

Please sign in to comment.