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

Side by Side Diff: chrome/browser/extensions/api/declarative_content/declarative_content_page_url_condition_tracker.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header 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 "chrome/browser/extensions/api/declarative_content/declarative_content_ page_url_condition_tracker.h" 5 #include "chrome/browser/extensions/api/declarative_content/declarative_content_ page_url_condition_tracker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h"
8 #include "base/stl_util.h" 9 #include "base/stl_util.h"
9 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" 12 #include "chrome/browser/extensions/api/declarative_content/content_constants.h"
12 #include "components/url_matcher/url_matcher_factory.h" 13 #include "components/url_matcher/url_matcher_factory.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 15
15 namespace extensions { 16 namespace extensions {
16 17
17 namespace { 18 namespace {
18 19
19 const char kInvalidTypeOfParameter[] = "Attribute '%s' has an invalid type"; 20 const char kInvalidTypeOfParameter[] = "Attribute '%s' has an invalid type";
20 21
21 static url_matcher::URLMatcherConditionSet::ID g_next_id = 0; 22 static url_matcher::URLMatcherConditionSet::ID g_next_id = 0;
22 23
23 } // namespace 24 } // namespace
24 25
25 // 26 //
26 // DeclarativeContentPageUrlPredicate 27 // DeclarativeContentPageUrlPredicate
27 // 28 //
28 29
29 DeclarativeContentPageUrlPredicate::~DeclarativeContentPageUrlPredicate() { 30 DeclarativeContentPageUrlPredicate::~DeclarativeContentPageUrlPredicate() {
30 } 31 }
31 32
32 // static 33 // static
33 scoped_ptr<DeclarativeContentPageUrlPredicate> 34 std::unique_ptr<DeclarativeContentPageUrlPredicate>
34 DeclarativeContentPageUrlPredicate::Create( 35 DeclarativeContentPageUrlPredicate::Create(
35 ContentPredicateEvaluator* evaluator, 36 ContentPredicateEvaluator* evaluator,
36 url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory, 37 url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory,
37 const base::Value& value, 38 const base::Value& value,
38 std::string* error) { 39 std::string* error) {
39 scoped_refptr<url_matcher::URLMatcherConditionSet> url_matcher_condition_set; 40 scoped_refptr<url_matcher::URLMatcherConditionSet> url_matcher_condition_set;
40 const base::DictionaryValue* dict = nullptr; 41 const base::DictionaryValue* dict = nullptr;
41 if (!value.GetAsDictionary(&dict)) { 42 if (!value.GetAsDictionary(&dict)) {
42 *error = base::StringPrintf(kInvalidTypeOfParameter, 43 *error = base::StringPrintf(kInvalidTypeOfParameter,
43 declarative_content_constants::kPageUrl); 44 declarative_content_constants::kPageUrl);
44 return scoped_ptr<DeclarativeContentPageUrlPredicate>(); 45 return std::unique_ptr<DeclarativeContentPageUrlPredicate>();
45 } else { 46 } else {
46 url_matcher_condition_set = 47 url_matcher_condition_set =
47 url_matcher::URLMatcherFactory::CreateFromURLFilterDictionary( 48 url_matcher::URLMatcherFactory::CreateFromURLFilterDictionary(
48 url_matcher_condition_factory, dict, ++g_next_id, error); 49 url_matcher_condition_factory, dict, ++g_next_id, error);
49 if (!url_matcher_condition_set) 50 if (!url_matcher_condition_set)
50 return scoped_ptr<DeclarativeContentPageUrlPredicate>(); 51 return std::unique_ptr<DeclarativeContentPageUrlPredicate>();
51 return make_scoped_ptr( 52 return base::WrapUnique(new DeclarativeContentPageUrlPredicate(
52 new DeclarativeContentPageUrlPredicate(evaluator, 53 evaluator, url_matcher_condition_set));
53 url_matcher_condition_set));
54 } 54 }
55 } 55 }
56 56
57 ContentPredicateEvaluator* 57 ContentPredicateEvaluator*
58 DeclarativeContentPageUrlPredicate::GetEvaluator() const { 58 DeclarativeContentPageUrlPredicate::GetEvaluator() const {
59 return evaluator_; 59 return evaluator_;
60 } 60 }
61 61
62 DeclarativeContentPageUrlPredicate::DeclarativeContentPageUrlPredicate( 62 DeclarativeContentPageUrlPredicate::DeclarativeContentPageUrlPredicate(
63 ContentPredicateEvaluator* evaluator, 63 ContentPredicateEvaluator* evaluator,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 DeclarativeContentPageUrlConditionTracker:: 114 DeclarativeContentPageUrlConditionTracker::
115 ~DeclarativeContentPageUrlConditionTracker() { 115 ~DeclarativeContentPageUrlConditionTracker() {
116 } 116 }
117 117
118 std::string DeclarativeContentPageUrlConditionTracker:: 118 std::string DeclarativeContentPageUrlConditionTracker::
119 GetPredicateApiAttributeName() const { 119 GetPredicateApiAttributeName() const {
120 return declarative_content_constants::kPageUrl; 120 return declarative_content_constants::kPageUrl;
121 } 121 }
122 122
123 scoped_ptr<const ContentPredicate> DeclarativeContentPageUrlConditionTracker:: 123 std::unique_ptr<const ContentPredicate>
124 CreatePredicate(const Extension* extension, 124 DeclarativeContentPageUrlConditionTracker::CreatePredicate(
125 const base::Value& value, 125 const Extension* extension,
126 std::string* error) { 126 const base::Value& value,
127 std::string* error) {
127 return DeclarativeContentPageUrlPredicate::Create(this, 128 return DeclarativeContentPageUrlPredicate::Create(this,
128 url_matcher_.condition_factory(), value, error); 129 url_matcher_.condition_factory(), value, error);
129 } 130 }
130 131
131 void DeclarativeContentPageUrlConditionTracker::TrackPredicates( 132 void DeclarativeContentPageUrlConditionTracker::TrackPredicates(
132 const std::map<const void*, std::vector<const ContentPredicate*>>& 133 const std::map<const void*, std::vector<const ContentPredicate*>>&
133 predicates) { 134 predicates) {
134 if (predicates.empty()) { 135 if (predicates.empty()) {
135 // Clean up temporary condition sets created during rule creation. 136 // Clean up temporary condition sets created during rule creation.
136 url_matcher_.ClearUnusedConditionSets(); 137 url_matcher_.ClearUnusedConditionSets();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 DCHECK(ContainsKey(per_web_contents_tracker_, contents)); 221 DCHECK(ContainsKey(per_web_contents_tracker_, contents));
221 per_web_contents_tracker_.erase(contents); 222 per_web_contents_tracker_.erase(contents);
222 } 223 }
223 224
224 void DeclarativeContentPageUrlConditionTracker::UpdateMatchesForAllTrackers() { 225 void DeclarativeContentPageUrlConditionTracker::UpdateMatchesForAllTrackers() {
225 for (const auto& web_contents_tracker_pair : per_web_contents_tracker_) 226 for (const auto& web_contents_tracker_pair : per_web_contents_tracker_)
226 web_contents_tracker_pair.second->UpdateMatchesForCurrentUrl(false); 227 web_contents_tracker_pair.second->UpdateMatchesForCurrentUrl(false);
227 } 228 }
228 229
229 } // namespace extensions 230 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698