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

Side by Side Diff: extensions/browser/api/declarative_webrequest/webrequest_condition.cc

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "extensions/browser/api/declarative_webrequest/webrequest_condition.h" 5 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 void WebRequestCondition::GetURLMatcherConditionSets( 119 void WebRequestCondition::GetURLMatcherConditionSets(
120 URLMatcherConditionSet::Vector* condition_sets) const { 120 URLMatcherConditionSet::Vector* condition_sets) const {
121 if (url_matcher_conditions_.get()) 121 if (url_matcher_conditions_.get())
122 condition_sets->push_back(url_matcher_conditions_); 122 condition_sets->push_back(url_matcher_conditions_);
123 if (first_party_url_matcher_conditions_.get()) 123 if (first_party_url_matcher_conditions_.get())
124 condition_sets->push_back(first_party_url_matcher_conditions_); 124 condition_sets->push_back(first_party_url_matcher_conditions_);
125 } 125 }
126 126
127 // static 127 // static
128 scoped_ptr<WebRequestCondition> WebRequestCondition::Create( 128 std::unique_ptr<WebRequestCondition> WebRequestCondition::Create(
129 const Extension* extension, 129 const Extension* extension,
130 URLMatcherConditionFactory* url_matcher_condition_factory, 130 URLMatcherConditionFactory* url_matcher_condition_factory,
131 const base::Value& condition, 131 const base::Value& condition,
132 std::string* error) { 132 std::string* error) {
133 const base::DictionaryValue* condition_dict = NULL; 133 const base::DictionaryValue* condition_dict = NULL;
134 if (!condition.GetAsDictionary(&condition_dict)) { 134 if (!condition.GetAsDictionary(&condition_dict)) {
135 *error = kExpectedDictionary; 135 *error = kExpectedDictionary;
136 return scoped_ptr<WebRequestCondition>(); 136 return std::unique_ptr<WebRequestCondition>();
137 } 137 }
138 138
139 // Verify that we are dealing with a Condition whose type we understand. 139 // Verify that we are dealing with a Condition whose type we understand.
140 std::string instance_type; 140 std::string instance_type;
141 if (!condition_dict->GetString(keys::kInstanceTypeKey, &instance_type)) { 141 if (!condition_dict->GetString(keys::kInstanceTypeKey, &instance_type)) {
142 *error = kConditionWithoutInstanceType; 142 *error = kConditionWithoutInstanceType;
143 return scoped_ptr<WebRequestCondition>(); 143 return std::unique_ptr<WebRequestCondition>();
144 } 144 }
145 if (instance_type != keys::kRequestMatcherType) { 145 if (instance_type != keys::kRequestMatcherType) {
146 *error = kExpectedOtherConditionType; 146 *error = kExpectedOtherConditionType;
147 return scoped_ptr<WebRequestCondition>(); 147 return std::unique_ptr<WebRequestCondition>();
148 } 148 }
149 149
150 WebRequestConditionAttributes attributes; 150 WebRequestConditionAttributes attributes;
151 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set; 151 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set;
152 scoped_refptr<URLMatcherConditionSet> first_party_url_matcher_condition_set; 152 scoped_refptr<URLMatcherConditionSet> first_party_url_matcher_condition_set;
153 153
154 for (base::DictionaryValue::Iterator iter(*condition_dict); 154 for (base::DictionaryValue::Iterator iter(*condition_dict);
155 !iter.IsAtEnd(); iter.Advance()) { 155 !iter.IsAtEnd(); iter.Advance()) {
156 const std::string& condition_attribute_name = iter.key(); 156 const std::string& condition_attribute_name = iter.key();
157 const base::Value& condition_attribute_value = iter.value(); 157 const base::Value& condition_attribute_value = iter.value();
(...skipping 20 matching lines...) Expand all
178 } else { 178 } else {
179 scoped_refptr<const WebRequestConditionAttribute> attribute = 179 scoped_refptr<const WebRequestConditionAttribute> attribute =
180 WebRequestConditionAttribute::Create( 180 WebRequestConditionAttribute::Create(
181 condition_attribute_name, 181 condition_attribute_name,
182 &condition_attribute_value, 182 &condition_attribute_value,
183 error); 183 error);
184 if (attribute.get()) 184 if (attribute.get())
185 attributes.push_back(attribute); 185 attributes.push_back(attribute);
186 } 186 }
187 if (!error->empty()) 187 if (!error->empty())
188 return scoped_ptr<WebRequestCondition>(); 188 return std::unique_ptr<WebRequestCondition>();
189 } 189 }
190 190
191 scoped_ptr<WebRequestCondition> result( 191 std::unique_ptr<WebRequestCondition> result(new WebRequestCondition(
192 new WebRequestCondition(url_matcher_condition_set, 192 url_matcher_condition_set, first_party_url_matcher_condition_set,
193 first_party_url_matcher_condition_set, 193 attributes));
194 attributes));
195 194
196 if (!result->stages()) { 195 if (!result->stages()) {
197 *error = kConditionCannotBeFulfilled; 196 *error = kConditionCannotBeFulfilled;
198 return scoped_ptr<WebRequestCondition>(); 197 return std::unique_ptr<WebRequestCondition>();
199 } 198 }
200 199
201 return result; 200 return result;
202 } 201 }
203 202
204 } // namespace extensions 203 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698