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

Unified 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: remove browser/renderer specific file impl as it is not helping much 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/shared_user_script_master.cc
diff --git a/chrome/browser/extensions/shared_user_script_master.cc b/chrome/browser/extensions/shared_user_script_master.cc
index 6a0dde4957736f3b9fd93535522f183094efaade..9bc601069783abd0f770c65e8d5285ff220a8d57 100644
--- a/chrome/browser/extensions/shared_user_script_master.cc
+++ b/chrome/browser/extensions/shared_user_script_master.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/extensions/shared_user_script_master.h"
+#include "base/memory/ptr_util.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
@@ -27,7 +28,8 @@ SharedUserScriptMaster::~SharedUserScriptMaster() {
void SharedUserScriptMaster::OnExtensionLoaded(
content::BrowserContext* browser_context,
const Extension* extension) {
- loader_.AddScripts(GetScriptsMetadata(extension));
+ UserScriptList list = GetScriptsMetadata(extension);
+ loader_.AddScripts(list);
Devlin 2016/08/17 16:39:30 nit: inline list?
lazyboy 2016/08/17 18:55:52 We need an l-value here since AddScripts takes a (
}
void SharedUserScriptMaster::OnExtensionUnloaded(
@@ -37,24 +39,24 @@ void SharedUserScriptMaster::OnExtensionUnloaded(
const UserScriptList& script_list =
ContentScriptsInfo::GetContentScripts(extension);
std::set<UserScriptIDPair> scripts_to_remove;
- for (const UserScript& script : script_list)
- scripts_to_remove.insert(UserScriptIDPair(script.id(), script.host_id()));
+ for (const std::unique_ptr<UserScript>& script : script_list)
+ scripts_to_remove.insert(UserScriptIDPair(script->id(), script->host_id()));
loader_.RemoveScripts(scripts_to_remove);
}
-const std::vector<UserScript> SharedUserScriptMaster::GetScriptsMetadata(
+UserScriptList SharedUserScriptMaster::GetScriptsMetadata(
const Extension* extension) {
bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_);
const UserScriptList& script_list =
ContentScriptsInfo::GetContentScripts(extension);
- std::vector<UserScript> scripts;
- scripts.reserve(script_list.size());
- for (const UserScript& script : script_list) {
- scripts.push_back(UserScript(script));
- scripts.back().set_incognito_enabled(incognito_enabled);
+ std::vector<std::unique_ptr<UserScript>> script_vector;
Devlin 2016/08/17 16:39:30 nit: UserScriptList?
lazyboy 2016/08/17 18:55:52 Done.
+ script_vector.reserve(script_list.size());
+ for (const std::unique_ptr<UserScript>& meta : script_list) {
+ std::unique_ptr<UserScript> data = UserScript::CopyFrom(*meta);
+ data->set_incognito_enabled(incognito_enabled);
Devlin 2016/08/17 16:39:30 (Not related to this patch set, but...) This seems
lazyboy 2016/08/17 18:55:52 Added TODO in user_script.h, will follow up.
+ script_vector.push_back(std::move(data));
}
-
- return scripts;
+ return script_vector;
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698