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

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

Issue 16703018: Rewrite scoped_ptr<T>(NULL) to use the default ctor in chrome/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
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 "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion.h" 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion.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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 121 }
122 122
123 // static 123 // static
124 scoped_ptr<WebRequestCondition> WebRequestCondition::Create( 124 scoped_ptr<WebRequestCondition> WebRequestCondition::Create(
125 URLMatcherConditionFactory* url_matcher_condition_factory, 125 URLMatcherConditionFactory* url_matcher_condition_factory,
126 const base::Value& condition, 126 const base::Value& condition,
127 std::string* error) { 127 std::string* error) {
128 const base::DictionaryValue* condition_dict = NULL; 128 const base::DictionaryValue* condition_dict = NULL;
129 if (!condition.GetAsDictionary(&condition_dict)) { 129 if (!condition.GetAsDictionary(&condition_dict)) {
130 *error = kExpectedDictionary; 130 *error = kExpectedDictionary;
131 return scoped_ptr<WebRequestCondition>(NULL); 131 return scoped_ptr<WebRequestCondition>();
132 } 132 }
133 133
134 // Verify that we are dealing with a Condition whose type we understand. 134 // Verify that we are dealing with a Condition whose type we understand.
135 std::string instance_type; 135 std::string instance_type;
136 if (!condition_dict->GetString(keys::kInstanceTypeKey, &instance_type)) { 136 if (!condition_dict->GetString(keys::kInstanceTypeKey, &instance_type)) {
137 *error = kConditionWithoutInstanceType; 137 *error = kConditionWithoutInstanceType;
138 return scoped_ptr<WebRequestCondition>(NULL); 138 return scoped_ptr<WebRequestCondition>();
139 } 139 }
140 if (instance_type != keys::kRequestMatcherType) { 140 if (instance_type != keys::kRequestMatcherType) {
141 *error = kExpectedOtherConditionType; 141 *error = kExpectedOtherConditionType;
142 return scoped_ptr<WebRequestCondition>(NULL); 142 return scoped_ptr<WebRequestCondition>();
143 } 143 }
144 144
145 WebRequestConditionAttributes attributes; 145 WebRequestConditionAttributes attributes;
146 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set; 146 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set;
147 scoped_refptr<URLMatcherConditionSet> first_party_url_matcher_condition_set; 147 scoped_refptr<URLMatcherConditionSet> first_party_url_matcher_condition_set;
148 148
149 for (base::DictionaryValue::Iterator iter(*condition_dict); 149 for (base::DictionaryValue::Iterator iter(*condition_dict);
150 !iter.IsAtEnd(); iter.Advance()) { 150 !iter.IsAtEnd(); iter.Advance()) {
151 const std::string& condition_attribute_name = iter.key(); 151 const std::string& condition_attribute_name = iter.key();
152 const Value& condition_attribute_value = iter.value(); 152 const Value& condition_attribute_value = iter.value();
(...skipping 20 matching lines...) Expand all
173 } else { 173 } else {
174 scoped_refptr<const WebRequestConditionAttribute> attribute = 174 scoped_refptr<const WebRequestConditionAttribute> attribute =
175 WebRequestConditionAttribute::Create( 175 WebRequestConditionAttribute::Create(
176 condition_attribute_name, 176 condition_attribute_name,
177 &condition_attribute_value, 177 &condition_attribute_value,
178 error); 178 error);
179 if (attribute.get()) 179 if (attribute.get())
180 attributes.push_back(attribute); 180 attributes.push_back(attribute);
181 } 181 }
182 if (!error->empty()) 182 if (!error->empty())
183 return scoped_ptr<WebRequestCondition>(NULL); 183 return scoped_ptr<WebRequestCondition>();
184 } 184 }
185 185
186 scoped_ptr<WebRequestCondition> result( 186 scoped_ptr<WebRequestCondition> result(
187 new WebRequestCondition(url_matcher_condition_set, 187 new WebRequestCondition(url_matcher_condition_set,
188 first_party_url_matcher_condition_set, 188 first_party_url_matcher_condition_set,
189 attributes)); 189 attributes));
190 190
191 if (!result->stages()) { 191 if (!result->stages()) {
192 *error = kConditionCannotBeFulfilled; 192 *error = kConditionCannotBeFulfilled;
193 return scoped_ptr<WebRequestCondition>(NULL); 193 return scoped_ptr<WebRequestCondition>();
194 } 194 }
195 195
196 return result.Pass(); 196 return result.Pass();
197 } 197 }
198 198
199 } // namespace extensions 199 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698