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

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: Remove redundant 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();
55 if (success)
56 coded_stream_.Trim();
57 return success;
55 } 58 }
56 59
57 bool UnindexedRulesetWriter::WritePendingChunk() { 60 bool UnindexedRulesetWriter::WritePendingChunk() {
58 DCHECK(!had_error()); 61 DCHECK(!had_error());
59 DCHECK_GT(pending_chunk_.url_rules_size(), 0); 62 DCHECK_GT(pending_chunk_.url_rules_size(), 0);
60 63
61 proto::FilteringRules chunk; 64 proto::FilteringRules chunk;
62 chunk.Swap(&pending_chunk_); 65 chunk.Swap(&pending_chunk_);
63 coded_stream_.WriteVarint32(base::checked_cast<uint32_t>(chunk.ByteSize())); 66 coded_stream_.WriteVarint32(base::checked_cast<uint32_t>(chunk.ByteSize()));
64 return !had_error() && chunk.SerializeToCodedStream(&coded_stream_); 67 return !had_error() && chunk.SerializeToCodedStream(&coded_stream_);
65 } 68 }
66 69
67 } // namespace subresource_filter 70 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698