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

Side by Side Diff: components/subresource_filter/core/browser/ruleset_service.cc

Issue 2404823002: Fix error handling in POSIX version of the base::File::GetLength. (Closed)
Patch Set: Fix error handling in POSIX version of the base::File::GetLength. Created 4 years 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/browser/ruleset_service.h" 5 #include "components/subresource_filter/core/browser/ruleset_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 DCHECK(indexed_version.IsValid()); 339 DCHECK(indexed_version.IsValid());
340 return indexed_version; 340 return indexed_version;
341 } 341 }
342 342
343 // static 343 // static
344 bool RulesetService::IndexRuleset(base::File unindexed_ruleset_file, 344 bool RulesetService::IndexRuleset(base::File unindexed_ruleset_file,
345 RulesetIndexer* indexer) { 345 RulesetIndexer* indexer) {
346 SCOPED_UMA_HISTOGRAM_TIMER("SubresourceFilter.IndexRuleset.WallDuration"); 346 SCOPED_UMA_HISTOGRAM_TIMER("SubresourceFilter.IndexRuleset.WallDuration");
347 347
348 int64_t unindexed_ruleset_size = unindexed_ruleset_file.GetLength(); 348 int64_t unindexed_ruleset_size = unindexed_ruleset_file.GetLength();
349 if (unindexed_ruleset_size < 0)
350 return false;
349 CopyingFileInputStream copying_stream(std::move(unindexed_ruleset_file)); 351 CopyingFileInputStream copying_stream(std::move(unindexed_ruleset_file));
350 google::protobuf::io::CopyingInputStreamAdaptor zero_copy_stream_adaptor( 352 google::protobuf::io::CopyingInputStreamAdaptor zero_copy_stream_adaptor(
351 &copying_stream, 4096 /* buffer_size */); 353 &copying_stream, 4096 /* buffer_size */);
352 UnindexedRulesetReader reader(&zero_copy_stream_adaptor); 354 UnindexedRulesetReader reader(&zero_copy_stream_adaptor);
353 355
354 size_t num_unsupported_rules = 0; 356 size_t num_unsupported_rules = 0;
355 proto::FilteringRules ruleset_chunk; 357 proto::FilteringRules ruleset_chunk;
356 while (reader.ReadNextChunk(&ruleset_chunk)) { 358 while (reader.ReadNextChunk(&ruleset_chunk)) {
357 for (const proto::UrlRule& rule : ruleset_chunk.url_rules()) { 359 for (const proto::UrlRule& rule : ruleset_chunk.url_rules()) {
358 if (!indexer->AddUrlRule(rule)) 360 if (!indexer->AddUrlRule(rule))
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 // version. Bail out. 495 // version. Bail out.
494 DCHECK(ruleset_data_); 496 DCHECK(ruleset_data_);
495 if (!ruleset_data_->IsValid()) 497 if (!ruleset_data_->IsValid())
496 return; 498 return;
497 499
498 DCHECK_EQ(error, base::File::Error::FILE_OK); 500 DCHECK_EQ(error, base::File::Error::FILE_OK);
499 delegate_->PublishNewRulesetVersion(ruleset_data_->DuplicateFile()); 501 delegate_->PublishNewRulesetVersion(ruleset_data_->DuplicateFile());
500 } 502 }
501 503
502 } // namespace subresource_filter 504 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698