OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 static bool GetDeclarationValue(const base::StringPiece& line, | 28 static bool GetDeclarationValue(const base::StringPiece& line, |
29 const base::StringPiece& prefix, | 29 const base::StringPiece& prefix, |
30 std::string* value) { | 30 std::string* value) { |
31 base::StringPiece::size_type index = line.find(prefix); | 31 base::StringPiece::size_type index = line.find(prefix); |
32 if (index == base::StringPiece::npos) | 32 if (index == base::StringPiece::npos) |
33 return false; | 33 return false; |
34 | 34 |
35 std::string temp(line.data() + index + prefix.length(), | 35 std::string temp(line.data() + index + prefix.length(), |
36 line.length() - index - prefix.length()); | 36 line.length() - index - prefix.length()); |
37 | 37 |
38 if (temp.size() == 0 || !IsWhitespace(temp[0])) | 38 if (temp.empty() || !IsWhitespace(temp[0])) |
39 return false; | 39 return false; |
40 | 40 |
41 TrimWhitespaceASCII(temp, TRIM_ALL, value); | 41 TrimWhitespaceASCII(temp, TRIM_ALL, value); |
42 return true; | 42 return true; |
43 } | 43 } |
44 | 44 |
45 UserScriptMaster::ScriptReloader::ScriptReloader(UserScriptMaster* master) | 45 UserScriptMaster::ScriptReloader::ScriptReloader(UserScriptMaster* master) |
46 : master_(master) { | 46 : master_(master) { |
47 CHECK(BrowserThread::GetCurrentThreadIdentifier(&master_thread_id_)); | 47 CHECK(BrowserThread::GetCurrentThreadIdentifier(&master_thread_id_)); |
48 } | 48 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 | 119 |
120 // TODO(aa): Handle more types of metadata. | 120 // TODO(aa): Handle more types of metadata. |
121 } | 121 } |
122 | 122 |
123 line_start = line_end + 1; | 123 line_start = line_end + 1; |
124 } | 124 } |
125 | 125 |
126 // If no patterns were specified, default to @include *. This is what | 126 // If no patterns were specified, default to @include *. This is what |
127 // Greasemonkey does. | 127 // Greasemonkey does. |
128 if (script->globs().size() == 0 && script->url_patterns().size() == 0) | 128 if (script->globs().empty() && script->url_patterns().empty()) |
129 script->add_glob("*"); | 129 script->add_glob("*"); |
130 | 130 |
131 return true; | 131 return true; |
132 } | 132 } |
133 | 133 |
134 void UserScriptMaster::ScriptReloader::StartScan( | 134 void UserScriptMaster::ScriptReloader::StartScan( |
135 const FilePath& script_dir, const UserScriptList& lone_scripts) { | 135 const FilePath& script_dir, const UserScriptList& lone_scripts) { |
136 // Add a reference to ourselves to keep ourselves alive while we're running. | 136 // Add a reference to ourselves to keep ourselves alive while we're running. |
137 // Balanced by NotifyMaster(). | 137 // Balanced by NotifyMaster(). |
138 AddRef(); | 138 AddRef(); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 DCHECK(false); | 397 DCHECK(false); |
398 } | 398 } |
399 } | 399 } |
400 | 400 |
401 void UserScriptMaster::StartScan() { | 401 void UserScriptMaster::StartScan() { |
402 if (!script_reloader_) | 402 if (!script_reloader_) |
403 script_reloader_ = new ScriptReloader(this); | 403 script_reloader_ = new ScriptReloader(this); |
404 | 404 |
405 script_reloader_->StartScan(user_script_dir_, lone_scripts_); | 405 script_reloader_->StartScan(user_script_dir_, lone_scripts_); |
406 } | 406 } |
OLD | NEW |