Commit 266b2dd5 authored by Lucas Furukawa Gadani's avatar Lucas Furukawa Gadani Committed by Commit Bot

Do not post task to IO when updating WebViewRendererState.

It is not necessary to post a task to the IO thread since the
WebViewRendererState was made thread-safe. This fixes a race between
updating the info on the IO thread and spawning the renderer process.

Bug: 925920
Change-Id: I2627011ca8ba5f9c77b2e090e65ff8c97a69aa91
Reviewed-on: https://chromium-review.googlesource.com/c/1440723Reviewed-by: default avatarJames MacLean <wjmaclean@chromium.org>
Reviewed-by: default avatarKevin McNee <mcnee@chromium.org>
Commit-Queue: Lucas Gadani <lfg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#627019}
parent 7070e881
......@@ -58,7 +58,7 @@ void WebViewContentScriptManager::AddContentScripts(
->GetDeclarativeUserScriptMasterByID(host_id);
DCHECK(master);
// We need to update WebViewRenderState in the IO thread if the guest exists.
// We need to update WebViewRenderState.
std::set<int> ids_to_add;
GuestMapKey key = std::pair<int, int>(embedder_process_id, view_instance_id);
......@@ -109,16 +109,10 @@ void WebViewContentScriptManager::AddContentScripts(
if (host_it == webview_host_id_map_.end())
webview_host_id_map_.insert(std::make_pair(key, host_id));
// Step 6: updates WebViewRenderState in the IO thread.
// It is safe to use base::Unretained(WebViewRendererState::GetInstance())
// since WebViewRendererState::GetInstance() always returns a Singleton of
// WebViewRendererState.
// Step 6: updates WebViewRenderState.
if (!ids_to_add.empty()) {
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::IO},
base::Bind(&WebViewRendererState::AddContentScriptIDs,
base::Unretained(WebViewRendererState::GetInstance()),
embedder_process_id, view_instance_id, ids_to_add));
WebViewRendererState::GetInstance()->AddContentScriptIDs(
embedder_process_id, view_instance_id, ids_to_add);
}
}
......@@ -157,7 +151,7 @@ void WebViewContentScriptManager::RemoveContentScripts(
->GetDeclarativeUserScriptMasterByID(host_id);
CHECK(master);
// We need to update WebViewRenderState in the IO thread if the guest exists.
// We need to update WebViewRenderState.
std::set<int> ids_to_delete;
std::set<UserScriptIDPair> scripts_to_delete;
......@@ -196,13 +190,10 @@ void WebViewContentScriptManager::RemoveContentScripts(
// Step 3: removes content scripts from master.
master->RemoveScripts(scripts_to_delete);
// Step 4: updates WebViewRenderState in the IO thread.
// Step 4: updates WebViewRenderState.
if (!ids_to_delete.empty()) {
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::IO},
base::Bind(&WebViewRendererState::RemoveContentScriptIDs,
base::Unretained(WebViewRendererState::GetInstance()),
embedder_process_id, view_instance_id, ids_to_delete));
WebViewRendererState::GetInstance()->RemoveContentScriptIDs(
embedder_process_id, view_instance_id, ids_to_delete);
}
}
......
......@@ -509,7 +509,9 @@ int WebViewGuest::GetTaskPrefix() const {
}
void WebViewGuest::GuestDestroyed() {
RemoveWebViewStateFromIOThread(web_contents());
WebViewRendererState::GetInstance()->RemoveGuest(
web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
web_contents()->GetRenderViewHost()->GetRoutingID());
}
void WebViewGuest::GuestReady() {
......@@ -1027,24 +1029,9 @@ void WebViewGuest::PushWebViewStateToIOThread() {
web_view_info.content_script_ids = manager->GetContentScriptIDSet(
web_view_info.embedder_process_id, web_view_info.instance_id);
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::IO},
base::Bind(&WebViewRendererState::AddGuest,
base::Unretained(WebViewRendererState::GetInstance()),
web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
web_contents()->GetRenderViewHost()->GetRoutingID(),
web_view_info));
}
// static
void WebViewGuest::RemoveWebViewStateFromIOThread(
WebContents* web_contents) {
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::IO},
base::Bind(&WebViewRendererState::RemoveGuest,
base::Unretained(WebViewRendererState::GetInstance()),
web_contents->GetRenderViewHost()->GetProcess()->GetID(),
web_contents->GetRenderViewHost()->GetRoutingID()));
WebViewRendererState::GetInstance()->AddGuest(
web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
web_contents()->GetRenderViewHost()->GetRoutingID(), web_view_info);
}
void WebViewGuest::RequestMediaAccessPermission(
......
......@@ -284,8 +284,6 @@ class WebViewGuest : public guest_view::GuestView<WebViewGuest> {
void ReportFrameNameChange(const std::string& name);
void PushWebViewStateToIOThread();
static void RemoveWebViewStateFromIOThread(
content::WebContents* web_contents);
// Loads the |url| provided. |force_navigation| indicates whether to reload
// the content if the provided |url| matches the current page of the guest.
......
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