| Index: extensions/browser/user_script_loader.cc
|
| diff --git a/extensions/browser/user_script_loader.cc b/extensions/browser/user_script_loader.cc
|
| index 4d5e4d4b3c42cf3229bdf75880b4e50c44f1a433..b3d1c833ceebba652b0c91a6e867f7a3cbac2ba5 100644
|
| --- a/extensions/browser/user_script_loader.cc
|
| +++ b/extensions/browser/user_script_loader.cc
|
| @@ -29,12 +29,12 @@ namespace extensions {
|
| namespace {
|
|
|
| #if DCHECK_IS_ON()
|
| -bool AreScriptsUnique(const UserScriptList& scripts) {
|
| +bool AreScriptsUnique(const BrowserUserScriptList& scripts) {
|
| std::set<int> script_ids;
|
| - for (const UserScript& script : scripts) {
|
| - if (script_ids.count(script.id()))
|
| + for (const std::unique_ptr<BrowserUserScript>& script : scripts) {
|
| + if (script_ids.count(script->id()))
|
| return false;
|
| - script_ids.insert(script.id());
|
| + script_ids.insert(script->id());
|
| }
|
| return true;
|
| }
|
| @@ -62,7 +62,7 @@ bool GetDeclarationValue(const base::StringPiece& line,
|
|
|
| // static
|
| bool UserScriptLoader::ParseMetadataHeader(const base::StringPiece& script_text,
|
| - UserScript* script) {
|
| + BrowserUserScript* script) {
|
| // http://wiki.greasespot.net/Metadata_block
|
| base::StringPiece line;
|
| size_t line_start = 0;
|
| @@ -157,7 +157,7 @@ bool UserScriptLoader::ParseMetadataHeader(const base::StringPiece& script_text,
|
|
|
| UserScriptLoader::UserScriptLoader(BrowserContext* browser_context,
|
| const HostID& host_id)
|
| - : user_scripts_(new UserScriptList()),
|
| + : user_scripts_(new BrowserUserScriptList()),
|
| clear_scripts_(false),
|
| ready_(false),
|
| pending_load_(false),
|
| @@ -173,23 +173,23 @@ UserScriptLoader::~UserScriptLoader() {
|
| FOR_EACH_OBSERVER(Observer, observers_, OnUserScriptLoaderDestroyed(this));
|
| }
|
|
|
| -void UserScriptLoader::AddScripts(const UserScriptList& scripts) {
|
| +void UserScriptLoader::AddScripts(BrowserUserScriptList& scripts) {
|
| #if DCHECK_IS_ON()
|
| // |scripts| with non-unique IDs will work, but that would indicate we are
|
| // doing something wrong somewhere, so DCHECK that.
|
| DCHECK(AreScriptsUnique(scripts))
|
| << "AddScripts() expects scripts with unique IDs.";
|
| #endif // DCHECK_IS_ON()
|
| - for (const UserScript& user_script : scripts) {
|
| - int id = user_script.id();
|
| + for (std::unique_ptr<BrowserUserScript>& user_script : scripts) {
|
| + int id = user_script->id();
|
| removed_script_hosts_.erase(UserScriptIDPair(id));
|
| if (added_scripts_map_.count(id) == 0)
|
| - added_scripts_map_[id] = user_script;
|
| + added_scripts_map_[id] = std::move(user_script);
|
| }
|
| AttemptLoad();
|
| }
|
|
|
| -void UserScriptLoader::AddScripts(const UserScriptList& scripts,
|
| +void UserScriptLoader::AddScripts(BrowserUserScriptList& scripts,
|
| int render_process_id,
|
| int render_view_id) {
|
| AddScripts(scripts);
|
| @@ -258,9 +258,9 @@ void UserScriptLoader::StartLoad() {
|
| if (clear_scripts_) {
|
| user_scripts_->clear();
|
| } else {
|
| - for (UserScriptList::iterator it = user_scripts_->begin();
|
| + for (BrowserUserScriptList::iterator it = user_scripts_->begin();
|
| it != user_scripts_->end();) {
|
| - UserScriptIDPair id_pair(it->id());
|
| + UserScriptIDPair id_pair(it->get()->id());
|
| if (removed_script_hosts_.count(id_pair) > 0u)
|
| it = user_scripts_->erase(it);
|
| else
|
| @@ -270,13 +270,13 @@ void UserScriptLoader::StartLoad() {
|
|
|
| std::set<int> added_script_ids;
|
| for (const auto& id_and_script : added_scripts_map_)
|
| - added_script_ids.insert(id_and_script.second.id());
|
| + added_script_ids.insert(id_and_script.second->id());
|
|
|
| // Expand |changed_hosts_| for OnScriptsLoaded, which will use it in
|
| // its IPC message. This must be done before we clear |added_scripts_map_| and
|
| // |removed_script_hosts_| below.
|
| for (const auto& id_and_script : added_scripts_map_)
|
| - changed_hosts_.insert(id_and_script.second.host_id());
|
| + changed_hosts_.insert(id_and_script.second->host_id());
|
| for (const UserScriptIDPair& id_pair : removed_script_hosts_)
|
| changed_hosts_.insert(id_pair.host_id);
|
|
|
| @@ -297,22 +297,24 @@ void UserScriptLoader::StartLoad() {
|
|
|
| // static
|
| std::unique_ptr<base::SharedMemory> UserScriptLoader::Serialize(
|
| - const UserScriptList& scripts) {
|
| + const BrowserUserScriptList& scripts) {
|
| base::Pickle pickle;
|
| pickle.WriteUInt32(scripts.size());
|
| - for (const UserScript& script : scripts) {
|
| + for (const std::unique_ptr<BrowserUserScript>& script : scripts) {
|
| // TODO(aa): This can be replaced by sending content script metadata to
|
| // renderers along with other extension data in ExtensionMsg_Loaded.
|
| // See crbug.com/70516.
|
| - script.Pickle(&pickle);
|
| + script->Pickle(&pickle);
|
| // Write scripts as 'data' so that we can read it out in the slave without
|
| // allocating a new string.
|
| - for (const UserScript::File& script_file : script.js_scripts()) {
|
| - base::StringPiece contents = script_file.GetContent();
|
| + for (const std::unique_ptr<BrowserScriptFile>& script_file :
|
| + script->js_scripts()) {
|
| + base::StringPiece contents = script_file->GetContent();
|
| pickle.WriteData(contents.data(), contents.length());
|
| }
|
| - for (const UserScript::File& script_file : script.css_scripts()) {
|
| - base::StringPiece contents = script_file.GetContent();
|
| + for (const std::unique_ptr<BrowserScriptFile>& script_file :
|
| + script->css_scripts()) {
|
| + base::StringPiece contents = script_file->GetContent();
|
| pickle.WriteData(contents.data(), contents.length());
|
| }
|
| }
|
| @@ -357,7 +359,7 @@ void UserScriptLoader::SetReady(bool ready) {
|
| }
|
|
|
| void UserScriptLoader::OnScriptsLoaded(
|
| - std::unique_ptr<UserScriptList> user_scripts,
|
| + std::unique_ptr<BrowserUserScriptList> user_scripts,
|
| std::unique_ptr<base::SharedMemory> shared_memory) {
|
| user_scripts_.reset(user_scripts.release());
|
| if (pending_load_) {
|
|
|