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

Remove unnecessary Profile parameters from BackgroundContentsService

The passed profile always matches |profile_|, so just remove it.

Bug: none
Change-Id: I29940c6ab54e9e9dbd7b1ed1833ab8893a2212d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832611Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701568}
parent 29b1bb2b
......@@ -126,7 +126,7 @@ class CrashNotificationDelegate : public message_center::NotificationDelegate {
BackgroundContentsService* service =
BackgroundContentsServiceFactory::GetForProfile(profile);
if (!service->GetAppBackgroundContents(extension_id))
service->LoadBackgroundContentsForExtension(profile, extension_id);
service->LoadBackgroundContentsForExtension(extension_id);
} else if (is_platform_app) {
apps::AppLoadService::Get(profile)->RestartApplication(extension_id);
} else {
......@@ -327,8 +327,8 @@ void BackgroundContentsService::StartObserving() {
}
void BackgroundContentsService::OnExtensionSystemReady() {
LoadBackgroundContentsFromManifests(profile_);
LoadBackgroundContentsFromPrefs(profile_);
LoadBackgroundContentsFromManifests();
LoadBackgroundContentsFromPrefs();
SendChangeNotification();
}
......@@ -358,8 +358,7 @@ void BackgroundContentsService::OnExtensionLoaded(
// Now load the manifest-specified background page. If service isn't
// ready, then the background page will be loaded from the
// EXTENSIONS_READY callback.
LoadBackgroundContents(profile,
BackgroundInfo::GetBackgroundURL(extension),
LoadBackgroundContents(BackgroundInfo::GetBackgroundURL(extension),
"background", extension->id());
}
}
......@@ -434,8 +433,7 @@ void BackgroundContentsService::OnExtensionUninstalled(
}
void BackgroundContentsService::RestartForceInstalledExtensionOnCrash(
const Extension* extension,
Profile* profile) {
const Extension* extension) {
int restart_delay = restart_delay_in_ms_;
// If the extension was a component extension, use exponential backoff when
......@@ -461,13 +459,12 @@ void BackgroundContentsService::RestartForceInstalledExtensionOnCrash(
}
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::BindOnce(&ReloadExtension, extension->id(), profile),
FROM_HERE, base::BindOnce(&ReloadExtension, extension->id(), profile_),
base::TimeDelta::FromMilliseconds(restart_delay));
}
// Loads all background contents whose urls have been stored in prefs.
void BackgroundContentsService::LoadBackgroundContentsFromPrefs(
Profile* profile) {
void BackgroundContentsService::LoadBackgroundContentsFromPrefs() {
if (!prefs_)
return;
const base::DictionaryValue* contents =
......@@ -475,7 +472,7 @@ void BackgroundContentsService::LoadBackgroundContentsFromPrefs(
if (!contents)
return;
extensions::ExtensionRegistry* extension_registry =
extensions::ExtensionRegistry::Get(profile);
extensions::ExtensionRegistry::Get(profile_);
DCHECK(extension_registry);
for (base::DictionaryValue::Iterator it(*contents); !it.IsAtEnd();
it.Advance()) {
......@@ -494,7 +491,7 @@ void BackgroundContentsService::LoadBackgroundContentsFromPrefs(
// load the next one.
continue;
}
LoadBackgroundContentsFromDictionary(profile, it.key(), contents);
LoadBackgroundContentsFromDictionary(it.key(), contents);
}
}
......@@ -520,15 +517,14 @@ void BackgroundContentsService::MaybeClearBackoffEntry(
}
void BackgroundContentsService::LoadBackgroundContentsForExtension(
Profile* profile,
const std::string& extension_id) {
// First look if the manifest specifies a background page.
const Extension* extension =
extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
extensions::ExtensionRegistry::Get(profile_)->GetExtensionById(
extension_id, extensions::ExtensionRegistry::ENABLED);
DCHECK(!extension || extension->is_hosted_app());
if (extension && BackgroundInfo::HasBackgroundPage(extension)) {
LoadBackgroundContents(profile, BackgroundInfo::GetBackgroundURL(extension),
LoadBackgroundContents(BackgroundInfo::GetBackgroundURL(extension),
"background", extension->id());
return;
}
......@@ -540,15 +536,14 @@ void BackgroundContentsService::LoadBackgroundContentsForExtension(
prefs_->GetDictionary(prefs::kRegisteredBackgroundContents);
if (!contents)
return;
LoadBackgroundContentsFromDictionary(profile, extension_id, contents);
LoadBackgroundContentsFromDictionary(extension_id, contents);
}
void BackgroundContentsService::LoadBackgroundContentsFromDictionary(
Profile* profile,
const std::string& extension_id,
const base::DictionaryValue* contents) {
extensions::ExtensionService* extensions_service =
extensions::ExtensionSystem::Get(profile)->extension_service();
extensions::ExtensionSystem::Get(profile_)->extension_service();
DCHECK(extensions_service);
const base::DictionaryValue* dict;
......@@ -560,24 +555,21 @@ void BackgroundContentsService::LoadBackgroundContentsFromDictionary(
std::string url;
dict->GetString(kUrlKey, &url);
dict->GetString(kFrameNameKey, &frame_name);
LoadBackgroundContents(profile, GURL(url), frame_name, extension_id);
LoadBackgroundContents(GURL(url), frame_name, extension_id);
}
void BackgroundContentsService::LoadBackgroundContentsFromManifests(
Profile* profile) {
void BackgroundContentsService::LoadBackgroundContentsFromManifests() {
for (const scoped_refptr<const extensions::Extension>& extension :
extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) {
extensions::ExtensionRegistry::Get(profile_)->enabled_extensions()) {
if (extension->is_hosted_app() &&
BackgroundInfo::HasBackgroundPage(extension.get())) {
LoadBackgroundContents(profile,
BackgroundInfo::GetBackgroundURL(extension.get()),
LoadBackgroundContents(BackgroundInfo::GetBackgroundURL(extension.get()),
"background", extension->id());
}
}
}
void BackgroundContentsService::LoadBackgroundContents(
Profile* profile,
const GURL& url,
const std::string& frame_name,
const std::string& application_id) {
......@@ -590,8 +582,8 @@ void BackgroundContentsService::LoadBackgroundContents(
DVLOG(1) << "Loading background content url: " << url;
BackgroundContents* contents = CreateBackgroundContents(
SiteInstance::CreateForURL(profile, url), nullptr, MSG_ROUTING_NONE,
MSG_ROUTING_NONE, MSG_ROUTING_NONE, profile, frame_name, application_id,
SiteInstance::CreateForURL(profile_, url), nullptr, MSG_ROUTING_NONE,
MSG_ROUTING_NONE, MSG_ROUTING_NONE, frame_name, application_id,
std::string(), nullptr);
contents->CreateRenderViewSoon(url);
......@@ -603,7 +595,6 @@ BackgroundContents* BackgroundContentsService::CreateBackgroundContents(
int32_t routing_id,
int32_t main_frame_route_id,
int32_t main_frame_widget_route_id,
Profile* profile,
const std::string& frame_name,
const std::string& application_id,
const std::string& partition_id,
......@@ -617,7 +608,7 @@ BackgroundContents* BackgroundContentsService::CreateBackgroundContents(
// to external listeners.
BackgroundContentsOpenedDetails details = {contents, frame_name,
application_id};
BackgroundContentsOpened(&details, profile);
BackgroundContentsOpened(&details);
for (auto& observer : observers_)
observer.OnBackgroundContentsOpened(details);
......@@ -680,15 +671,14 @@ void BackgroundContentsService::ShutdownAssociatedBackgroundContents(
}
void BackgroundContentsService::BackgroundContentsOpened(
BackgroundContentsOpenedDetails* details,
Profile* profile) {
BackgroundContentsOpenedDetails* details) {
// Add the passed object to our list. Should not already be tracked.
DCHECK(!IsTracked(details->contents));
DCHECK(!details->application_id.empty());
contents_map_[details->application_id].contents = details->contents;
contents_map_[details->application_id].frame_name = details->frame_name;
CloseBalloon(details->application_id, profile);
CloseBalloon(details->application_id, profile_);
}
// Used by test code and debug checks to verify whether a given
......@@ -796,6 +786,6 @@ void BackgroundContentsService::HandleExtensionCrashed(
ShowBalloon(extension, profile_);
} else {
// Restart the extension.
RestartForceInstalledExtensionOnCrash(extension, profile_);
RestartForceInstalledExtensionOnCrash(extension);
}
}
......@@ -118,16 +118,13 @@ class BackgroundContentsService : private content::NotificationObserver,
// Creates a new BackgroundContents using the passed |site| and
// the |route_id| and begins tracking the object internally so it can be
// shutdown if the parent application is uninstalled.
// A BACKGROUND_CONTENTS_OPENED notification will be generated with the passed
// |frame_name| and |application_id| values, using the passed |profile| as the
// Source.
// Observers will receive a OnBackgroundContentsOpened call.
BackgroundContents* CreateBackgroundContents(
scoped_refptr<content::SiteInstance> site,
content::RenderFrameHost* opener,
int32_t route_id,
int32_t main_frame_route_id,
int32_t main_frame_widget_route_id,
Profile* profile,
const std::string& frame_name,
const std::string& application_id,
const std::string& partition_id,
......@@ -137,8 +134,7 @@ class BackgroundContentsService : private content::NotificationObserver,
// If the manifest doesn't specify one, then load the BackgroundContents
// registered in the pref. This is typically used to reload a crashed
// background page.
void LoadBackgroundContentsForExtension(Profile* profile,
const std::string& extension_id);
void LoadBackgroundContentsForExtension(const std::string& extension_id);
private:
friend class BackgroundContentsServiceTest;
......@@ -172,34 +168,30 @@ class BackgroundContentsService : private content::NotificationObserver,
// Restarts a force-installed app/extension after a crash.
void RestartForceInstalledExtensionOnCrash(
const extensions::Extension* extension,
Profile* profile);
const extensions::Extension* extension);
// Loads all registered BackgroundContents at startup.
void LoadBackgroundContentsFromPrefs(Profile* profile);
void LoadBackgroundContentsFromPrefs();
// Load a BackgroundContent; the settings are read from the provided
// dictionary.
void LoadBackgroundContentsFromDictionary(
Profile* profile,
const std::string& extension_id,
const base::DictionaryValue* contents);
// Load the manifest-specified BackgroundContents for all apps for the
// profile.
void LoadBackgroundContentsFromManifests(Profile* profile);
void LoadBackgroundContentsFromManifests();
// Creates a single BackgroundContents associated with the specified |appid|,
// creates an associated RenderView with the name specified by |frame_name|,
// and navigates to the passed |url|.
void LoadBackgroundContents(Profile* profile,
const GURL& url,
void LoadBackgroundContents(const GURL& url,
const std::string& frame_name,
const std::string& appid);
// Invoked when a new BackgroundContents is opened.
void BackgroundContentsOpened(BackgroundContentsOpenedDetails* details,
Profile* profile);
void BackgroundContentsOpened(BackgroundContentsOpenedDetails* details);
// Registers the |contents->GetURL()| to be run at startup. Only happens for
// the first navigation after window.open() (future calls to
......
......@@ -68,15 +68,14 @@ class BackgroundContentsServiceTest : public testing::Test {
class MockBackgroundContents : public BackgroundContents {
public:
MockBackgroundContents(BackgroundContentsService* service,
Profile* profile,
const std::string& id)
: service_(service), appid_(id), profile_(profile) {}
MockBackgroundContents(BackgroundContentsService* service, Profile* profile)
: MockBackgroundContents(service, profile, "app_id") {}
: service_(service), appid_(id) {}
explicit MockBackgroundContents(BackgroundContentsService* service)
: MockBackgroundContents(service, "app_id") {}
void SendOpenedNotification() {
BackgroundContentsOpenedDetails details = {this, "background", appid_};
service_->BackgroundContentsOpened(&details, profile_);
service_->BackgroundContentsOpened(&details);
}
void Navigate(GURL url) {
......@@ -104,9 +103,6 @@ class MockBackgroundContents : public BackgroundContents {
// The ID of our parent application
std::string appid_;
// Parent profile
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(MockBackgroundContents);
};
......@@ -154,8 +150,7 @@ TEST_F(BackgroundContentsServiceTest, Create) {
TEST_F(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy) {
TestingProfile profile;
BackgroundContentsService service(&profile, command_line_.get());
MockBackgroundContents* contents =
new MockBackgroundContents(&service, &profile);
MockBackgroundContents* contents = new MockBackgroundContents(&service);
EXPECT_FALSE(service.IsTracked(contents));
contents->SendOpenedNotification();
EXPECT_TRUE(service.IsTracked(contents));
......@@ -172,7 +167,7 @@ TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAdded) {
GURL url2("http://a/");
{
std::unique_ptr<MockBackgroundContents> contents(
new MockBackgroundContents(&service, &profile));
new MockBackgroundContents(&service));
EXPECT_EQ(0U, GetPrefs(&profile)->size());
contents->SendOpenedNotification();
......@@ -194,8 +189,7 @@ TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAddedAndClosed) {
BackgroundContentsService service(&profile, command_line_.get());
GURL url("http://a/");
MockBackgroundContents* contents =
new MockBackgroundContents(&service, &profile);
MockBackgroundContents* contents = new MockBackgroundContents(&service);
EXPECT_EQ(0U, GetPrefs(&profile)->size());
contents->SendOpenedNotification();
contents->Navigate(url);
......@@ -216,7 +210,7 @@ TEST_F(BackgroundContentsServiceTest, RestartBackgroundContents) {
GURL url("http://a/");
{
std::unique_ptr<MockBackgroundContents> contents(
new MockBackgroundContents(&service, &profile, "appid"));
new MockBackgroundContents(&service, "appid"));
contents->SendOpenedNotification();
contents->Navigate(url);
EXPECT_EQ(1U, GetPrefs(&profile)->size());
......@@ -229,7 +223,7 @@ TEST_F(BackgroundContentsServiceTest, RestartBackgroundContents) {
// Reopen the BackgroundContents to the same URL, we should not register the
// URL again.
std::unique_ptr<MockBackgroundContents> contents(
new MockBackgroundContents(&service, &profile, "appid"));
new MockBackgroundContents(&service, "appid"));
contents->SendOpenedNotification();
contents->Navigate(url);
EXPECT_EQ(1U, GetPrefs(&profile)->size());
......@@ -245,9 +239,9 @@ TEST_F(BackgroundContentsServiceTest, TestApplicationIDLinkage) {
EXPECT_EQ(NULL, service.GetAppBackgroundContents("appid"));
MockBackgroundContents* contents =
new MockBackgroundContents(&service, &profile, "appid");
new MockBackgroundContents(&service, "appid");
std::unique_ptr<MockBackgroundContents> contents2(
new MockBackgroundContents(&service, &profile, "appid2"));
new MockBackgroundContents(&service, "appid2"));
contents->SendOpenedNotification();
EXPECT_EQ(contents, service.GetAppBackgroundContents(contents->appid()));
contents2->SendOpenedNotification();
......
......@@ -270,8 +270,8 @@ bool DriveWebContentsManager::ShouldCreateWebContents(
BackgroundContents* contents =
background_contents_service->CreateBackgroundContents(
content::SiteInstance::Create(profile_), nullptr, MSG_ROUTING_NONE,
MSG_ROUTING_NONE, MSG_ROUTING_NONE, profile_, frame_name, app_id_,
partition_id, session_storage_namespace);
MSG_ROUTING_NONE, MSG_ROUTING_NONE, frame_name, app_id_, partition_id,
session_storage_namespace);
contents->web_contents()->GetController().LoadURL(
target_url,
......
......@@ -2858,8 +2858,8 @@ BackgroundContents* Browser::CreateBackgroundContents(
if (allow_js_access) {
return service->CreateBackgroundContents(
source_site_instance, opener, route_id, main_frame_route_id,
main_frame_widget_route_id, profile_, frame_name, extension->id(),
partition_id, session_storage_namespace);
main_frame_widget_route_id, frame_name, extension->id(), partition_id,
session_storage_namespace);
}
// If script access is not allowed, create the the background contents in a
......@@ -2868,8 +2868,8 @@ BackgroundContents* Browser::CreateBackgroundContents(
// process.
BackgroundContents* contents = service->CreateBackgroundContents(
content::SiteInstance::Create(source_site_instance->GetBrowserContext()),
nullptr, MSG_ROUTING_NONE, MSG_ROUTING_NONE, MSG_ROUTING_NONE, profile_,
frame_name, extension->id(), partition_id, session_storage_namespace);
nullptr, MSG_ROUTING_NONE, MSG_ROUTING_NONE, MSG_ROUTING_NONE, frame_name,
extension->id(), partition_id, session_storage_namespace);
// When a separate process is used, the original renderer cannot access the
// new window later, thus we need to navigate the window now.
......
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