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

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

Issue 495853002: Atomic UserScript ID generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 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
« no previous file with comments | « no previous file | chrome/common/extensions/manifest_handlers/content_scripts_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_loader.h" 5 #include "chrome/browser/extensions/user_script_loader.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 const ExtensionId& extension_id) { 121 const ExtensionId& extension_id) {
122 ExtensionsInfo::const_iterator iter = extensions_info.find(extension_id); 122 ExtensionsInfo::const_iterator iter = extensions_info.find(extension_id);
123 if (iter == extensions_info.end()) 123 if (iter == extensions_info.end())
124 return NULL; 124 return NULL;
125 return file_util::LoadMessageBundleSubstitutionMap( 125 return file_util::LoadMessageBundleSubstitutionMap(
126 iter->second.first, extension_id, iter->second.second); 126 iter->second.first, extension_id, iter->second.second);
127 } 127 }
128 128
129 void LoadUserScripts(UserScriptList* user_scripts, 129 void LoadUserScripts(UserScriptList* user_scripts,
130 const ExtensionsInfo& extensions_info, 130 const ExtensionsInfo& extensions_info,
131 const std::set<int64>& added_script_ids, 131 const std::set<int>& added_script_ids,
132 ContentVerifier* verifier) { 132 ContentVerifier* verifier) {
133 for (UserScriptList::iterator script = user_scripts->begin(); 133 for (UserScriptList::iterator script = user_scripts->begin();
134 script != user_scripts->end(); 134 script != user_scripts->end();
135 ++script) { 135 ++script) {
136 if (added_script_ids.count(script->id()) == 0) 136 if (added_script_ids.count(script->id()) == 0)
137 continue; 137 continue;
138 scoped_ptr<SubstitutionMap> localization_messages( 138 scoped_ptr<SubstitutionMap> localization_messages(
139 GetLocalizationMessages(extensions_info, script->extension_id())); 139 GetLocalizationMessages(extensions_info, script->extension_id()));
140 for (size_t k = 0; k < script->js_scripts().size(); ++k) { 140 for (size_t k = 0; k < script->js_scripts().size(); ++k) {
141 UserScript::File& script_file = script->js_scripts()[k]; 141 UserScript::File& script_file = script->js_scripts()[k];
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 if (!shared_memory.ShareReadOnlyToProcess(base::GetCurrentProcessHandle(), 195 if (!shared_memory.ShareReadOnlyToProcess(base::GetCurrentProcessHandle(),
196 &readonly_handle)) 196 &readonly_handle))
197 return scoped_ptr<base::SharedMemory>(); 197 return scoped_ptr<base::SharedMemory>();
198 198
199 return make_scoped_ptr(new base::SharedMemory(readonly_handle, 199 return make_scoped_ptr(new base::SharedMemory(readonly_handle,
200 /*read_only=*/true)); 200 /*read_only=*/true));
201 } 201 }
202 202
203 void LoadScriptsOnFileThread(scoped_ptr<UserScriptList> user_scripts, 203 void LoadScriptsOnFileThread(scoped_ptr<UserScriptList> user_scripts,
204 const ExtensionsInfo& extensions_info, 204 const ExtensionsInfo& extensions_info,
205 const std::set<int64>& added_script_ids, 205 const std::set<int>& added_script_ids,
206 scoped_refptr<ContentVerifier> verifier, 206 scoped_refptr<ContentVerifier> verifier,
207 LoadScriptsCallback callback) { 207 LoadScriptsCallback callback) {
208 DCHECK(user_scripts.get()); 208 DCHECK(user_scripts.get());
209 LoadUserScripts( 209 LoadUserScripts(
210 user_scripts.get(), extensions_info, added_script_ids, verifier); 210 user_scripts.get(), extensions_info, added_script_ids, verifier);
211 scoped_ptr<base::SharedMemory> memory = Serialize(*user_scripts); 211 scoped_ptr<base::SharedMemory> memory = Serialize(*user_scripts);
212 BrowserThread::PostTask( 212 BrowserThread::PostTask(
213 BrowserThread::UI, 213 BrowserThread::UI,
214 FROM_HERE, 214 FROM_HERE,
215 base::Bind(callback, base::Passed(&user_scripts), base::Passed(&memory))); 215 base::Bind(callback, base::Passed(&user_scripts), base::Passed(&memory)));
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 // Greasemonkey does. 326 // Greasemonkey does.
327 if (script->globs().empty() && script->url_patterns().is_empty()) 327 if (script->globs().empty() && script->url_patterns().is_empty())
328 script->add_glob("*"); 328 script->add_glob("*");
329 329
330 return true; 330 return true;
331 } 331 }
332 332
333 // static 333 // static
334 void UserScriptLoader::LoadScriptsForTest(UserScriptList* user_scripts) { 334 void UserScriptLoader::LoadScriptsForTest(UserScriptList* user_scripts) {
335 ExtensionsInfo info; 335 ExtensionsInfo info;
336 std::set<int64> added_script_ids; 336 std::set<int> added_script_ids;
337 for (UserScriptList::iterator it = user_scripts->begin(); 337 for (UserScriptList::iterator it = user_scripts->begin();
338 it != user_scripts->end(); 338 it != user_scripts->end();
339 ++it) { 339 ++it) {
340 added_script_ids.insert(it->id()); 340 added_script_ids.insert(it->id());
341 } 341 }
342 LoadUserScripts( 342 LoadUserScripts(
343 user_scripts, info, added_script_ids, NULL /* no verifier for testing */); 343 user_scripts, info, added_script_ids, NULL /* no verifier for testing */);
344 } 344 }
345 345
346 UserScriptLoader::UserScriptLoader(Profile* profile, 346 UserScriptLoader::UserScriptLoader(Profile* profile,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 if (removed_scripts_.count(*it)) 461 if (removed_scripts_.count(*it))
462 it = user_scripts_->erase(it); 462 it = user_scripts_->erase(it);
463 else 463 else
464 ++it; 464 ++it;
465 } 465 }
466 } 466 }
467 467
468 user_scripts_->insert( 468 user_scripts_->insert(
469 user_scripts_->end(), added_scripts_.begin(), added_scripts_.end()); 469 user_scripts_->end(), added_scripts_.begin(), added_scripts_.end());
470 470
471 std::set<int64> added_script_ids; 471 std::set<int> added_script_ids;
472 for (std::set<UserScript>::const_iterator it = added_scripts_.begin(); 472 for (std::set<UserScript>::const_iterator it = added_scripts_.begin();
473 it != added_scripts_.end(); 473 it != added_scripts_.end();
474 ++it) { 474 ++it) {
475 added_script_ids.insert(it->id()); 475 added_script_ids.insert(it->id());
476 } 476 }
477 477
478 // Expand |changed_extensions_| for OnScriptsLoaded, which will use it in 478 // Expand |changed_extensions_| for OnScriptsLoaded, which will use it in
479 // its IPC message. This must be done before we clear |added_scripts_| and 479 // its IPC message. This must be done before we clear |added_scripts_| and
480 // |removed_scripts_| below. 480 // |removed_scripts_| below.
481 std::set<UserScript> changed_scripts(added_scripts_); 481 std::set<UserScript> changed_scripts(added_scripts_);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 // which leads to the above lookup failing. In this case, just continue. 595 // which leads to the above lookup failing. In this case, just continue.
596 if (!extension) 596 if (!extension)
597 continue; 597 continue;
598 extensions_info_[*it] = ExtensionSet::ExtensionPathAndDefaultLocale( 598 extensions_info_[*it] = ExtensionSet::ExtensionPathAndDefaultLocale(
599 extension->path(), LocaleInfo::GetDefaultLocale(extension)); 599 extension->path(), LocaleInfo::GetDefaultLocale(extension));
600 } 600 }
601 } 601 }
602 } 602 }
603 603
604 } // namespace extensions 604 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/manifest_handlers/content_scripts_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698