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

Side by Side Diff: components/sync/core_impl/syncapi_internal.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
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/syncapi_internal.h" 5 #include "components/sync/core_impl/syncapi_internal.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "sync/protocol/attachments.pb.h" 12 #include "components/sync/base/cryptographer.h"
13 #include "sync/protocol/password_specifics.pb.h" 13 #include "components/sync/protocol/attachments.pb.h"
14 #include "sync/protocol/sync.pb.h" 14 #include "components/sync/protocol/password_specifics.pb.h"
15 #include "sync/util/cryptographer.h" 15 #include "components/sync/protocol/sync.pb.h"
16 16
17 namespace syncer { 17 namespace syncer {
18 18
19 namespace { 19 namespace {
20 20
21 bool EndsWithSpace(const std::string& string) { 21 bool EndsWithSpace(const std::string& string) {
22 return !string.empty() && *string.rbegin() == ' '; 22 return !string.empty() && *string.rbegin() == ' ';
23 } 23 }
24
25 } 24 }
26 25
27 sync_pb::PasswordSpecificsData* DecryptPasswordSpecifics( 26 sync_pb::PasswordSpecificsData* DecryptPasswordSpecifics(
28 const sync_pb::EntitySpecifics& specifics, Cryptographer* crypto) { 27 const sync_pb::EntitySpecifics& specifics,
28 Cryptographer* crypto) {
29 if (!specifics.has_password()) 29 if (!specifics.has_password())
30 return NULL; 30 return NULL;
31 const sync_pb::PasswordSpecifics& password_specifics = specifics.password(); 31 const sync_pb::PasswordSpecifics& password_specifics = specifics.password();
32 if (!password_specifics.has_encrypted()) 32 if (!password_specifics.has_encrypted())
33 return NULL; 33 return NULL;
34 const sync_pb::EncryptedData& encrypted = password_specifics.encrypted(); 34 const sync_pb::EncryptedData& encrypted = password_specifics.encrypted();
35 std::unique_ptr<sync_pb::PasswordSpecificsData> data( 35 std::unique_ptr<sync_pb::PasswordSpecificsData> data(
36 new sync_pb::PasswordSpecificsData); 36 new sync_pb::PasswordSpecificsData);
37 if (!crypto->CanDecrypt(encrypted)) 37 if (!crypto->CanDecrypt(encrypted))
38 return NULL; 38 return NULL;
39 if (!crypto->Decrypt(encrypted, data.get())) 39 if (!crypto->Decrypt(encrypted, data.get()))
40 return NULL; 40 return NULL;
41 return data.release(); 41 return data.release();
42 } 42 }
43 43
44 // The list of names which are reserved for use by the server. 44 // The list of names which are reserved for use by the server.
45 static const char* kForbiddenServerNames[] = { "", ".", ".." }; 45 static const char* kForbiddenServerNames[] = {"", ".", ".."};
46 46
47 // When taking a name from the syncapi, append a space if it matches the 47 // When taking a name from the syncapi, append a space if it matches the
48 // pattern of a server-illegal name followed by zero or more spaces. 48 // pattern of a server-illegal name followed by zero or more spaces.
49 void SyncAPINameToServerName(const std::string& syncer_name, 49 void SyncAPINameToServerName(const std::string& syncer_name, std::string* out) {
50 std::string* out) {
51 *out = syncer_name; 50 *out = syncer_name;
52 if (IsNameServerIllegalAfterTrimming(*out)) 51 if (IsNameServerIllegalAfterTrimming(*out))
53 out->append(" "); 52 out->append(" ");
54 } 53 }
55 54
56 // In the reverse direction, if a server name matches the pattern of a 55 // In the reverse direction, if a server name matches the pattern of a
57 // server-illegal name followed by one or more spaces, remove the trailing 56 // server-illegal name followed by one or more spaces, remove the trailing
58 // space. 57 // space.
59 void ServerNameToSyncAPIName(const std::string& server_name, 58 void ServerNameToSyncAPIName(const std::string& server_name, std::string* out) {
60 std::string* out) {
61 CHECK(out); 59 CHECK(out);
62 int length_to_copy = server_name.length(); 60 int length_to_copy = server_name.length();
63 if (IsNameServerIllegalAfterTrimming(server_name) && 61 if (IsNameServerIllegalAfterTrimming(server_name) &&
64 EndsWithSpace(server_name)) { 62 EndsWithSpace(server_name)) {
65 --length_to_copy; 63 --length_to_copy;
66 } 64 }
67 *out = server_name.substr(0, length_to_copy); 65 *out = server_name.substr(0, length_to_copy);
68 } 66 }
69 67
70 // Checks whether |name| is a server-illegal name followed by zero or more space 68 // Checks whether |name| is a server-illegal name followed by zero or more space
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 111
114 bool AreAttachmentMetadataEqual(const sync_pb::AttachmentMetadata& left, 112 bool AreAttachmentMetadataEqual(const sync_pb::AttachmentMetadata& left,
115 const sync_pb::AttachmentMetadata& right) { 113 const sync_pb::AttachmentMetadata& right) {
116 if (left.SerializeAsString() == right.SerializeAsString()) { 114 if (left.SerializeAsString() == right.SerializeAsString()) {
117 return true; 115 return true;
118 } 116 }
119 return false; 117 return false;
120 } 118 }
121 119
122 } // namespace syncer 120 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/core_impl/syncapi_internal.h ('k') | components/sync/core_impl/syncapi_server_connection_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698