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

Side by Side Diff: sync/internal_api/base_node.cc

Issue 11571092: sync: Move unique_client_tag hashing code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 12 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "sync/internal_api/public/base_node.h" 5 #include "sync/internal_api/public/base_node.h"
6 6
7 #include <stack> 7 #include <stack>
8 8
9 #include "base/base64.h"
10 #include "base/sha1.h"
11 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
12 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 11 #include "base/values.h"
14 #include "sync/internal_api/public/base_transaction.h" 12 #include "sync/internal_api/public/base_transaction.h"
15 #include "sync/internal_api/syncapi_internal.h" 13 #include "sync/internal_api/syncapi_internal.h"
16 #include "sync/protocol/app_specifics.pb.h" 14 #include "sync/protocol/app_specifics.pb.h"
17 #include "sync/protocol/autofill_specifics.pb.h" 15 #include "sync/protocol/autofill_specifics.pb.h"
18 #include "sync/protocol/bookmark_specifics.pb.h" 16 #include "sync/protocol/bookmark_specifics.pb.h"
19 #include "sync/protocol/extension_specifics.pb.h" 17 #include "sync/protocol/extension_specifics.pb.h"
20 #include "sync/protocol/nigori_specifics.pb.h" 18 #include "sync/protocol/nigori_specifics.pb.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 EndsWithSpace(server_name)) { 56 EndsWithSpace(server_name)) {
59 --length_to_copy; 57 --length_to_copy;
60 } 58 }
61 *out = std::string(server_name.c_str(), length_to_copy); 59 *out = std::string(server_name.c_str(), length_to_copy);
62 } 60 }
63 61
64 BaseNode::BaseNode() : password_data_(new sync_pb::PasswordSpecificsData) {} 62 BaseNode::BaseNode() : password_data_(new sync_pb::PasswordSpecificsData) {}
65 63
66 BaseNode::~BaseNode() {} 64 BaseNode::~BaseNode() {}
67 65
68 std::string BaseNode::GenerateSyncableHash(
69 ModelType model_type, const std::string& client_tag) {
70 // Blank PB with just the field in it has termination symbol,
71 // handy for delimiter.
72 sync_pb::EntitySpecifics serialized_type;
73 AddDefaultFieldValue(model_type, &serialized_type);
74 std::string hash_input;
75 serialized_type.AppendToString(&hash_input);
76 hash_input.append(client_tag);
77
78 std::string encode_output;
79 CHECK(base::Base64Encode(base::SHA1HashString(hash_input), &encode_output));
80 return encode_output;
81 }
82
83 bool BaseNode::DecryptIfNecessary() { 66 bool BaseNode::DecryptIfNecessary() {
84 if (!GetEntry()->Get(syncable::UNIQUE_SERVER_TAG).empty()) 67 if (!GetEntry()->Get(syncable::UNIQUE_SERVER_TAG).empty())
85 return true; // Ignore unique folders. 68 return true; // Ignore unique folders.
86 const sync_pb::EntitySpecifics& specifics = 69 const sync_pb::EntitySpecifics& specifics =
87 GetEntry()->Get(syncable::SPECIFICS); 70 GetEntry()->Get(syncable::SPECIFICS);
88 if (specifics.has_password()) { 71 if (specifics.has_password()) {
89 // Passwords have their own legacy encryption structure. 72 // Passwords have their own legacy encryption structure.
90 scoped_ptr<sync_pb::PasswordSpecificsData> data(DecryptPasswordSpecifics( 73 scoped_ptr<sync_pb::PasswordSpecificsData> data(DecryptPasswordSpecifics(
91 specifics, GetTransaction()->GetCryptographer())); 74 specifics, GetTransaction()->GetCryptographer()));
92 if (!data.get()) { 75 if (!data.get()) {
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 const sync_pb::EntitySpecifics& specifics) { 355 const sync_pb::EntitySpecifics& specifics) {
373 ModelType type = GetModelTypeFromSpecifics(specifics); 356 ModelType type = GetModelTypeFromSpecifics(specifics);
374 DCHECK_NE(UNSPECIFIED, type); 357 DCHECK_NE(UNSPECIFIED, type);
375 if (GetModelType() != UNSPECIFIED) { 358 if (GetModelType() != UNSPECIFIED) {
376 DCHECK_EQ(GetModelType(), type); 359 DCHECK_EQ(GetModelType(), type);
377 } 360 }
378 unencrypted_data_.CopyFrom(specifics); 361 unencrypted_data_.CopyFrom(specifics);
379 } 362 }
380 363
381 } // namespace syncer 364 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | sync/internal_api/public/base_node.h » ('j') | sync/internal_api/sync_manager_impl_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698