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

Side by Side Diff: extensions/browser/api/declarative/declarative_rule.h

Issue 1854993002: [Extensions] Remove linked_ptr entirely from extensions generated code (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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 // DeclarativeRule<>, DeclarativeConditionSet<>, and DeclarativeActionSet<> 5 // DeclarativeRule<>, DeclarativeConditionSet<>, and DeclarativeActionSet<>
6 // templates usable with multiple different declarativeFoo systems. These are 6 // templates usable with multiple different declarativeFoo systems. These are
7 // templated on the Condition and Action types that define the behavior of a 7 // templated on the Condition and Action types that define the behavior of a
8 // particular declarative event. 8 // particular declarative event.
9 9
10 #ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_DECLARATIVE_RULE_H__ 10 #ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_DECLARATIVE_RULE_H__
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // // If the Condition needs to be filtered by some URLMatcherConditionSets, 53 // // If the Condition needs to be filtered by some URLMatcherConditionSets,
54 // // append them to |condition_sets|. 54 // // append them to |condition_sets|.
55 // // DeclarativeConditionSet::GetURLMatcherConditionSets forwards here. 55 // // DeclarativeConditionSet::GetURLMatcherConditionSets forwards here.
56 // void GetURLMatcherConditionSets( 56 // void GetURLMatcherConditionSets(
57 // URLMatcherConditionSet::Vector* condition_sets); 57 // URLMatcherConditionSet::Vector* condition_sets);
58 // // |match_data| passed through from DeclarativeConditionSet::IsFulfilled. 58 // // |match_data| passed through from DeclarativeConditionSet::IsFulfilled.
59 // bool IsFulfilled(const ConditionT::MatchData& match_data); 59 // bool IsFulfilled(const ConditionT::MatchData& match_data);
60 template<typename ConditionT> 60 template<typename ConditionT>
61 class DeclarativeConditionSet { 61 class DeclarativeConditionSet {
62 public: 62 public:
63 typedef std::vector<linked_ptr<base::Value>> Values; 63 typedef std::vector<scoped_ptr<base::Value>> Values;
64 typedef std::vector<linked_ptr<const ConditionT> > Conditions; 64 typedef std::vector<linked_ptr<const ConditionT> > Conditions;
65 typedef typename Conditions::const_iterator const_iterator; 65 typedef typename Conditions::const_iterator const_iterator;
66 66
67 // Factory method that creates a DeclarativeConditionSet for |extension| 67 // Factory method that creates a DeclarativeConditionSet for |extension|
68 // according to the JSON array |conditions| passed by the extension API. Sets 68 // according to the JSON array |conditions| passed by the extension API. Sets
69 // |error| and returns NULL in case of an error. 69 // |error| and returns NULL in case of an error.
70 static scoped_ptr<DeclarativeConditionSet> Create( 70 static scoped_ptr<DeclarativeConditionSet> Create(
71 const Extension* extension, 71 const Extension* extension,
72 url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory, 72 url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory,
73 const Values& condition_values, 73 const Values& condition_values,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // // Return the minimum priority of rules that can be evaluated after this 136 // // Return the minimum priority of rules that can be evaluated after this
137 // // action runs. A suitable default value is MIN_INT. 137 // // action runs. A suitable default value is MIN_INT.
138 // int minimum_priority() const; 138 // int minimum_priority() const;
139 // 139 //
140 // TODO(battre): As DeclarativeActionSet can become the single owner of all 140 // TODO(battre): As DeclarativeActionSet can become the single owner of all
141 // actions, we can optimize here by making some of them singletons (e.g. Cancel 141 // actions, we can optimize here by making some of them singletons (e.g. Cancel
142 // actions). 142 // actions).
143 template<typename ActionT> 143 template<typename ActionT>
144 class DeclarativeActionSet { 144 class DeclarativeActionSet {
145 public: 145 public:
146 typedef std::vector<linked_ptr<base::Value>> Values; 146 typedef std::vector<scoped_ptr<base::Value>> Values;
147 typedef std::vector<scoped_refptr<const ActionT> > Actions; 147 typedef std::vector<scoped_refptr<const ActionT> > Actions;
148 148
149 explicit DeclarativeActionSet(const Actions& actions); 149 explicit DeclarativeActionSet(const Actions& actions);
150 150
151 // Factory method that instantiates a DeclarativeActionSet for |extension| 151 // Factory method that instantiates a DeclarativeActionSet for |extension|
152 // according to |actions| which represents the array of actions received from 152 // according to |actions| which represents the array of actions received from
153 // the extension API. 153 // the extension API.
154 static scoped_ptr<DeclarativeActionSet> Create( 154 static scoped_ptr<DeclarativeActionSet> Create(
155 content::BrowserContext* browser_context, 155 content::BrowserContext* browser_context,
156 const Extension* extension, 156 const Extension* extension,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // static 302 // static
303 template <typename ConditionT> 303 template <typename ConditionT>
304 scoped_ptr<DeclarativeConditionSet<ConditionT>> 304 scoped_ptr<DeclarativeConditionSet<ConditionT>>
305 DeclarativeConditionSet<ConditionT>::Create( 305 DeclarativeConditionSet<ConditionT>::Create(
306 const Extension* extension, 306 const Extension* extension,
307 url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory, 307 url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory,
308 const Values& condition_values, 308 const Values& condition_values,
309 std::string* error) { 309 std::string* error) {
310 Conditions result; 310 Conditions result;
311 311
312 for (const linked_ptr<base::Value>& value : condition_values) { 312 for (const scoped_ptr<base::Value>& value : condition_values) {
313 CHECK(value.get()); 313 CHECK(value.get());
314 scoped_ptr<ConditionT> condition = ConditionT::Create( 314 scoped_ptr<ConditionT> condition = ConditionT::Create(
315 extension, url_matcher_condition_factory, *value, error); 315 extension, url_matcher_condition_factory, *value, error);
316 if (!error->empty()) 316 if (!error->empty())
317 return scoped_ptr<DeclarativeConditionSet>(); 317 return scoped_ptr<DeclarativeConditionSet>();
318 result.push_back(make_linked_ptr(condition.release())); 318 result.push_back(make_linked_ptr(condition.release()));
319 } 319 }
320 320
321 URLMatcherIdToCondition match_id_to_condition; 321 URLMatcherIdToCondition match_id_to_condition;
322 std::vector<const ConditionT*> conditions_without_urls; 322 std::vector<const ConditionT*> conditions_without_urls;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 scoped_ptr<DeclarativeActionSet<ActionT>> DeclarativeActionSet<ActionT>::Create( 360 scoped_ptr<DeclarativeActionSet<ActionT>> DeclarativeActionSet<ActionT>::Create(
361 content::BrowserContext* browser_context, 361 content::BrowserContext* browser_context,
362 const Extension* extension, 362 const Extension* extension,
363 const Values& action_values, 363 const Values& action_values,
364 std::string* error, 364 std::string* error,
365 bool* bad_message) { 365 bool* bad_message) {
366 *error = ""; 366 *error = "";
367 *bad_message = false; 367 *bad_message = false;
368 Actions result; 368 Actions result;
369 369
370 for (const linked_ptr<base::Value>& value : action_values) { 370 for (const scoped_ptr<base::Value>& value : action_values) {
371 CHECK(value.get()); 371 CHECK(value.get());
372 scoped_refptr<const ActionT> action = 372 scoped_refptr<const ActionT> action =
373 ActionT::Create(browser_context, extension, *value, error, bad_message); 373 ActionT::Create(browser_context, extension, *value, error, bad_message);
374 if (!error->empty() || *bad_message) 374 if (!error->empty() || *bad_message)
375 return scoped_ptr<DeclarativeActionSet>(); 375 return scoped_ptr<DeclarativeActionSet>();
376 result.push_back(action); 376 result.push_back(action);
377 } 377 }
378 378
379 return scoped_ptr<DeclarativeActionSet>(new DeclarativeActionSet(result)); 379 return scoped_ptr<DeclarativeActionSet>(new DeclarativeActionSet(result));
380 } 380 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 } 497 }
498 498
499 template<typename ConditionT, typename ActionT> 499 template<typename ConditionT, typename ActionT>
500 int DeclarativeRule<ConditionT, ActionT>::GetMinimumPriority() const { 500 int DeclarativeRule<ConditionT, ActionT>::GetMinimumPriority() const {
501 return actions_->GetMinimumPriority(); 501 return actions_->GetMinimumPriority();
502 } 502 }
503 503
504 } // namespace extensions 504 } // namespace extensions
505 505
506 #endif // EXTENSIONS_BROWSER_API_DECLARATIVE_DECLARATIVE_RULE_H__ 506 #endif // EXTENSIONS_BROWSER_API_DECLARATIVE_DECLARATIVE_RULE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698