Skip to content

Commit

Permalink
Re-land the protocol extension for syncing passwords patch.
Browse files Browse the repository at this point in the history
BUG=34176
TEST=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46747 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
albertb@chromium.org committed May 7, 2010
1 parent 1056b6c commit 58fe019
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 0 deletions.
27 changes: 27 additions & 0 deletions chrome/browser/sync/engine/syncapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "chrome/browser/sync/engine/syncer_thread.h"
#include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
#include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
#include "chrome/browser/sync/protocol/password_specifics.pb.h"
#include "chrome/browser/sync/protocol/preference_specifics.pb.h"
#include "chrome/browser/sync/protocol/service_constants.h"
#include "chrome/browser/sync/protocol/theme_specifics.pb.h"
Expand Down Expand Up @@ -483,6 +484,15 @@ const sync_pb::BookmarkSpecifics& BaseNode::GetBookmarkSpecifics() const {
return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::bookmark);
}

bool BaseNode::GetPasswordSpecifics(sync_pb::PasswordSpecificsData* data)
const {
DCHECK(GetModelType() == syncable::PASSWORD);
DCHECK(data);
const sync_pb::PasswordSpecifics& specifics =
GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::password);
return data->ParseFromString(specifics.blob());
}

const sync_pb::PreferenceSpecifics& BaseNode::GetPreferenceSpecifics() const {
DCHECK(GetModelType() == syncable::PREFERENCES);
return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::preference);
Expand Down Expand Up @@ -557,6 +567,16 @@ void WriteNode::PutBookmarkSpecificsAndMarkForSyncing(
PutSpecificsAndMarkForSyncing(entity_specifics);
}

void WriteNode::SetPasswordSpecifics(
const sync_pb::PasswordSpecificsData& data) {
DCHECK(GetModelType() == syncable::PASSWORD);
std::string serialized_data;
data.SerializeToString(&serialized_data);
sync_pb::PasswordSpecifics new_value;
new_value.set_blob(serialized_data);
PutPasswordSpecificsAndMarkForSyncing(new_value);
}

void WriteNode::SetPreferenceSpecifics(
const sync_pb::PreferenceSpecifics& new_value) {
DCHECK(GetModelType() == syncable::PREFERENCES);
Expand All @@ -569,6 +589,13 @@ void WriteNode::SetThemeSpecifics(
PutThemeSpecificsAndMarkForSyncing(new_value);
}

void WriteNode::PutPasswordSpecificsAndMarkForSyncing(
const sync_pb::PasswordSpecifics& new_value) {
sync_pb::EntitySpecifics entity_specifics;
entity_specifics.MutableExtension(sync_pb::password)->CopyFrom(new_value);
PutSpecificsAndMarkForSyncing(entity_specifics);
}

void WriteNode::PutPreferenceSpecificsAndMarkForSyncing(
const sync_pb::PreferenceSpecifics& new_value) {
sync_pb::EntitySpecifics entity_specifics;
Expand Down
12 changes: 12 additions & 0 deletions chrome/browser/sync/engine/syncapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class AutofillSpecifics;
class BookmarkSpecifics;
class EntitySpecifics;
class PreferenceSpecifics;
class PasswordSpecifics;
class PasswordSpecificsData;
class ThemeSpecifics;
class TypedUrlSpecifics;
}
Expand Down Expand Up @@ -172,6 +174,10 @@ class BaseNode {
// data. Can only be called if GetModelType() == AUTOFILL.
const sync_pb::AutofillSpecifics& GetAutofillSpecifics() const;

// Getter specific to the PASSWORD datatype. Returns protobuf
// data. Can only be called if GetModelType() == PASSWORD.
bool GetPasswordSpecifics(sync_pb::PasswordSpecificsData*) const;

// Getter specific to the PREFERENCE datatype. Returns protobuf
// data. Can only be called if GetModelType() == PREFERENCE.
const sync_pb::PreferenceSpecifics& GetPreferenceSpecifics() const;
Expand Down Expand Up @@ -287,6 +293,10 @@ class WriteNode : public BaseNode {
// Should only be called if GetModelType() == AUTOFILL.
void SetAutofillSpecifics(const sync_pb::AutofillSpecifics& specifics);

// Set the password specifics.
// Should only be called if GetModelType() == PASSWORD.
void SetPasswordSpecifics(const sync_pb::PasswordSpecificsData& specifics);

// Set the preference specifics (name and value).
// Should only be called if GetModelType() == PREFERENCE.
void SetPreferenceSpecifics(const sync_pb::PreferenceSpecifics& specifics);
Expand Down Expand Up @@ -322,6 +332,8 @@ class WriteNode : public BaseNode {
const sync_pb::AutofillSpecifics& new_value);
void PutBookmarkSpecificsAndMarkForSyncing(
const sync_pb::BookmarkSpecifics& new_value);
void PutPasswordSpecificsAndMarkForSyncing(
const sync_pb::PasswordSpecifics& new_value);
void PutPreferenceSpecificsAndMarkForSyncing(
const sync_pb::PreferenceSpecifics& new_value);
void PutThemeSpecificsAndMarkForSyncing(
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/sync/engine/syncproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define CHROME_BROWSER_SYNC_ENGINE_SYNCPROTO_H_

#include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
#include "chrome/browser/sync/protocol/password_specifics.pb.h"
#include "chrome/browser/sync/protocol/preference_specifics.pb.h"
#include "chrome/browser/sync/protocol/sync.pb.h"
#include "chrome/browser/sync/syncable/model_type.h"
Expand Down
40 changes: 40 additions & 0 deletions chrome/browser/sync/protocol/password_specifics.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2010 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 password data.

syntax = "proto2";

option optimize_for = LITE_RUNTIME;

package sync_pb;

import "sync.proto";

// These are the properties that get serialized into the |blob| field of
// |PasswordSpecifics|.
message PasswordSpecificsData {
optional int32 scheme = 1;
optional string signon_realm = 2;
optional string origin = 3;
optional string action = 4;
optional string username_element = 5;
optional string username_value = 6;
optional string password_element = 7;
optional string password_value = 8;
optional bool ssl_valid = 9;
optional bool preferred = 10;
optional int64 date_created = 11;
optional bool blacklisted = 12;
}

// Properties of password sync objects.
message PasswordSpecifics {
optional string key = 1;
optional string blob = 2;
}

extend EntitySpecifics {
optional PasswordSpecifics password = 45873;
}
1 change: 1 addition & 0 deletions chrome/browser/sync/protocol/sync_proto.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'sync.proto',
'autofill_specifics.proto',
'bookmark_specifics.proto',
'password_specifics.proto',
'preference_specifics.proto',
'theme_specifics.proto',
'typed_url_specifics.proto',
Expand Down
7 changes: 7 additions & 0 deletions chrome/browser/sync/syncable/model_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "chrome/browser/sync/engine/syncproto.h"
#include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
#include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
#include "chrome/browser/sync/protocol/password_specifics.pb.h"
#include "chrome/browser/sync/protocol/preference_specifics.pb.h"
#include "chrome/browser/sync/protocol/sync.pb.h"
#include "chrome/browser/sync/protocol/theme_specifics.pb.h"
Expand All @@ -20,6 +21,9 @@ void AddDefaultExtensionValue(syncable::ModelType datatype,
case BOOKMARKS:
specifics->MutableExtension(sync_pb::bookmark);
break;
case PASSWORD:
specifics->MutableExtension(sync_pb::password);
break;
case PREFERENCES:
specifics->MutableExtension(sync_pb::preference);
break;
Expand Down Expand Up @@ -72,6 +76,9 @@ ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics) {
if (specifics.HasExtension(sync_pb::bookmark))
return BOOKMARKS;

if (specifics.HasExtension(sync_pb::password))
return PASSWORD;

if (specifics.HasExtension(sync_pb::preference))
return PREFERENCES;

Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/sync/syncable/model_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ enum ModelType {

// A preference folder or a preference object.
PREFERENCES,
// A password folder or password object.
PASSWORD,
// An autofill folder or an autofill object.
AUTOFILL,
// A themes folder or a themes object.
Expand Down
2 changes: 2 additions & 0 deletions chrome/chrome.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,8 @@
'<(protoc_out_dir)/chrome/browser/sync/protocol/autofill_specifics.pb.h',
'<(protoc_out_dir)/chrome/browser/sync/protocol/bookmark_specifics.pb.cc',
'<(protoc_out_dir)/chrome/browser/sync/protocol/bookmark_specifics.pb.h',
'<(protoc_out_dir)/chrome/browser/sync/protocol/password_specifics.pb.cc',
'<(protoc_out_dir)/chrome/browser/sync/protocol/password_specifics.pb.h',
'<(protoc_out_dir)/chrome/browser/sync/protocol/preference_specifics.pb.cc',
'<(protoc_out_dir)/chrome/browser/sync/protocol/preference_specifics.pb.h',
'<(protoc_out_dir)/chrome/browser/sync/protocol/theme_specifics.pb.cc',
Expand Down

0 comments on commit 58fe019

Please sign in to comment.