Commit 058190b1 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

extensions: Rename DeclarativeUserScriptMaster to DeclarativeUserScriptSet

This change removes the uninclusive term "master" from the name of this
class.

Bug: 1097189
Change-Id: I1d268411316529d33e6bbe8c6228b065c7ad5634
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2261365
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781597}
parent 73b0df2d
...@@ -248,7 +248,7 @@ std::unique_ptr<ContentAction> RequestContentScript::Create( ...@@ -248,7 +248,7 @@ std::unique_ptr<ContentAction> RequestContentScript::Create(
// static // static
std::unique_ptr<ContentAction> RequestContentScript::CreateForTest( std::unique_ptr<ContentAction> RequestContentScript::CreateForTest(
DeclarativeUserScriptMaster* master, DeclarativeUserScriptSet* script_set,
const Extension* extension, const Extension* extension,
const base::Value& json_action, const base::Value& json_action,
std::string* error) { std::string* error) {
...@@ -269,10 +269,10 @@ std::unique_ptr<ContentAction> RequestContentScript::CreateForTest( ...@@ -269,10 +269,10 @@ std::unique_ptr<ContentAction> RequestContentScript::CreateForTest(
if (!InitScriptData(action_dict, error, &script_data)) if (!InitScriptData(action_dict, error, &script_data))
return std::unique_ptr<ContentAction>(); return std::unique_ptr<ContentAction>();
// Inject provided DeclarativeUserScriptMaster, rather than looking it up // Inject provided DeclarativeUserScriptSet, rather than looking it up
// using a BrowserContext. // using a BrowserContext.
return base::WrapUnique( return base::WrapUnique(
new RequestContentScript(master, extension, script_data)); new RequestContentScript(script_set, extension, script_data));
} }
// static // static
...@@ -322,25 +322,24 @@ RequestContentScript::RequestContentScript( ...@@ -322,25 +322,24 @@ RequestContentScript::RequestContentScript(
HostID host_id(HostID::EXTENSIONS, extension->id()); HostID host_id(HostID::EXTENSIONS, extension->id());
InitScript(host_id, extension, script_data); InitScript(host_id, extension, script_data);
master_ = DeclarativeUserScriptManager::Get(browser_context) script_set_ = DeclarativeUserScriptManager::Get(browser_context)
->GetDeclarativeUserScriptMasterByID(host_id); ->GetDeclarativeUserScriptSetByID(host_id);
AddScript(); AddScript();
} }
RequestContentScript::RequestContentScript( RequestContentScript::RequestContentScript(DeclarativeUserScriptSet* script_set,
DeclarativeUserScriptMaster* master,
const Extension* extension, const Extension* extension,
const ScriptData& script_data) { const ScriptData& script_data) {
HostID host_id(HostID::EXTENSIONS, extension->id()); HostID host_id(HostID::EXTENSIONS, extension->id());
InitScript(host_id, extension, script_data); InitScript(host_id, extension, script_data);
master_ = master; script_set_ = script_set;
AddScript(); AddScript();
} }
RequestContentScript::~RequestContentScript() { RequestContentScript::~RequestContentScript() {
DCHECK(master_); DCHECK(script_set_);
master_->RemoveScript(UserScriptIDPair(script_.id(), script_.host_id())); script_set_->RemoveScript(UserScriptIDPair(script_.id(), script_.host_id()));
} }
void RequestContentScript::InitScript(const HostID& host_id, void RequestContentScript::InitScript(const HostID& host_id,
...@@ -368,8 +367,8 @@ void RequestContentScript::InitScript(const HostID& host_id, ...@@ -368,8 +367,8 @@ void RequestContentScript::InitScript(const HostID& host_id,
} }
void RequestContentScript::AddScript() { void RequestContentScript::AddScript() {
DCHECK(master_); DCHECK(script_set_);
master_->AddScript(UserScript::CopyMetadataFrom(script_)); script_set_->AddScript(UserScript::CopyMetadataFrom(script_));
} }
void RequestContentScript::Apply(const ApplyInfo& apply_info) const { void RequestContentScript::Apply(const ApplyInfo& apply_info) const {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <string> #include <string>
#include "base/macros.h" #include "base/macros.h"
#include "extensions/browser/declarative_user_script_master.h" #include "extensions/browser/declarative_user_script_set.h"
#include "extensions/common/user_script.h" #include "extensions/common/user_script.h"
namespace base { namespace base {
...@@ -74,7 +74,7 @@ class RequestContentScript : public ContentAction { ...@@ -74,7 +74,7 @@ class RequestContentScript : public ContentAction {
RequestContentScript(content::BrowserContext* browser_context, RequestContentScript(content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
const ScriptData& script_data); const ScriptData& script_data);
RequestContentScript(DeclarativeUserScriptMaster* master, RequestContentScript(DeclarativeUserScriptSet* script_set,
const Extension* extension, const Extension* extension,
const ScriptData& script_data); const ScriptData& script_data);
...@@ -87,7 +87,7 @@ class RequestContentScript : public ContentAction { ...@@ -87,7 +87,7 @@ class RequestContentScript : public ContentAction {
std::string* error); std::string* error);
static std::unique_ptr<ContentAction> CreateForTest( static std::unique_ptr<ContentAction> CreateForTest(
DeclarativeUserScriptMaster* master, DeclarativeUserScriptSet* master,
const Extension* extension, const Extension* extension,
const base::Value& json_action, const base::Value& json_action,
std::string* error); std::string* error);
...@@ -112,7 +112,7 @@ class RequestContentScript : public ContentAction { ...@@ -112,7 +112,7 @@ class RequestContentScript : public ContentAction {
const Extension* extension) const; const Extension* extension) const;
UserScript script_; UserScript script_;
DeclarativeUserScriptMaster* master_; DeclarativeUserScriptSet* script_set_;
DISALLOW_COPY_AND_ASSIGN(RequestContentScript); DISALLOW_COPY_AND_ASSIGN(RequestContentScript);
}; };
......
...@@ -100,8 +100,8 @@ jumbo_source_set("browser_sources") { ...@@ -100,8 +100,8 @@ jumbo_source_set("browser_sources") {
"declarative_user_script_manager.h", "declarative_user_script_manager.h",
"declarative_user_script_manager_factory.cc", "declarative_user_script_manager_factory.cc",
"declarative_user_script_manager_factory.h", "declarative_user_script_manager_factory.h",
"declarative_user_script_master.cc", "declarative_user_script_set.cc",
"declarative_user_script_master.h", "declarative_user_script_set.h",
"deferred_start_render_host.h", "deferred_start_render_host.h",
"device_local_account_util.cc", "device_local_account_util.cc",
"device_local_account_util.h", "device_local_account_util.h",
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "extensions/browser/declarative_user_script_manager_factory.h" #include "extensions/browser/declarative_user_script_manager_factory.h"
#include "extensions/browser/declarative_user_script_master.h" #include "extensions/browser/declarative_user_script_set.h"
namespace extensions { namespace extensions {
...@@ -26,24 +26,24 @@ DeclarativeUserScriptManager* DeclarativeUserScriptManager::Get( ...@@ -26,24 +26,24 @@ DeclarativeUserScriptManager* DeclarativeUserScriptManager::Get(
browser_context); browser_context);
} }
DeclarativeUserScriptMaster* DeclarativeUserScriptSet*
DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID( DeclarativeUserScriptManager::GetDeclarativeUserScriptSetByID(
const HostID& host_id) { const HostID& host_id) {
auto it = declarative_user_script_masters_.find(host_id); auto it = declarative_user_script_sets_.find(host_id);
if (it != declarative_user_script_masters_.end()) if (it != declarative_user_script_sets_.end())
return it->second.get(); return it->second.get();
return CreateDeclarativeUserScriptMaster(host_id); return CreateDeclarativeUserScriptSet(host_id);
} }
DeclarativeUserScriptMaster* DeclarativeUserScriptSet*
DeclarativeUserScriptManager::CreateDeclarativeUserScriptMaster( DeclarativeUserScriptManager::CreateDeclarativeUserScriptSet(
const HostID& host_id) { const HostID& host_id) {
// Inserts a new DeclarativeUserScriptManager and returns a ptr to it. // Inserts a new DeclarativeUserScriptManager and returns a ptr to it.
return declarative_user_script_masters_ return declarative_user_script_sets_
.insert( .insert(
std::make_pair(host_id, std::make_unique<DeclarativeUserScriptMaster>( std::make_pair(host_id, std::make_unique<DeclarativeUserScriptSet>(
browser_context_, host_id))) browser_context_, host_id)))
.first->second.get(); .first->second.get();
} }
...@@ -52,10 +52,10 @@ void DeclarativeUserScriptManager::OnExtensionUnloaded( ...@@ -52,10 +52,10 @@ void DeclarativeUserScriptManager::OnExtensionUnloaded(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
UnloadedExtensionReason reason) { UnloadedExtensionReason reason) {
for (const auto& val : declarative_user_script_masters_) { for (const auto& val : declarative_user_script_sets_) {
DeclarativeUserScriptMaster* master = val.second.get(); DeclarativeUserScriptSet* set = val.second.get();
if (master->host_id().id() == extension->id()) if (set->host_id().id() == extension->id())
master->ClearScripts(); set->ClearScripts();
} }
} }
......
...@@ -19,9 +19,9 @@ class BrowserContext; ...@@ -19,9 +19,9 @@ class BrowserContext;
} }
namespace extensions { namespace extensions {
class DeclarativeUserScriptMaster; class DeclarativeUserScriptSet;
// Manages a set of DeclarativeUserScriptMaster objects for script injections. // Manages a set of DeclarativeUserScriptSet objects for script injections.
class DeclarativeUserScriptManager : public KeyedService, class DeclarativeUserScriptManager : public KeyedService,
public ExtensionRegistryObserver { public ExtensionRegistryObserver {
public: public:
...@@ -33,27 +33,27 @@ class DeclarativeUserScriptManager : public KeyedService, ...@@ -33,27 +33,27 @@ class DeclarativeUserScriptManager : public KeyedService,
// |context|. // |context|.
static DeclarativeUserScriptManager* Get(content::BrowserContext* context); static DeclarativeUserScriptManager* Get(content::BrowserContext* context);
// Gets the user script master for declarative scripts by the given // Gets the user script set for declarative scripts by the given HostId.
// HostID; if one does not exist, a new object will be created. // If one does not exist, a new object will be created.
DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByID( DeclarativeUserScriptSet* GetDeclarativeUserScriptSetByID(
const HostID& host_id); const HostID& host_id);
private: private:
using UserScriptMasterMap = using UserScriptSetMap =
std::map<HostID, std::unique_ptr<DeclarativeUserScriptMaster>>; std::map<HostID, std::unique_ptr<DeclarativeUserScriptSet>>;
// ExtensionRegistryObserver: // ExtensionRegistryObserver:
void OnExtensionUnloaded(content::BrowserContext* browser_context, void OnExtensionUnloaded(content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
UnloadedExtensionReason reason) override; UnloadedExtensionReason reason) override;
// Creates a DeclarativeUserScriptMaster object. // Creates a DeclarativeUserScriptSet object.
DeclarativeUserScriptMaster* CreateDeclarativeUserScriptMaster( DeclarativeUserScriptSet* CreateDeclarativeUserScriptSet(
const HostID& host_id); const HostID& host_id);
// A map of DeclarativeUserScriptMasters for each host; each master // A map of DeclarativeUserScriptSets for each host; each set is lazily
// is lazily initialized. // initialized.
UserScriptMasterMap declarative_user_script_masters_; UserScriptSetMap declarative_user_script_sets_;
content::BrowserContext* browser_context_; content::BrowserContext* browser_context_;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "extensions/browser/declarative_user_script_master.h" #include "extensions/browser/declarative_user_script_set.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "extensions/browser/extension_user_script_loader.h" #include "extensions/browser/extension_user_script_loader.h"
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
namespace extensions { namespace extensions {
DeclarativeUserScriptMaster::DeclarativeUserScriptMaster( DeclarativeUserScriptSet::DeclarativeUserScriptSet(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const HostID& host_id) const HostID& host_id)
: host_id_(host_id) { : host_id_(host_id) {
...@@ -28,35 +28,33 @@ DeclarativeUserScriptMaster::DeclarativeUserScriptMaster( ...@@ -28,35 +28,33 @@ DeclarativeUserScriptMaster::DeclarativeUserScriptMaster(
} }
} }
DeclarativeUserScriptMaster::~DeclarativeUserScriptMaster() { DeclarativeUserScriptSet::~DeclarativeUserScriptSet() {}
}
void DeclarativeUserScriptMaster::AddScript( void DeclarativeUserScriptSet::AddScript(std::unique_ptr<UserScript> script) {
std::unique_ptr<UserScript> script) {
std::unique_ptr<UserScriptList> scripts(new UserScriptList()); std::unique_ptr<UserScriptList> scripts(new UserScriptList());
scripts->push_back(std::move(script)); scripts->push_back(std::move(script));
loader_->AddScripts(std::move(scripts)); loader_->AddScripts(std::move(scripts));
} }
void DeclarativeUserScriptMaster::AddScripts( void DeclarativeUserScriptSet::AddScripts(
std::unique_ptr<UserScriptList> scripts, std::unique_ptr<UserScriptList> scripts,
int render_process_id, int render_process_id,
int render_view_id) { int render_view_id) {
loader_->AddScripts(std::move(scripts), render_process_id, render_view_id); loader_->AddScripts(std::move(scripts), render_process_id, render_view_id);
} }
void DeclarativeUserScriptMaster::RemoveScript(const UserScriptIDPair& script) { void DeclarativeUserScriptSet::RemoveScript(const UserScriptIDPair& script) {
std::set<UserScriptIDPair> scripts; std::set<UserScriptIDPair> scripts;
scripts.insert(script); scripts.insert(script);
RemoveScripts(scripts); RemoveScripts(scripts);
} }
void DeclarativeUserScriptMaster::RemoveScripts( void DeclarativeUserScriptSet::RemoveScripts(
const std::set<UserScriptIDPair>& scripts) { const std::set<UserScriptIDPair>& scripts) {
loader_->RemoveScripts(scripts); loader_->RemoveScripts(scripts);
} }
void DeclarativeUserScriptMaster::ClearScripts() { void DeclarativeUserScriptSet::ClearScripts() {
loader_->ClearScripts(); loader_->ClearScripts();
} }
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_ #ifndef EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_SET_H_
#define EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_ #define EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_SET_H_
#include <memory> #include <memory>
#include <set> #include <set>
...@@ -27,11 +27,11 @@ struct UserScriptIDPair; ...@@ -27,11 +27,11 @@ struct UserScriptIDPair;
// UserScriptLoader to which file loading and shared memory management // UserScriptLoader to which file loading and shared memory management
// operations are delegated, and provides an interface for adding, removing, // operations are delegated, and provides an interface for adding, removing,
// and clearing scripts. // and clearing scripts.
class DeclarativeUserScriptMaster { class DeclarativeUserScriptSet {
public: public:
DeclarativeUserScriptMaster(content::BrowserContext* browser_context, DeclarativeUserScriptSet(content::BrowserContext* browser_context,
const HostID& host_id); const HostID& host_id);
~DeclarativeUserScriptMaster(); ~DeclarativeUserScriptSet();
// Adds script to shared memory region. This may not happen right away if a // Adds script to shared memory region. This may not happen right away if a
// script load is in progress. // script load is in progress.
...@@ -70,9 +70,9 @@ class DeclarativeUserScriptMaster { ...@@ -70,9 +70,9 @@ class DeclarativeUserScriptMaster {
// and notifying renderers of script updates. // and notifying renderers of script updates.
std::unique_ptr<UserScriptLoader> loader_; std::unique_ptr<UserScriptLoader> loader_;
DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptMaster); DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptSet);
}; };
} // namespace extensions } // namespace extensions
#endif // EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_ #endif // EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_SET_H_
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "extensions/browser/declarative_user_script_manager.h" #include "extensions/browser/declarative_user_script_manager.h"
#include "extensions/browser/declarative_user_script_master.h" #include "extensions/browser/declarative_user_script_set.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/browser/guest_view/web_view/web_view_constants.h" #include "extensions/browser/guest_view/web_view/web_view_constants.h"
#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
...@@ -53,10 +53,10 @@ void WebViewContentScriptManager::AddContentScripts( ...@@ -53,10 +53,10 @@ void WebViewContentScriptManager::AddContentScripts(
std::unique_ptr<UserScriptList> scripts) { std::unique_ptr<UserScriptList> scripts) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DeclarativeUserScriptMaster* master = DeclarativeUserScriptSet* script_set =
DeclarativeUserScriptManager::Get(browser_context_) DeclarativeUserScriptManager::Get(browser_context_)
->GetDeclarativeUserScriptMasterByID(host_id); ->GetDeclarativeUserScriptSetByID(host_id);
DCHECK(master); DCHECK(script_set);
// We need to update WebViewRenderState. // We need to update WebViewRenderState.
std::set<int> ids_to_add; std::set<int> ids_to_add;
...@@ -90,17 +90,17 @@ void WebViewContentScriptManager::AddContentScripts( ...@@ -90,17 +90,17 @@ void WebViewContentScriptManager::AddContentScripts(
} }
if (!to_delete.empty()) if (!to_delete.empty())
master->RemoveScripts(to_delete); script_set->RemoveScripts(to_delete);
// Step 3: makes WebViewContentScriptManager become an observer of the // Step 3: makes WebViewContentScriptManager become an observer of the
// |loader| for scripts loaded event. // |loader| for scripts loaded event.
UserScriptLoader* loader = master->loader(); UserScriptLoader* loader = script_set->loader();
DCHECK(loader); DCHECK(loader);
if (!user_script_loader_observer_.IsObserving(loader)) if (!user_script_loader_observer_.IsObserving(loader))
user_script_loader_observer_.Add(loader); user_script_loader_observer_.Add(loader);
// Step 4: adds new scripts to the master. // Step 4: adds new scripts to the set.
master->AddScripts(std::move(scripts), embedder_process_id, script_set->AddScripts(std::move(scripts), embedder_process_id,
render_frame_host->GetRoutingID()); render_frame_host->GetRoutingID());
// Step 5: creates an entry in |webview_host_id_map_| for the given // Step 5: creates an entry in |webview_host_id_map_| for the given
...@@ -146,16 +146,16 @@ void WebViewContentScriptManager::RemoveContentScripts( ...@@ -146,16 +146,16 @@ void WebViewContentScriptManager::RemoveContentScripts(
if (script_map_iter == guest_content_script_map_.end()) if (script_map_iter == guest_content_script_map_.end())
return; return;
DeclarativeUserScriptMaster* master = DeclarativeUserScriptSet* script_set =
DeclarativeUserScriptManager::Get(browser_context_) DeclarativeUserScriptManager::Get(browser_context_)
->GetDeclarativeUserScriptMasterByID(host_id); ->GetDeclarativeUserScriptSetByID(host_id);
CHECK(master); CHECK(script_set);
// We need to update WebViewRenderState. // We need to update WebViewRenderState.
std::set<int> ids_to_delete; std::set<int> ids_to_delete;
std::set<UserScriptIDPair> scripts_to_delete; std::set<UserScriptIDPair> scripts_to_delete;
// Step 1: removes content scripts from |master| and updates // Step 1: removes content scripts from |set| and updates
// |guest_content_script_map_|. // |guest_content_script_map_|.
std::map<std::string, UserScriptIDPair>& map = script_map_iter->second; std::map<std::string, UserScriptIDPair>& map = script_map_iter->second;
// If the |script_name_list| is empty, all the content scripts added by the // If the |script_name_list| is empty, all the content scripts added by the
...@@ -182,13 +182,13 @@ void WebViewContentScriptManager::RemoveContentScripts( ...@@ -182,13 +182,13 @@ void WebViewContentScriptManager::RemoveContentScripts(
// Step 2: makes WebViewContentScriptManager become an observer of the // Step 2: makes WebViewContentScriptManager become an observer of the
// |loader| for scripts loaded event. // |loader| for scripts loaded event.
UserScriptLoader* loader = master->loader(); UserScriptLoader* loader = script_set->loader();
DCHECK(loader); DCHECK(loader);
if (!user_script_loader_observer_.IsObserving(loader)) if (!user_script_loader_observer_.IsObserving(loader))
user_script_loader_observer_.Add(loader); user_script_loader_observer_.Add(loader);
// Step 3: removes content scripts from master. // Step 3: removes content scripts from set.
master->RemoveScripts(scripts_to_delete); script_set->RemoveScripts(scripts_to_delete);
// Step 4: updates WebViewRenderState. // Step 4: updates WebViewRenderState.
if (!ids_to_delete.empty()) { if (!ids_to_delete.empty()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment