Commit f3b29abd authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Remove NOTIFICATION_PROFILE_DESTROYED from UserScriptListener.

For normal profiles, it isn't sent until browser shutdown, at which
point there's no need to check if all user scripts are ready. For OTR
profiles, it can be sent when the last incognito window is closed, but
|profile_data_| doesn't hold OTR profiles.

Bug: 268984
Change-Id: I041fd6242457cf4b94633fe28aacc7c945cfad0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1833908Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704374}
parent 24be339f
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/navigation_throttle.h" #include "content/public/browser/navigation_throttle.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
...@@ -20,7 +19,6 @@ ...@@ -20,7 +19,6 @@
#include "extensions/common/manifest_handlers/content_scripts_handler.h" #include "extensions/common/manifest_handlers/content_scripts_handler.h"
#include "extensions/common/url_pattern.h" #include "extensions/common/url_pattern.h"
using content::BrowserThread;
using content::NavigationThrottle; using content::NavigationThrottle;
using content::ResourceType; using content::ResourceType;
...@@ -77,8 +75,6 @@ struct UserScriptListener::ProfileData { ...@@ -77,8 +75,6 @@ struct UserScriptListener::ProfileData {
}; };
UserScriptListener::UserScriptListener() { UserScriptListener::UserScriptListener() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Profile manager can be null in unit tests. // Profile manager can be null in unit tests.
if (g_browser_process->profile_manager()) { if (g_browser_process->profile_manager()) {
for (auto* profile : for (auto* profile :
...@@ -90,8 +86,6 @@ UserScriptListener::UserScriptListener() { ...@@ -90,8 +86,6 @@ UserScriptListener::UserScriptListener() {
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllSources());
registrar_.Add(this, registrar_.Add(this,
extensions::NOTIFICATION_USER_SCRIPTS_UPDATED, extensions::NOTIFICATION_USER_SCRIPTS_UPDATED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
...@@ -117,7 +111,6 @@ void UserScriptListener::SetUserScriptsNotReadyForTesting( ...@@ -117,7 +111,6 @@ void UserScriptListener::SetUserScriptsNotReadyForTesting(
UserScriptListener::~UserScriptListener() {} UserScriptListener::~UserScriptListener() {}
bool UserScriptListener::ShouldDelayRequest(const GURL& url) { bool UserScriptListener::ShouldDelayRequest(const GURL& url) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Note: we could delay only requests made by the profile who is causing the // Note: we could delay only requests made by the profile who is causing the
// delay, but it's a little more complicated to associate requests with the // delay, but it's a little more complicated to associate requests with the
// right profile. Since this is a rare case, we'll just take the easy way // right profile. Since this is a rare case, we'll just take the easy way
...@@ -150,7 +143,6 @@ void UserScriptListener::StartDelayedRequests() { ...@@ -150,7 +143,6 @@ void UserScriptListener::StartDelayedRequests() {
} }
void UserScriptListener::CheckIfAllUserScriptsReady() { void UserScriptListener::CheckIfAllUserScriptsReady() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
bool was_ready = user_scripts_ready_; bool was_ready = user_scripts_ready_;
user_scripts_ready_ = true; user_scripts_ready_ = true;
...@@ -165,23 +157,15 @@ void UserScriptListener::CheckIfAllUserScriptsReady() { ...@@ -165,23 +157,15 @@ void UserScriptListener::CheckIfAllUserScriptsReady() {
} }
void UserScriptListener::UserScriptsReady(content::BrowserContext* context) { void UserScriptListener::UserScriptsReady(content::BrowserContext* context) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK(!context->IsOffTheRecord());
profile_data_[context].user_scripts_ready = true; profile_data_[context].user_scripts_ready = true;
CheckIfAllUserScriptsReady(); CheckIfAllUserScriptsReady();
} }
void UserScriptListener::ProfileDestroyed(content::BrowserContext* context) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
profile_data_.erase(context);
// We may have deleted the only profile we were waiting on.
CheckIfAllUserScriptsReady();
}
void UserScriptListener::AppendNewURLPatterns(content::BrowserContext* context, void UserScriptListener::AppendNewURLPatterns(content::BrowserContext* context,
const URLPatterns& new_patterns) { const URLPatterns& new_patterns) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK(!context->IsOffTheRecord());
user_scripts_ready_ = false; user_scripts_ready_ = false;
...@@ -194,16 +178,14 @@ void UserScriptListener::AppendNewURLPatterns(content::BrowserContext* context, ...@@ -194,16 +178,14 @@ void UserScriptListener::AppendNewURLPatterns(content::BrowserContext* context,
void UserScriptListener::ReplaceURLPatterns(content::BrowserContext* context, void UserScriptListener::ReplaceURLPatterns(content::BrowserContext* context,
const URLPatterns& patterns) { const URLPatterns& patterns) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); // TODO(estade): enable this check once it no longer fails.
// DCHECK_EQ(1U, profile_data_.count(context));
ProfileData& data = profile_data_[context]; profile_data_[context].url_patterns = patterns;
data.url_patterns = patterns;
} }
void UserScriptListener::CollectURLPatterns(const Extension* extension, void UserScriptListener::CollectURLPatterns(const Extension* extension,
URLPatterns* patterns) { URLPatterns* patterns) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
for (const std::unique_ptr<UserScript>& script : for (const std::unique_ptr<UserScript>& script :
ContentScriptsInfo::GetContentScripts(extension)) { ContentScriptsInfo::GetContentScripts(extension)) {
patterns->insert(patterns->end(), script->url_patterns().begin(), patterns->insert(patterns->end(), script->url_patterns().begin(),
...@@ -214,8 +196,6 @@ void UserScriptListener::CollectURLPatterns(const Extension* extension, ...@@ -214,8 +196,6 @@ void UserScriptListener::CollectURLPatterns(const Extension* extension,
void UserScriptListener::Observe(int type, void UserScriptListener::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
switch (type) { switch (type) {
case chrome::NOTIFICATION_PROFILE_ADDED: { case chrome::NOTIFICATION_PROFILE_ADDED: {
auto* registry = auto* registry =
...@@ -224,11 +204,6 @@ void UserScriptListener::Observe(int type, ...@@ -224,11 +204,6 @@ void UserScriptListener::Observe(int type,
extension_registry_observer_.Add(registry); extension_registry_observer_.Add(registry);
break; break;
} }
case chrome::NOTIFICATION_PROFILE_DESTROYED: {
Profile* profile = content::Source<Profile>(source).ptr();
ProfileDestroyed(profile);
break;
}
case extensions::NOTIFICATION_USER_SCRIPTS_UPDATED: { case extensions::NOTIFICATION_USER_SCRIPTS_UPDATED: {
Profile* profile = content::Source<Profile>(source).ptr(); Profile* profile = content::Source<Profile>(source).ptr();
UserScriptsReady(profile); UserScriptsReady(profile);
......
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