| 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 "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/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/rand_util.h" |
| 10 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 11 #include "components/sync/base/data_type_histogram.h" | 13 #include "components/sync/base/data_type_histogram.h" |
| 12 #include "components/sync/engine/events/commit_request_event.h" | 14 #include "components/sync/engine/events/commit_request_event.h" |
| 13 #include "components/sync/engine/events/commit_response_event.h" | 15 #include "components/sync/engine/events/commit_response_event.h" |
| 16 #include "components/sync/engine/net/http_bridge.h" |
| 14 #include "components/sync/engine_impl/commit_processor.h" | 17 #include "components/sync/engine_impl/commit_processor.h" |
| 15 #include "components/sync/engine_impl/commit_util.h" | 18 #include "components/sync/engine_impl/commit_util.h" |
| 16 #include "components/sync/engine_impl/cycle/sync_cycle.h" | 19 #include "components/sync/engine_impl/cycle/sync_cycle.h" |
| 17 #include "components/sync/engine_impl/syncer.h" | 20 #include "components/sync/engine_impl/syncer.h" |
| 18 #include "components/sync/engine_impl/syncer_proto_util.h" | 21 #include "components/sync/engine_impl/syncer_proto_util.h" |
| 19 | 22 |
| 20 namespace syncer { | 23 namespace syncer { |
| 21 | 24 |
| 25 namespace { |
| 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 |
| 28 // it is not too small to easily be canceled out using statistical analysis. |
| 29 const size_t kPaddingSize = 256; |
| 30 } |
| 31 |
| 22 Commit::Commit(ContributionMap contributions, | 32 Commit::Commit(ContributionMap contributions, |
| 23 const sync_pb::ClientToServerMessage& message, | 33 const sync_pb::ClientToServerMessage& message, |
| 24 ExtensionsActivity::Records extensions_activity_buffer) | 34 ExtensionsActivity::Records extensions_activity_buffer) |
| 25 : contributions_(std::move(contributions)), | 35 : contributions_(std::move(contributions)), |
| 26 message_(message), | 36 message_(message), |
| 27 extensions_activity_buffer_(extensions_activity_buffer), | 37 extensions_activity_buffer_(extensions_activity_buffer), |
| 28 cleaned_up_(false) {} | 38 cleaned_up_(false) {} |
| 29 | 39 |
| 30 Commit::~Commit() { | 40 Commit::~Commit() { |
| 31 DCHECK(cleaned_up_); | 41 DCHECK(cleaned_up_); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 50 if (contributions.empty()) | 60 if (contributions.empty()) |
| 51 return nullptr; | 61 return nullptr; |
| 52 | 62 |
| 53 sync_pb::ClientToServerMessage message; | 63 sync_pb::ClientToServerMessage message; |
| 54 message.set_message_contents(sync_pb::ClientToServerMessage::COMMIT); | 64 message.set_message_contents(sync_pb::ClientToServerMessage::COMMIT); |
| 55 message.set_share(account_name); | 65 message.set_share(account_name); |
| 56 | 66 |
| 57 sync_pb::CommitMessage* commit_message = message.mutable_commit(); | 67 sync_pb::CommitMessage* commit_message = message.mutable_commit(); |
| 58 commit_message->set_cache_guid(cache_guid); | 68 commit_message->set_cache_guid(cache_guid); |
| 59 | 69 |
| 70 // Set padding to mitigate CRIME attack. |
| 71 if (base::FeatureList::IsEnabled(syncer::kSyncClientToServerCompression)) { |
| 72 commit_message->set_padding(base::RandBytesAsString(kPaddingSize)); |
| 73 } |
| 74 |
| 60 // Set extensions activity if bookmark commits are present. | 75 // Set extensions activity if bookmark commits are present. |
| 61 ExtensionsActivity::Records extensions_activity_buffer; | 76 ExtensionsActivity::Records extensions_activity_buffer; |
| 62 ContributionMap::const_iterator it = contributions.find(BOOKMARKS); | 77 ContributionMap::const_iterator it = contributions.find(BOOKMARKS); |
| 63 if (it != contributions.end() && it->second->GetNumEntries() != 0) { | 78 if (it != contributions.end() && it->second->GetNumEntries() != 0) { |
| 64 commit_util::AddExtensionsActivityToMessage( | 79 commit_util::AddExtensionsActivityToMessage( |
| 65 extensions_activity, &extensions_activity_buffer, commit_message); | 80 extensions_activity, &extensions_activity_buffer, commit_message); |
| 66 } | 81 } |
| 67 | 82 |
| 68 // Set the client config params. | 83 // Set the client config params. |
| 69 commit_util::AddClientConfigParamsToMessage( | 84 commit_util::AddClientConfigParamsToMessage( |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 190 |
| 176 void Commit::CleanUp() { | 191 void Commit::CleanUp() { |
| 177 for (ContributionMap::const_iterator it = contributions_.begin(); | 192 for (ContributionMap::const_iterator it = contributions_.begin(); |
| 178 it != contributions_.end(); ++it) { | 193 it != contributions_.end(); ++it) { |
| 179 it->second->CleanUp(); | 194 it->second->CleanUp(); |
| 180 } | 195 } |
| 181 cleaned_up_ = true; | 196 cleaned_up_ = true; |
| 182 } | 197 } |
| 183 | 198 |
| 184 } // namespace syncer | 199 } // namespace syncer |
| OLD | NEW |