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(
// static
std::unique_ptr<ContentAction> RequestContentScript::CreateForTest(
DeclarativeUserScriptMaster* master,
DeclarativeUserScriptSet* script_set,
const Extension* extension,
const base::Value& json_action,
std::string* error) {
......@@ -269,10 +269,10 @@ std::unique_ptr<ContentAction> RequestContentScript::CreateForTest(
if (!InitScriptData(action_dict, error, &script_data))
return std::unique_ptr<ContentAction>();
// Inject provided DeclarativeUserScriptMaster, rather than looking it up
// Inject provided DeclarativeUserScriptSet, rather than looking it up
// using a BrowserContext.
return base::WrapUnique(
new RequestContentScript(master, extension, script_data));
new RequestContentScript(script_set, extension, script_data));
}
// static
......@@ -322,25 +322,24 @@ RequestContentScript::RequestContentScript(
HostID host_id(HostID::EXTENSIONS, extension->id());
InitScript(host_id, extension, script_data);
master_ = DeclarativeUserScriptManager::Get(browser_context)
->GetDeclarativeUserScriptMasterByID(host_id);
script_set_ = DeclarativeUserScriptManager::Get(browser_context)
->GetDeclarativeUserScriptSetByID(host_id);
AddScript();
}
RequestContentScript::RequestContentScript(
DeclarativeUserScriptMaster* master,
const Extension* extension,
const ScriptData& script_data) {
RequestContentScript::RequestContentScript(DeclarativeUserScriptSet* script_set,
const Extension* extension,
const ScriptData& script_data) {
HostID host_id(HostID::EXTENSIONS, extension->id());
InitScript(host_id, extension, script_data);
master_ = master;
script_set_ = script_set;
AddScript();
}
RequestContentScript::~RequestContentScript() {
DCHECK(master_);
master_->RemoveScript(UserScriptIDPair(script_.id(), script_.host_id()));
DCHECK(script_set_);
script_set_->RemoveScript(UserScriptIDPair(script_.id(), script_.host_id()));
}
void RequestContentScript::InitScript(const HostID& host_id,
......@@ -368,8 +367,8 @@ void RequestContentScript::InitScript(const HostID& host_id,
}
void RequestContentScript::AddScript() {
DCHECK(master_);
master_->AddScript(UserScript::CopyMetadataFrom(script_));
DCHECK(script_set_);
script_set_->AddScript(UserScript::CopyMetadataFrom(script_));
}
void RequestContentScript::Apply(const ApplyInfo& apply_info) const {
......
......@@ -9,7 +9,7 @@
#include <string>
#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"
namespace base {
......@@ -74,7 +74,7 @@ class RequestContentScript : public ContentAction {
RequestContentScript(content::BrowserContext* browser_context,
const Extension* extension,
const ScriptData& script_data);
RequestContentScript(DeclarativeUserScriptMaster* master,
RequestContentScript(DeclarativeUserScriptSet* script_set,
const Extension* extension,
const ScriptData& script_data);
......@@ -87,7 +87,7 @@ class RequestContentScript : public ContentAction {
std::string* error);
static std::unique_ptr<ContentAction> CreateForTest(
DeclarativeUserScriptMaster* master,
DeclarativeUserScriptSet* master,
const Extension* extension,
const base::Value& json_action,
std::string* error);
......@@ -112,7 +112,7 @@ class RequestContentScript : public ContentAction {
const Extension* extension) const;
UserScript script_;
DeclarativeUserScriptMaster* master_;
DeclarativeUserScriptSet* script_set_;
DISALLOW_COPY_AND_ASSIGN(RequestContentScript);
};
......
......@@ -100,8 +100,8 @@ jumbo_source_set("browser_sources") {
"declarative_user_script_manager.h",
"declarative_user_script_manager_factory.cc",
"declarative_user_script_manager_factory.h",
"declarative_user_script_master.cc",
"declarative_user_script_master.h",
"declarative_user_script_set.cc",
"declarative_user_script_set.h",
"deferred_start_render_host.h",
"device_local_account_util.cc",
"device_local_account_util.h",
......
......@@ -6,7 +6,7 @@
#include "content/public/browser/browser_context.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 {
......@@ -26,24 +26,24 @@ DeclarativeUserScriptManager* DeclarativeUserScriptManager::Get(
browser_context);
}
DeclarativeUserScriptMaster*
DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID(
DeclarativeUserScriptSet*
DeclarativeUserScriptManager::GetDeclarativeUserScriptSetByID(
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 CreateDeclarativeUserScriptMaster(host_id);
return CreateDeclarativeUserScriptSet(host_id);
}
DeclarativeUserScriptMaster*
DeclarativeUserScriptManager::CreateDeclarativeUserScriptMaster(
DeclarativeUserScriptSet*
DeclarativeUserScriptManager::CreateDeclarativeUserScriptSet(
const HostID& host_id) {
// Inserts a new DeclarativeUserScriptManager and returns a ptr to it.
return declarative_user_script_masters_
return declarative_user_script_sets_
.insert(
std::make_pair(host_id, std::make_unique<DeclarativeUserScriptMaster>(
std::make_pair(host_id, std::make_unique<DeclarativeUserScriptSet>(
browser_context_, host_id)))
.first->second.get();
}
......@@ -52,10 +52,10 @@ void DeclarativeUserScriptManager::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionReason reason) {
for (const auto& val : declarative_user_script_masters_) {
DeclarativeUserScriptMaster* master = val.second.get();
if (master->host_id().id() == extension->id())
master->ClearScripts();
for (const auto& val : declarative_user_script_sets_) {
DeclarativeUserScriptSet* set = val.second.get();
if (set->host_id().id() == extension->id())
set->ClearScripts();
}
}
......
......@@ -19,9 +19,9 @@ class BrowserContext;
}
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,
public ExtensionRegistryObserver {
public:
......@@ -33,27 +33,27 @@ class DeclarativeUserScriptManager : public KeyedService,
// |context|.
static DeclarativeUserScriptManager* Get(content::BrowserContext* context);
// Gets the user script master for declarative scripts by the given
// HostID; if one does not exist, a new object will be created.
DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByID(
// Gets the user script set for declarative scripts by the given HostId.
// If one does not exist, a new object will be created.
DeclarativeUserScriptSet* GetDeclarativeUserScriptSetByID(
const HostID& host_id);
private:
using UserScriptMasterMap =
std::map<HostID, std::unique_ptr<DeclarativeUserScriptMaster>>;
using UserScriptSetMap =
std::map<HostID, std::unique_ptr<DeclarativeUserScriptSet>>;
// ExtensionRegistryObserver:
void OnExtensionUnloaded(content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionReason reason) override;
// Creates a DeclarativeUserScriptMaster object.
DeclarativeUserScriptMaster* CreateDeclarativeUserScriptMaster(
// Creates a DeclarativeUserScriptSet object.
DeclarativeUserScriptSet* CreateDeclarativeUserScriptSet(
const HostID& host_id);
// A map of DeclarativeUserScriptMasters for each host; each master
// is lazily initialized.
UserScriptMasterMap declarative_user_script_masters_;
// A map of DeclarativeUserScriptSets for each host; each set is lazily
// initialized.
UserScriptSetMap declarative_user_script_sets_;
content::BrowserContext* browser_context_;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// 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 "extensions/browser/extension_user_script_loader.h"
......@@ -12,7 +12,7 @@
namespace extensions {
DeclarativeUserScriptMaster::DeclarativeUserScriptMaster(
DeclarativeUserScriptSet::DeclarativeUserScriptSet(
content::BrowserContext* browser_context,
const HostID& host_id)
: host_id_(host_id) {
......@@ -28,35 +28,33 @@ DeclarativeUserScriptMaster::DeclarativeUserScriptMaster(
}
}
DeclarativeUserScriptMaster::~DeclarativeUserScriptMaster() {
}
DeclarativeUserScriptSet::~DeclarativeUserScriptSet() {}
void DeclarativeUserScriptMaster::AddScript(
std::unique_ptr<UserScript> script) {
void DeclarativeUserScriptSet::AddScript(std::unique_ptr<UserScript> script) {
std::unique_ptr<UserScriptList> scripts(new UserScriptList());
scripts->push_back(std::move(script));
loader_->AddScripts(std::move(scripts));
}
void DeclarativeUserScriptMaster::AddScripts(
void DeclarativeUserScriptSet::AddScripts(
std::unique_ptr<UserScriptList> scripts,
int render_process_id,
int 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;
scripts.insert(script);
RemoveScripts(scripts);
}
void DeclarativeUserScriptMaster::RemoveScripts(
void DeclarativeUserScriptSet::RemoveScripts(
const std::set<UserScriptIDPair>& scripts) {
loader_->RemoveScripts(scripts);
}
void DeclarativeUserScriptMaster::ClearScripts() {
void DeclarativeUserScriptSet::ClearScripts() {
loader_->ClearScripts();
}
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_
#define EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_
#ifndef EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_SET_H_
#define EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_SET_H_
#include <memory>
#include <set>
......@@ -27,11 +27,11 @@ struct UserScriptIDPair;
// UserScriptLoader to which file loading and shared memory management
// operations are delegated, and provides an interface for adding, removing,
// and clearing scripts.
class DeclarativeUserScriptMaster {
class DeclarativeUserScriptSet {
public:
DeclarativeUserScriptMaster(content::BrowserContext* browser_context,
const HostID& host_id);
~DeclarativeUserScriptMaster();
DeclarativeUserScriptSet(content::BrowserContext* browser_context,
const HostID& host_id);
~DeclarativeUserScriptSet();
// Adds script to shared memory region. This may not happen right away if a
// script load is in progress.
......@@ -70,9 +70,9 @@ class DeclarativeUserScriptMaster {
// and notifying renderers of script updates.
std::unique_ptr<UserScriptLoader> loader_;
DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptMaster);
DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptSet);
};
} // namespace extensions
#endif // EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_
#endif // EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_SET_H_
......@@ -14,7 +14,7 @@
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.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/guest_view/web_view/web_view_constants.h"
#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
......@@ -53,10 +53,10 @@ void WebViewContentScriptManager::AddContentScripts(
std::unique_ptr<UserScriptList> scripts) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DeclarativeUserScriptMaster* master =
DeclarativeUserScriptSet* script_set =
DeclarativeUserScriptManager::Get(browser_context_)
->GetDeclarativeUserScriptMasterByID(host_id);
DCHECK(master);
->GetDeclarativeUserScriptSetByID(host_id);
DCHECK(script_set);
// We need to update WebViewRenderState.
std::set<int> ids_to_add;
......@@ -90,18 +90,18 @@ void WebViewContentScriptManager::AddContentScripts(
}
if (!to_delete.empty())
master->RemoveScripts(to_delete);
script_set->RemoveScripts(to_delete);
// Step 3: makes WebViewContentScriptManager become an observer of the
// |loader| for scripts loaded event.
UserScriptLoader* loader = master->loader();
UserScriptLoader* loader = script_set->loader();
DCHECK(loader);
if (!user_script_loader_observer_.IsObserving(loader))
user_script_loader_observer_.Add(loader);
// Step 4: adds new scripts to the master.
master->AddScripts(std::move(scripts), embedder_process_id,
render_frame_host->GetRoutingID());
// Step 4: adds new scripts to the set.
script_set->AddScripts(std::move(scripts), embedder_process_id,
render_frame_host->GetRoutingID());
// Step 5: creates an entry in |webview_host_id_map_| for the given
// |embedder_process_id| and |view_instance_id| if it doesn't exist.
......@@ -146,16 +146,16 @@ void WebViewContentScriptManager::RemoveContentScripts(
if (script_map_iter == guest_content_script_map_.end())
return;
DeclarativeUserScriptMaster* master =
DeclarativeUserScriptSet* script_set =
DeclarativeUserScriptManager::Get(browser_context_)
->GetDeclarativeUserScriptMasterByID(host_id);
CHECK(master);
->GetDeclarativeUserScriptSetByID(host_id);
CHECK(script_set);
// We need to update WebViewRenderState.
std::set<int> ids_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_|.
std::map<std::string, UserScriptIDPair>& map = script_map_iter->second;
// If the |script_name_list| is empty, all the content scripts added by the
......@@ -182,13 +182,13 @@ void WebViewContentScriptManager::RemoveContentScripts(
// Step 2: makes WebViewContentScriptManager become an observer of the
// |loader| for scripts loaded event.
UserScriptLoader* loader = master->loader();
UserScriptLoader* loader = script_set->loader();
DCHECK(loader);
if (!user_script_loader_observer_.IsObserving(loader))
user_script_loader_observer_.Add(loader);
// Step 3: removes content scripts from master.
master->RemoveScripts(scripts_to_delete);
// Step 3: removes content scripts from set.
script_set->RemoveScripts(scripts_to_delete);
// Step 4: updates WebViewRenderState.
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