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

Side by Side Diff: components/sync/engine_impl/commit.cc

Issue 2637173004: [Sync] Do not use base::RandBytesAsString to generate random string (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/sync/engine_impl/commit.h" 5 #include "components/sync/engine_impl/commit.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/feature_list.h" 9 #include "base/feature_list.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "components/sync/base/data_type_histogram.h" 13 #include "components/sync/base/data_type_histogram.h"
14 #include "components/sync/engine/net/http_bridge.h" 14 #include "components/sync/engine/net/http_bridge.h"
15 #include "components/sync/engine_impl/commit_processor.h" 15 #include "components/sync/engine_impl/commit_processor.h"
16 #include "components/sync/engine_impl/commit_util.h" 16 #include "components/sync/engine_impl/commit_util.h"
17 #include "components/sync/engine_impl/cycle/sync_cycle.h" 17 #include "components/sync/engine_impl/cycle/sync_cycle.h"
18 #include "components/sync/engine_impl/events/commit_request_event.h" 18 #include "components/sync/engine_impl/events/commit_request_event.h"
19 #include "components/sync/engine_impl/events/commit_response_event.h" 19 #include "components/sync/engine_impl/events/commit_response_event.h"
20 #include "components/sync/engine_impl/syncer.h" 20 #include "components/sync/engine_impl/syncer.h"
21 #include "components/sync/engine_impl/syncer_proto_util.h" 21 #include "components/sync/engine_impl/syncer_proto_util.h"
22 22
23 namespace syncer { 23 namespace syncer {
24 24
25 namespace { 25 namespace {
26 // The number of random ASCII bytes we'll add to CommitMessage. We choose 256 26 // The number of random ASCII bytes we'll add to CommitMessage. We choose 256
27 // because it is not too large (to hurt performance and compression ratio), but 27 // because it is not too large (to hurt performance and compression ratio), but
28 // it is not too small to easily be canceled out using statistical analysis. 28 // it is not too small to easily be canceled out using statistical analysis.
29 const size_t kPaddingSize = 256; 29 const size_t kPaddingSize = 256;
30
31 const char kLegalCharacters[] =
32 "abcdefghijklmnopqrstuvwxyz"
33 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34 "0123456789"
35 " .-,/\\:;";
36
37 const int first_char_index = 0;
38 const int last_char_index = sizeof(kLegalCharacters) - 2;
39
40 std::string RandomString(int length) {
maxbogue 2017/01/20 01:24:56 I was poking around trying to understand RandInt a
Gang Wu 2017/01/20 07:46:56 Done.
41 std::string random;
42 random.reserve(length);
43 for (int i = 0; i < length; ++i) {
44 random.push_back(
45 kLegalCharacters[base::RandInt(first_char_index, last_char_index)]);
46 }
47
48 return random;
30 } 49 }
31 50
51 } // namespace
52
32 Commit::Commit(ContributionMap contributions, 53 Commit::Commit(ContributionMap contributions,
33 const sync_pb::ClientToServerMessage& message, 54 const sync_pb::ClientToServerMessage& message,
34 ExtensionsActivity::Records extensions_activity_buffer) 55 ExtensionsActivity::Records extensions_activity_buffer)
35 : contributions_(std::move(contributions)), 56 : contributions_(std::move(contributions)),
36 message_(message), 57 message_(message),
37 extensions_activity_buffer_(extensions_activity_buffer), 58 extensions_activity_buffer_(extensions_activity_buffer),
38 cleaned_up_(false) {} 59 cleaned_up_(false) {}
39 60
40 Commit::~Commit() { 61 Commit::~Commit() {
41 DCHECK(cleaned_up_); 62 DCHECK(cleaned_up_);
(...skipping 20 matching lines...) Expand all
62 83
63 sync_pb::ClientToServerMessage message; 84 sync_pb::ClientToServerMessage message;
64 message.set_message_contents(sync_pb::ClientToServerMessage::COMMIT); 85 message.set_message_contents(sync_pb::ClientToServerMessage::COMMIT);
65 message.set_share(account_name); 86 message.set_share(account_name);
66 87
67 sync_pb::CommitMessage* commit_message = message.mutable_commit(); 88 sync_pb::CommitMessage* commit_message = message.mutable_commit();
68 commit_message->set_cache_guid(cache_guid); 89 commit_message->set_cache_guid(cache_guid);
69 90
70 // Set padding to mitigate CRIME attack. 91 // Set padding to mitigate CRIME attack.
71 if (base::FeatureList::IsEnabled(syncer::kSyncClientToServerCompression)) { 92 if (base::FeatureList::IsEnabled(syncer::kSyncClientToServerCompression)) {
72 commit_message->set_padding(base::RandBytesAsString(kPaddingSize)); 93 commit_message->set_padding(RandomString(kPaddingSize));
73 } 94 }
74 95
75 // Set extensions activity if bookmark commits are present. 96 // Set extensions activity if bookmark commits are present.
76 ExtensionsActivity::Records extensions_activity_buffer; 97 ExtensionsActivity::Records extensions_activity_buffer;
77 if (extensions_activity != nullptr) { 98 if (extensions_activity != nullptr) {
78 ContributionMap::const_iterator it = contributions.find(BOOKMARKS); 99 ContributionMap::const_iterator it = contributions.find(BOOKMARKS);
79 if (it != contributions.end() && it->second->GetNumEntries() != 0) { 100 if (it != contributions.end() && it->second->GetNumEntries() != 0) {
80 commit_util::AddExtensionsActivityToMessage( 101 commit_util::AddExtensionsActivityToMessage(
81 extensions_activity, &extensions_activity_buffer, commit_message); 102 extensions_activity, &extensions_activity_buffer, commit_message);
82 } 103 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 214
194 void Commit::CleanUp() { 215 void Commit::CleanUp() {
195 for (ContributionMap::const_iterator it = contributions_.begin(); 216 for (ContributionMap::const_iterator it = contributions_.begin();
196 it != contributions_.end(); ++it) { 217 it != contributions_.end(); ++it) {
197 it->second->CleanUp(); 218 it->second->CleanUp();
198 } 219 }
199 cleaned_up_ = true; 220 cleaned_up_ = true;
200 } 221 }
201 222
202 } // namespace syncer 223 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698