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

Side by Side Diff: chrome/browser/extensions/api/omnibox/omnibox_api.cc

Issue 10837044: Correct const accessors in base/values.(h|cc), Part II (ListValue) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: David's comments Created 8 years, 4 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 "chrome/browser/extensions/api/omnibox/omnibox_api.h" 5 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return false; 172 return false;
173 } 173 }
174 } else if (value.HasKey(kSuggestionDescriptionStylesRaw)) { 174 } else if (value.HasKey(kSuggestionDescriptionStylesRaw)) {
175 // This version comes from ToValue(), which we use to persist to disk. 175 // This version comes from ToValue(), which we use to persist to disk.
176 const ListValue* styles = NULL; 176 const ListValue* styles = NULL;
177 if (!value.GetList(kSuggestionDescriptionStylesRaw, &styles) || 177 if (!value.GetList(kSuggestionDescriptionStylesRaw, &styles) ||
178 styles->empty()) { 178 styles->empty()) {
179 return false; 179 return false;
180 } 180 }
181 for (size_t i = 0; i < styles->GetSize(); ++i) { 181 for (size_t i = 0; i < styles->GetSize(); ++i) {
182 base::DictionaryValue* style = NULL; 182 const base::DictionaryValue* style = NULL;
183 int offset, type; 183 int offset, type;
184 if (!styles->GetDictionary(i, &style)) 184 if (!styles->GetDictionary(i, &style))
185 return false; 185 return false;
186 if (!style->GetInteger(kDescriptionStylesType, &type)) 186 if (!style->GetInteger(kDescriptionStylesType, &type))
187 return false; 187 return false;
188 if (!style->GetInteger(kDescriptionStylesOffset, &offset)) 188 if (!style->GetInteger(kDescriptionStylesOffset, &offset))
189 return false; 189 return false;
190 description_styles.push_back(ACMatchClassification(offset, type)); 190 description_styles.push_back(ACMatchClassification(offset, type));
191 } 191 }
192 } else { 192 } else {
193 description_styles.push_back( 193 description_styles.push_back(
194 ACMatchClassification(0, ACMatchClassification::NONE)); 194 ACMatchClassification(0, ACMatchClassification::NONE));
195 } 195 }
196 196
197 return true; 197 return true;
198 } 198 }
199 199
200 bool ExtensionOmniboxSuggestion::ReadStylesFromValue( 200 bool ExtensionOmniboxSuggestion::ReadStylesFromValue(
201 const ListValue& styles_value) { 201 const ListValue& styles_value) {
202 description_styles.clear(); 202 description_styles.clear();
203 203
204 // Step 1: Build a vector of styles, 1 per character of description text. 204 // Step 1: Build a vector of styles, 1 per character of description text.
205 std::vector<int> styles; 205 std::vector<int> styles;
206 styles.resize(description.length()); // sets all styles to 0 206 styles.resize(description.length()); // sets all styles to 0
207 207
208 for (size_t i = 0; i < styles_value.GetSize(); ++i) { 208 for (size_t i = 0; i < styles_value.GetSize(); ++i) {
209 DictionaryValue* style; 209 const DictionaryValue* style;
210 std::string type; 210 std::string type;
211 int offset; 211 int offset;
212 int length; 212 int length;
213 if (!styles_value.GetDictionary(i, &style)) 213 if (!styles_value.GetDictionary(i, &style))
214 return false; 214 return false;
215 if (!style->GetString(kDescriptionStylesType, &type)) 215 if (!style->GetString(kDescriptionStylesType, &type))
216 return false; 216 return false;
217 if (!style->GetInteger(kDescriptionStylesOffset, &offset)) 217 if (!style->GetInteger(kDescriptionStylesOffset, &offset))
218 return false; 218 return false;
219 if (!style->GetInteger(kDescriptionStylesLength, &length) || length < 0) 219 if (!style->GetInteger(kDescriptionStylesLength, &length) || length < 0)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 for (size_t i = 0; i < description_styles.size(); ++i) { 303 for (size_t i = 0; i < description_styles.size(); ++i) {
304 if (description_styles[i].offset > placeholder) 304 if (description_styles[i].offset > placeholder)
305 description_styles[i].offset += replacement.length() - 2; 305 description_styles[i].offset += replacement.length() - 2;
306 } 306 }
307 } 307 }
308 308
309 match->contents.assign(description); 309 match->contents.assign(description);
310 } 310 }
311 311
312 } // namespace extensions 312 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/management/management_api.cc ('k') | chrome/browser/extensions/api/record/record_api_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698