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

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

Issue 2227193002: Make UserScript non-copyable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync @tott Created 4 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 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/shared_user_script_master.h" 5 #include "chrome/browser/extensions/shared_user_script_master.h"
6 6
7 #include "base/memory/ptr_util.h"
7 #include "chrome/browser/extensions/extension_util.h" 8 #include "chrome/browser/extensions/extension_util.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" 10 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
10 #include "extensions/browser/extension_registry.h" 11 #include "extensions/browser/extension_registry.h"
11 #include "extensions/common/host_id.h" 12 #include "extensions/common/host_id.h"
12 13
13 namespace extensions { 14 namespace extensions {
14 15
15 SharedUserScriptMaster::SharedUserScriptMaster(Profile* profile) 16 SharedUserScriptMaster::SharedUserScriptMaster(Profile* profile)
16 : loader_(profile, 17 : loader_(profile,
(...skipping 13 matching lines...) Expand all
30 loader_.AddScripts(GetScriptsMetadata(extension)); 31 loader_.AddScripts(GetScriptsMetadata(extension));
31 } 32 }
32 33
33 void SharedUserScriptMaster::OnExtensionUnloaded( 34 void SharedUserScriptMaster::OnExtensionUnloaded(
34 content::BrowserContext* browser_context, 35 content::BrowserContext* browser_context,
35 const Extension* extension, 36 const Extension* extension,
36 UnloadedExtensionInfo::Reason reason) { 37 UnloadedExtensionInfo::Reason reason) {
37 const UserScriptList& script_list = 38 const UserScriptList& script_list =
38 ContentScriptsInfo::GetContentScripts(extension); 39 ContentScriptsInfo::GetContentScripts(extension);
39 std::set<UserScriptIDPair> scripts_to_remove; 40 std::set<UserScriptIDPair> scripts_to_remove;
40 for (const UserScript& script : script_list) 41 for (const std::unique_ptr<UserScript>& script : script_list)
41 scripts_to_remove.insert(UserScriptIDPair(script.id(), script.host_id())); 42 scripts_to_remove.insert(UserScriptIDPair(script->id(), script->host_id()));
42 loader_.RemoveScripts(scripts_to_remove); 43 loader_.RemoveScripts(scripts_to_remove);
43 } 44 }
44 45
45 const std::vector<UserScript> SharedUserScriptMaster::GetScriptsMetadata( 46 std::unique_ptr<UserScriptList> SharedUserScriptMaster::GetScriptsMetadata(
46 const Extension* extension) { 47 const Extension* extension) {
47 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); 48 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_);
48 const UserScriptList& script_list = 49 const UserScriptList& script_list =
49 ContentScriptsInfo::GetContentScripts(extension); 50 ContentScriptsInfo::GetContentScripts(extension);
50 std::vector<UserScript> scripts; 51 std::unique_ptr<UserScriptList> script_vector(new UserScriptList());
51 scripts.reserve(script_list.size()); 52 script_vector->reserve(script_list.size());
52 for (const UserScript& script : script_list) { 53 for (const std::unique_ptr<UserScript>& script : script_list) {
53 scripts.push_back(UserScript(script)); 54 std::unique_ptr<UserScript> script_copy =
54 scripts.back().set_incognito_enabled(incognito_enabled); 55 UserScript::CopyMetadataFrom(*script);
56 script_copy->set_incognito_enabled(incognito_enabled);
57 script_vector->push_back(std::move(script_copy));
55 } 58 }
56 59 return script_vector;
57 return scripts;
58 } 60 }
59 61
60 } // namespace extensions 62 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/shared_user_script_master.h ('k') | chrome/browser/extensions/user_script_listener.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698