OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/syncable/syncable_util.h" | 5 #include "sync/syncable/syncable_util.h" |
6 | 6 |
| 7 #include "base/base64.h" |
7 #include "base/location.h" | 8 #include "base/location.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/sha1.h" |
9 #include "sync/syncable/directory.h" | 11 #include "sync/syncable/directory.h" |
10 #include "sync/syncable/entry.h" | 12 #include "sync/syncable/entry.h" |
11 #include "sync/syncable/mutable_entry.h" | 13 #include "sync/syncable/mutable_entry.h" |
12 #include "sync/syncable/syncable_id.h" | 14 #include "sync/syncable/syncable_id.h" |
13 #include "sync/syncable/syncable_write_transaction.h" | 15 #include "sync/syncable/syncable_write_transaction.h" |
14 | 16 |
15 namespace syncer { | 17 namespace syncer { |
16 namespace syncable { | 18 namespace syncable { |
17 | 19 |
18 // Returns the number of unsynced entries. | 20 // Returns the number of unsynced entries. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 const tracked_objects::Location& location, | 97 const tracked_objects::Location& location, |
96 const char* msg, | 98 const char* msg, |
97 BaseTransaction* trans) { | 99 BaseTransaction* trans) { |
98 if (!condition) { | 100 if (!condition) { |
99 trans->OnUnrecoverableError(location, msg); | 101 trans->OnUnrecoverableError(location, msg); |
100 return false; | 102 return false; |
101 } | 103 } |
102 return true; | 104 return true; |
103 } | 105 } |
104 | 106 |
| 107 std::string GenerateSyncableHash( |
| 108 ModelType model_type, const std::string& client_tag) { |
| 109 // Blank PB with just the field in it has termination symbol, |
| 110 // handy for delimiter. |
| 111 sync_pb::EntitySpecifics serialized_type; |
| 112 AddDefaultFieldValue(model_type, &serialized_type); |
| 113 std::string hash_input; |
| 114 serialized_type.AppendToString(&hash_input); |
| 115 hash_input.append(client_tag); |
| 116 |
| 117 std::string encode_output; |
| 118 CHECK(base::Base64Encode(base::SHA1HashString(hash_input), &encode_output)); |
| 119 return encode_output; |
| 120 } |
| 121 |
105 } // namespace syncable | 122 } // namespace syncable |
106 } // namespace syncer | 123 } // namespace syncer |
OLD | NEW |