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

Side by Side Diff: components/subresource_filter/core/common/unindexed_ruleset.cc

Issue 2279803002: Fix UnindexedRulesetWriter finishing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add regression test. Created 4 years, 3 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/subresource_filter/core/common/unindexed_ruleset.h" 5 #include "components/subresource_filter/core/common/unindexed_ruleset.h"
6 6
7 #include "base/numerics/safe_conversions.h" 7 #include "base/numerics/safe_conversions.h"
8 8
9 namespace subresource_filter { 9 namespace subresource_filter {
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 pending_chunk_.add_url_rules()->CopyFrom(rule); 44 pending_chunk_.add_url_rules()->CopyFrom(rule);
45 if (pending_chunk_.url_rules_size() >= max_rules_per_chunk_) { 45 if (pending_chunk_.url_rules_size() >= max_rules_per_chunk_) {
46 DCHECK_EQ(pending_chunk_.url_rules_size(), max_rules_per_chunk_); 46 DCHECK_EQ(pending_chunk_.url_rules_size(), max_rules_per_chunk_);
47 return WritePendingChunk(); 47 return WritePendingChunk();
48 } 48 }
49 return true; 49 return true;
50 } 50 }
51 51
52 bool UnindexedRulesetWriter::Finish() { 52 bool UnindexedRulesetWriter::Finish() {
53 DCHECK(!had_error()); 53 DCHECK(!had_error());
54 return !pending_chunk_.url_rules_size() || WritePendingChunk(); 54 const bool success = !pending_chunk_.url_rules_size() || WritePendingChunk();
engedy 2016/08/26 15:43:17 nit: Same here as above, feel free to return false
pkalinnikov1 2016/08/26 16:29:47 Done.
55 coded_stream_.Trim();
56 return success;
55 } 57 }
56 58
57 bool UnindexedRulesetWriter::WritePendingChunk() { 59 bool UnindexedRulesetWriter::WritePendingChunk() {
58 DCHECK(!had_error()); 60 DCHECK(!had_error());
59 DCHECK_GT(pending_chunk_.url_rules_size(), 0); 61 DCHECK_GT(pending_chunk_.url_rules_size(), 0);
60 62
61 proto::FilteringRules chunk; 63 proto::FilteringRules chunk;
62 chunk.Swap(&pending_chunk_); 64 chunk.Swap(&pending_chunk_);
63 coded_stream_.WriteVarint32(base::checked_cast<uint32_t>(chunk.ByteSize())); 65 coded_stream_.WriteVarint32(base::checked_cast<uint32_t>(chunk.ByteSize()));
64 return !had_error() && chunk.SerializeToCodedStream(&coded_stream_); 66 return !had_error() && chunk.SerializeToCodedStream(&coded_stream_);
65 } 67 }
66 68
67 } // namespace subresource_filter 69 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698