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

Side by Side Diff: components/dom_distiller/core/distillable_page_detector.cc

Issue 1879613003: Convert //components/dom_distiller from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/dom_distiller/core/distillable_page_detector.h" 5 #include "components/dom_distiller/core/distillable_page_detector.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "grit/components_resources.h" 11 #include "grit/components_resources.h"
12 #include "ui/base/resource/resource_bundle.h" 12 #include "ui/base/resource/resource_bundle.h"
13 13
14 namespace dom_distiller { 14 namespace dom_distiller {
15 15
16 const DistillablePageDetector* DistillablePageDetector::GetDefault() { 16 const DistillablePageDetector* DistillablePageDetector::GetDefault() {
17 static DistillablePageDetector* detector = nullptr; 17 static DistillablePageDetector* detector = nullptr;
18 if (!detector) { 18 if (!detector) {
19 std::string serialized_proto = 19 std::string serialized_proto =
20 ResourceBundle::GetSharedInstance() 20 ResourceBundle::GetSharedInstance()
21 .GetRawDataResource(IDR_DISTILLABLE_PAGE_SERIALIZED_MODEL) 21 .GetRawDataResource(IDR_DISTILLABLE_PAGE_SERIALIZED_MODEL)
22 .as_string(); 22 .as_string();
23 scoped_ptr<AdaBoostProto> proto(new AdaBoostProto); 23 std::unique_ptr<AdaBoostProto> proto(new AdaBoostProto);
24 CHECK(proto->ParseFromString(serialized_proto)); 24 CHECK(proto->ParseFromString(serialized_proto));
25 detector = new DistillablePageDetector(std::move(proto)); 25 detector = new DistillablePageDetector(std::move(proto));
26 } 26 }
27 return detector; 27 return detector;
28 } 28 }
29 29
30 const DistillablePageDetector* DistillablePageDetector::GetNewModel() { 30 const DistillablePageDetector* DistillablePageDetector::GetNewModel() {
31 static DistillablePageDetector* detector = nullptr; 31 static DistillablePageDetector* detector = nullptr;
32 if (!detector) { 32 if (!detector) {
33 std::string serialized_proto = 33 std::string serialized_proto =
34 ResourceBundle::GetSharedInstance() 34 ResourceBundle::GetSharedInstance()
35 .GetRawDataResource(IDR_DISTILLABLE_PAGE_SERIALIZED_MODEL_NEW) 35 .GetRawDataResource(IDR_DISTILLABLE_PAGE_SERIALIZED_MODEL_NEW)
36 .as_string(); 36 .as_string();
37 scoped_ptr<AdaBoostProto> proto(new AdaBoostProto); 37 std::unique_ptr<AdaBoostProto> proto(new AdaBoostProto);
38 CHECK(proto->ParseFromString(serialized_proto)); 38 CHECK(proto->ParseFromString(serialized_proto));
39 detector = new DistillablePageDetector(std::move(proto)); 39 detector = new DistillablePageDetector(std::move(proto));
40 } 40 }
41 return detector; 41 return detector;
42 } 42 }
43 43
44 const DistillablePageDetector* DistillablePageDetector::GetLongPageModel() { 44 const DistillablePageDetector* DistillablePageDetector::GetLongPageModel() {
45 static DistillablePageDetector* detector = nullptr; 45 static DistillablePageDetector* detector = nullptr;
46 if (!detector) { 46 if (!detector) {
47 std::string serialized_proto = 47 std::string serialized_proto =
48 ResourceBundle::GetSharedInstance() 48 ResourceBundle::GetSharedInstance()
49 .GetRawDataResource(IDR_LONG_PAGE_SERIALIZED_MODEL) 49 .GetRawDataResource(IDR_LONG_PAGE_SERIALIZED_MODEL)
50 .as_string(); 50 .as_string();
51 scoped_ptr<AdaBoostProto> proto(new AdaBoostProto); 51 std::unique_ptr<AdaBoostProto> proto(new AdaBoostProto);
52 CHECK(proto->ParseFromString(serialized_proto)); 52 CHECK(proto->ParseFromString(serialized_proto));
53 detector = new DistillablePageDetector(std::move(proto)); 53 detector = new DistillablePageDetector(std::move(proto));
54 } 54 }
55 return detector; 55 return detector;
56 } 56 }
57 57
58 DistillablePageDetector::DistillablePageDetector( 58 DistillablePageDetector::DistillablePageDetector(
59 scoped_ptr<AdaBoostProto> proto) 59 std::unique_ptr<AdaBoostProto> proto)
60 : proto_(std::move(proto)), threshold_(0.0) { 60 : proto_(std::move(proto)), threshold_(0.0) {
61 CHECK(proto_->num_stumps() == proto_->stump_size()); 61 CHECK(proto_->num_stumps() == proto_->stump_size());
62 for (int i = 0; i < proto_->num_stumps(); ++i) { 62 for (int i = 0; i < proto_->num_stumps(); ++i) {
63 const StumpProto& stump = proto_->stump(i); 63 const StumpProto& stump = proto_->stump(i);
64 CHECK(stump.feature_number() >= 0); 64 CHECK(stump.feature_number() >= 0);
65 CHECK(stump.feature_number() < proto_->num_features()); 65 CHECK(stump.feature_number() < proto_->num_features());
66 threshold_ += stump.weight() / 2.0; 66 threshold_ += stump.weight() / 2.0;
67 } 67 }
68 } 68 }
69 69
(...skipping 18 matching lines...) Expand all
88 } 88 }
89 } 89 }
90 return score; 90 return score;
91 } 91 }
92 92
93 double DistillablePageDetector::GetThreshold() const { 93 double DistillablePageDetector::GetThreshold() const {
94 return threshold_; 94 return threshold_;
95 } 95 }
96 96
97 } // namespace dom_distiller 97 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698