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

Side by Side Diff: chrome/common/extensions/user_script.cc

Issue 7347011: Update URLPatternSet to contain a std::set instead of std::vector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows compile errors. Created 9 years, 5 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/common/extensions/user_script.h" 5 #include "chrome/common/extensions/user_script.h"
6 6
7 #include "base/pickle.h" 7 #include "base/pickle.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 9
10 namespace { 10 namespace {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 pickle->WriteSize(globs_.size()); 114 pickle->WriteSize(globs_.size());
115 for (glob = globs_.begin(); glob != globs_.end(); ++glob) { 115 for (glob = globs_.begin(); glob != globs_.end(); ++glob) {
116 pickle->WriteString(*glob); 116 pickle->WriteString(*glob);
117 } 117 }
118 pickle->WriteSize(exclude_globs_.size()); 118 pickle->WriteSize(exclude_globs_.size());
119 for (glob = exclude_globs_.begin(); glob != exclude_globs_.end(); ++glob) { 119 for (glob = exclude_globs_.begin(); glob != exclude_globs_.end(); ++glob) {
120 pickle->WriteString(*glob); 120 pickle->WriteString(*glob);
121 } 121 }
122 122
123 // Write url patterns. 123 // Write url patterns.
124 URLPatternList pattern_list = url_set_.patterns(); 124 URLPatternSet pattern_list = url_set_;
125 pickle->WriteSize(pattern_list.size()); 125 pickle->WriteSize(pattern_list.patterns().size());
126 for (URLPatternList::const_iterator pattern = pattern_list.begin(); 126 for (URLPatternSet::const_iterator pattern = pattern_list.begin();
127 pattern != pattern_list.end(); ++pattern) { 127 pattern != pattern_list.end(); ++pattern) {
128 pickle->WriteInt(pattern->valid_schemes()); 128 pickle->WriteInt(pattern->valid_schemes());
129 pickle->WriteString(pattern->GetAsString()); 129 pickle->WriteString(pattern->GetAsString());
130 } 130 }
131 131
132 // Write js scripts. 132 // Write js scripts.
133 pickle->WriteSize(js_scripts_.size()); 133 pickle->WriteSize(js_scripts_.size());
134 for (FileList::const_iterator file = js_scripts_.begin(); 134 for (FileList::const_iterator file = js_scripts_.begin();
135 file != js_scripts_.end(); ++file) { 135 file != js_scripts_.end(); ++file) {
136 file->Pickle(pickle); 136 file->Pickle(pickle);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 CHECK(pickle.ReadInt(iter, &valid_schemes)); 184 CHECK(pickle.ReadInt(iter, &valid_schemes));
185 std::string pattern_str; 185 std::string pattern_str;
186 URLPattern pattern(valid_schemes); 186 URLPattern pattern(valid_schemes);
187 CHECK(pickle.ReadString(iter, &pattern_str)); 187 CHECK(pickle.ReadString(iter, &pattern_str));
188 188
189 // We remove the file scheme if it's not actually allowed (see Extension:: 189 // We remove the file scheme if it's not actually allowed (see Extension::
190 // LoadUserScriptHelper), but we need it temporarily while loading the 190 // LoadUserScriptHelper), but we need it temporarily while loading the
191 // pattern so that it's valid. 191 // pattern so that it's valid.
192 bool had_file_scheme = (valid_schemes & URLPattern::SCHEME_FILE) != 0; 192 bool had_file_scheme = (valid_schemes & URLPattern::SCHEME_FILE) != 0;
193 if (!had_file_scheme) 193 if (!had_file_scheme)
194 pattern.set_valid_schemes(valid_schemes | URLPattern::SCHEME_FILE); 194 pattern.SetValidSchemes(valid_schemes | URLPattern::SCHEME_FILE);
195 CHECK(URLPattern::PARSE_SUCCESS == 195 CHECK(URLPattern::PARSE_SUCCESS ==
196 pattern.Parse(pattern_str, URLPattern::IGNORE_PORTS)); 196 pattern.Parse(pattern_str, URLPattern::IGNORE_PORTS));
197 if (!had_file_scheme) 197 if (!had_file_scheme)
198 pattern.set_valid_schemes(valid_schemes); 198 pattern.SetValidSchemes(valid_schemes);
199 199
200 url_set_.AddPattern(pattern); 200 url_set_.AddPattern(pattern);
201 } 201 }
202 202
203 // Read js scripts. 203 // Read js scripts.
204 size_t num_js_files = 0; 204 size_t num_js_files = 0;
205 CHECK(pickle.ReadSize(iter, &num_js_files)); 205 CHECK(pickle.ReadSize(iter, &num_js_files));
206 js_scripts_.clear(); 206 js_scripts_.clear();
207 for (size_t i = 0; i < num_js_files; ++i) { 207 for (size_t i = 0; i < num_js_files; ++i) {
208 File file; 208 File file;
209 file.Unpickle(pickle, iter); 209 file.Unpickle(pickle, iter);
210 js_scripts_.push_back(file); 210 js_scripts_.push_back(file);
211 } 211 }
212 212
213 // Read css scripts. 213 // Read css scripts.
214 size_t num_css_files = 0; 214 size_t num_css_files = 0;
215 CHECK(pickle.ReadSize(iter, &num_css_files)); 215 CHECK(pickle.ReadSize(iter, &num_css_files));
216 css_scripts_.clear(); 216 css_scripts_.clear();
217 for (size_t i = 0; i < num_css_files; ++i) { 217 for (size_t i = 0; i < num_css_files; ++i) {
218 File file; 218 File file;
219 file.Unpickle(pickle, iter); 219 file.Unpickle(pickle, iter);
220 css_scripts_.push_back(file); 220 css_scripts_.push_back(file);
221 } 221 }
222 } 222 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/user_script.h ('k') | chrome/common/extensions/user_script_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698