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

Side by Side Diff: chrome/browser/extensions/user_script_master.cc

Issue 31008: Coalesce more hardcoded schemes to using predefined constants. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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/user_script_master.h" 5 #include "chrome/browser/extensions/user_script_master.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/pickle.h" 13 #include "base/pickle.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "chrome/common/notification_service.h" 15 #include "chrome/common/notification_service.h"
16 #include "chrome/common/stl_util-inl.h" 16 #include "chrome/common/stl_util-inl.h"
17 #include "chrome/common/url_constants.h"
17 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
18 19
19 // Defined in extension.h.
20 extern const char kExtensionURLScheme[];
21 extern const char kUserScriptURLScheme[];
22
23 // static 20 // static
24 bool GetDeclarationValue(const StringPiece& line, const StringPiece& prefix, 21 bool GetDeclarationValue(const StringPiece& line, const StringPiece& prefix,
25 std::string* value) { 22 std::string* value) {
26 if (!line.starts_with(prefix)) 23 if (!line.starts_with(prefix))
27 return false; 24 return false;
28 25
29 std::string temp(line.data() + prefix.length(), 26 std::string temp(line.data() + prefix.length(),
30 line.length() - prefix.length()); 27 line.length() - prefix.length());
31 TrimWhitespace(temp, TRIM_ALL, value); 28 TrimWhitespace(temp, TRIM_ALL, value);
32 return true; 29 return true;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 if (!file_util::DirectoryExists(script_dir)) 148 if (!file_util::DirectoryExists(script_dir))
152 file_util::CreateDirectory(script_dir); 149 file_util::CreateDirectory(script_dir);
153 150
154 file_util::FileEnumerator enumerator(script_dir, false, 151 file_util::FileEnumerator enumerator(script_dir, false,
155 file_util::FileEnumerator::FILES, 152 file_util::FileEnumerator::FILES,
156 FILE_PATH_LITERAL("*.user.js")); 153 FILE_PATH_LITERAL("*.user.js"));
157 for (FilePath file = enumerator.Next(); !file.value().empty(); 154 for (FilePath file = enumerator.Next(); !file.value().empty();
158 file = enumerator.Next()) { 155 file = enumerator.Next()) {
159 all_scripts.push_back(UserScript()); 156 all_scripts.push_back(UserScript());
160 UserScript& info = all_scripts.back(); 157 UserScript& info = all_scripts.back();
161 info.set_url(GURL(std::string(kUserScriptURLScheme) + ":/" + 158 info.set_url(GURL(std::string(chrome::kUserScriptScheme) + ":/" +
162 net::FilePathToFileURL(file.ToWStringHack()).ExtractFileName())); 159 net::FilePathToFileURL(file.ToWStringHack()).ExtractFileName()));
163 info.set_path(file); 160 info.set_path(file);
164 } 161 }
165 } 162 }
166 163
167 if (all_scripts.empty() && lone_scripts.empty()) 164 if (all_scripts.empty() && lone_scripts.empty())
168 return NULL; 165 return NULL;
169 166
170 // Add all the lone scripts. 167 // Add all the lone scripts.
171 all_scripts.insert(all_scripts.end(), lone_scripts.begin(), 168 all_scripts.insert(all_scripts.end(), lone_scripts.begin(),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 271
275 StartScan(); 272 StartScan();
276 } 273 }
277 274
278 void UserScriptMaster::StartScan() { 275 void UserScriptMaster::StartScan() {
279 if (!script_reloader_) 276 if (!script_reloader_)
280 script_reloader_ = new ScriptReloader(this); 277 script_reloader_ = new ScriptReloader(this);
281 278
282 script_reloader_->StartScan(worker_loop_, user_script_dir_, lone_scripts_); 279 script_reloader_->StartScan(worker_loop_, user_script_dir_, lone_scripts_);
283 } 280 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_protocols.cc ('k') | chrome/browser/history/history_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698