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

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: change the way to random string 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 std::string RandASCIIString(size_t length) {
32 std::string result;
33 const int kMin = static_cast<int>(' ');
34 const int kMax = static_cast<int>('~');
35 result.reserve(length);
36 for (size_t i = 0; i < length; ++i)
37 result.push_back(static_cast<char>(base::RandInt(kMin, kMax)));
38 return result;
30 } 39 }
31 40
41 } // namespace
42
32 Commit::Commit(ContributionMap contributions, 43 Commit::Commit(ContributionMap contributions,
33 const sync_pb::ClientToServerMessage& message, 44 const sync_pb::ClientToServerMessage& message,
34 ExtensionsActivity::Records extensions_activity_buffer) 45 ExtensionsActivity::Records extensions_activity_buffer)
35 : contributions_(std::move(contributions)), 46 : contributions_(std::move(contributions)),
36 message_(message), 47 message_(message),
37 extensions_activity_buffer_(extensions_activity_buffer), 48 extensions_activity_buffer_(extensions_activity_buffer),
38 cleaned_up_(false) {} 49 cleaned_up_(false) {}
39 50
40 Commit::~Commit() { 51 Commit::~Commit() {
41 DCHECK(cleaned_up_); 52 DCHECK(cleaned_up_);
(...skipping 20 matching lines...) Expand all
62 73
63 sync_pb::ClientToServerMessage message; 74 sync_pb::ClientToServerMessage message;
64 message.set_message_contents(sync_pb::ClientToServerMessage::COMMIT); 75 message.set_message_contents(sync_pb::ClientToServerMessage::COMMIT);
65 message.set_share(account_name); 76 message.set_share(account_name);
66 77
67 sync_pb::CommitMessage* commit_message = message.mutable_commit(); 78 sync_pb::CommitMessage* commit_message = message.mutable_commit();
68 commit_message->set_cache_guid(cache_guid); 79 commit_message->set_cache_guid(cache_guid);
69 80
70 // Set padding to mitigate CRIME attack. 81 // Set padding to mitigate CRIME attack.
71 if (base::FeatureList::IsEnabled(syncer::kSyncClientToServerCompression)) { 82 if (base::FeatureList::IsEnabled(syncer::kSyncClientToServerCompression)) {
72 commit_message->set_padding(base::RandBytesAsString(kPaddingSize)); 83 commit_message->set_padding(RandASCIIString(kPaddingSize));
73 } 84 }
74 85
75 // Set extensions activity if bookmark commits are present. 86 // Set extensions activity if bookmark commits are present.
76 ExtensionsActivity::Records extensions_activity_buffer; 87 ExtensionsActivity::Records extensions_activity_buffer;
77 if (extensions_activity != nullptr) { 88 if (extensions_activity != nullptr) {
78 ContributionMap::const_iterator it = contributions.find(BOOKMARKS); 89 ContributionMap::const_iterator it = contributions.find(BOOKMARKS);
79 if (it != contributions.end() && it->second->GetNumEntries() != 0) { 90 if (it != contributions.end() && it->second->GetNumEntries() != 0) {
80 commit_util::AddExtensionsActivityToMessage( 91 commit_util::AddExtensionsActivityToMessage(
81 extensions_activity, &extensions_activity_buffer, commit_message); 92 extensions_activity, &extensions_activity_buffer, commit_message);
82 } 93 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 204
194 void Commit::CleanUp() { 205 void Commit::CleanUp() {
195 for (ContributionMap::const_iterator it = contributions_.begin(); 206 for (ContributionMap::const_iterator it = contributions_.begin();
196 it != contributions_.end(); ++it) { 207 it != contributions_.end(); ++it) {
197 it->second->CleanUp(); 208 it->second->CleanUp();
198 } 209 }
199 cleaned_up_ = true; 210 cleaned_up_ = true;
200 } 211 }
201 212
202 } // namespace syncer 213 } // 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