Commit 64399d62 authored by Randy Smith's avatar Randy Smith Committed by Commit Bot

Shift ExtensionCookieNotifier over to Mojo.

This also allows its removal from the ProfileIOData pathway as it is no
longer associated with the IO thread.

Bug: 721395
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: Ib58633ce6b8a597c9f4900d0bc3de2096e3d1bff
Reviewed-on: https://chromium-review.googlesource.com/806594Reviewed-by: default avatarNicolas Zea <zea@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Commit-Queue: Randy Smith <rdsmith@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525261}
parent 55c409db
......@@ -146,32 +146,28 @@ void CookiesEventRouter::CookieChanged(
switch (details->cause) {
// Report an inserted cookie as an "explicit" change cause. All other causes
// only make sense for deletions.
case net::CookieStore::ChangeCause::INSERTED:
case net::CookieStore::ChangeCause::EXPLICIT:
case net::CookieStore::ChangeCause::EXPLICIT_DELETE_BETWEEN:
case net::CookieStore::ChangeCause::EXPLICIT_DELETE_PREDICATE:
case net::CookieStore::ChangeCause::EXPLICIT_DELETE_SINGLE:
case net::CookieStore::ChangeCause::EXPLICIT_DELETE_CANONICAL:
case network::mojom::CookieChangeCause::INSERTED:
case network::mojom::CookieChangeCause::EXPLICIT:
cause = keys::kExplicitChangeCause;
break;
case net::CookieStore::ChangeCause::OVERWRITE:
case network::mojom::CookieChangeCause::OVERWRITE:
cause = keys::kOverwriteChangeCause;
break;
case net::CookieStore::ChangeCause::EXPIRED:
case network::mojom::CookieChangeCause::EXPIRED:
cause = keys::kExpiredChangeCause;
break;
case net::CookieStore::ChangeCause::EVICTED:
case network::mojom::CookieChangeCause::EVICTED:
cause = keys::kEvictedChangeCause;
break;
case net::CookieStore::ChangeCause::EXPIRED_OVERWRITE:
case network::mojom::CookieChangeCause::EXPIRED_OVERWRITE:
cause = keys::kExpiredOverwriteChangeCause;
break;
case net::CookieStore::ChangeCause::UNKNOWN_DELETION:
case network::mojom::CookieChangeCause::UNKNOWN_DELETION:
NOTREACHED();
}
dict->SetString(keys::kCauseKey, cause);
......
......@@ -11,61 +11,46 @@
#include "chrome/browser/net/chrome_cookie_notification_details.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
namespace {
void OnCookieChangedAsyncHelper(Profile* profile,
const net::CanonicalCookie& cookie,
bool removed,
net::CookieStore::ChangeCause cause) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Confirm the profile hasn't gone away since this object was created.
if (!g_browser_process->profile_manager()->IsValidProfile(profile))
return;
ChromeCookieDetails cookie_details(&cookie, removed, cause);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_COOKIE_CHANGED_FOR_EXTENSIONS,
content::Source<Profile>(profile),
content::Details<ChromeCookieDetails>(&cookie_details));
}
} // namespace
#include "content/public/browser/storage_partition.h"
#include "net/cookies/canonical_cookie.h"
ExtensionCookieNotifier::ExtensionCookieNotifier(Profile* profile)
: profile_(profile) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(profile);
DETACH_FROM_SEQUENCE(sequence_checker_);
}
void ExtensionCookieNotifier::AddStore(net::CookieStore* store) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
std::unique_ptr<net::CookieStore::CookieChangedSubscription> sub =
store->AddCallbackForAllChanges(
base::Bind(&ExtensionCookieNotifier::OnCookieChanged,
// |*store| is guaranteed to outlive this object, and
// this object's destruction will deregister the
// subscription.
base::Unretained(this)));
network::mojom::CookieManagerPtr manager_ptr;
subscriptions_.push_back(std::move(sub));
content::BrowserContext::GetDefaultStoragePartition(profile)
->GetNetworkContext()
->GetCookieManager(mojo::MakeRequest(&manager_ptr));
network::mojom::CookieChangeNotificationPtr notification_ptr;
binding_ =
std::make_unique<mojo::Binding<network::mojom::CookieChangeNotification>>(
this, mojo::MakeRequest(&notification_ptr));
manager_ptr->RequestGlobalNotifications(std::move(notification_ptr));
}
void ExtensionCookieNotifier::OnCookieChanged(
const net::CanonicalCookie& cookie,
net::CookieStore::ChangeCause cause) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
network::mojom::CookieChangeCause cause) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::BindOnce(&OnCookieChangedAsyncHelper, profile_, cookie,
!(cause == net::CookieStore::ChangeCause::INSERTED),
cause));
// Confirm the profile hasn't gone away since this object was created.
if (!g_browser_process->profile_manager()->IsValidProfile(profile_))
return;
ChromeCookieDetails cookie_details(
&cookie, cause != network::mojom::CookieChangeCause::INSERTED, cause);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_COOKIE_CHANGED_FOR_EXTENSIONS,
content::Source<Profile>(profile_),
content::Details<ChromeCookieDetails>(&cookie_details));
}
ExtensionCookieNotifier::~ExtensionCookieNotifier() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
......@@ -9,36 +9,32 @@
#include <vector>
#include "base/macros.h"
#include "base/sequence_checker.h"
#include "net/cookies/cookie_store.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/network/public/interfaces/cookie_manager.mojom.h"
class Profile;
namespace net {
class CanonicalCookie;
}
// Sends cookie-change notifications on the UI thread via
// chrome::NOTIFICATION_COOKIE_CHANGED_FOR_EXTENSIONS.
// This class must be used (AddStore() and OnCookieChanged() called) on a
// single thread, but it may be constructed on a different thread.
class ExtensionCookieNotifier {
// chrome::NOTIFICATION_COOKIE_CHANGED_FOR_EXTENSIONS for all cookie
// changes associated with the given profile.
class ExtensionCookieNotifier
: public network::mojom::CookieChangeNotification {
public:
explicit ExtensionCookieNotifier(Profile* profile);
~ExtensionCookieNotifier();
// Add a CookieStore for which cookie notifications will be transmitted.
// This store will be monitored until this object is destructed; i.e.
// |*store| must outlive this object.
// Must be called on the IO thread.
void AddStore(net::CookieStore* store);
~ExtensionCookieNotifier() override;
private:
// net::CookieStore::CookieChangedCallback implementation.
// network::mojom::CookieChangeNotification implementation.
void OnCookieChanged(const net::CanonicalCookie& cookie,
net::CookieStore::ChangeCause cause);
network::mojom::CookieChangeCause cause) override;
Profile* profile_;
std::vector<std::unique_ptr<net::CookieStore::CookieChangedSubscription>>
subscriptions_;
SEQUENCE_CHECKER(sequence_checker_);
std::unique_ptr<mojo::Binding<network::mojom::CookieChangeNotification>>
binding_;
DISALLOW_COPY_AND_ASSIGN(ExtensionCookieNotifier);
};
......
......@@ -368,7 +368,8 @@ void ExtensionSystemImpl::Shutdown() {
void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) {
TRACE_EVENT0("browser,startup", "ExtensionSystemImpl::InitForRegularProfile");
DCHECK(!profile_->IsOffTheRecord());
cookie_notifier_ = std::make_unique<ExtensionCookieNotifier>(profile_);
if (shared_user_script_master() || extension_service())
return; // Already initialized.
......@@ -377,6 +378,10 @@ void ExtensionSystemImpl::InitForRegularProfile(bool extensions_enabled) {
shared_->Init(extensions_enabled);
}
void ExtensionSystemImpl::InitForIncognitoProfile() {
cookie_notifier_ = std::make_unique<ExtensionCookieNotifier>(profile_);
}
ExtensionService* ExtensionSystemImpl::extension_service() {
return shared_->extension_service();
}
......
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/extension_cookie_notifier.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_system.h"
......@@ -49,6 +50,7 @@ class ExtensionSystemImpl : public ExtensionSystem {
void Shutdown() override;
void InitForRegularProfile(bool extensions_enabled) override;
void InitForIncognitoProfile() override;
ExtensionService* extension_service() override; // shared
RuntimeData* runtime_data() override; // shared
......@@ -160,6 +162,8 @@ class ExtensionSystemImpl : public ExtensionSystem {
OneShotEvent ready_;
};
std::unique_ptr<ExtensionCookieNotifier> cookie_notifier_;
Profile* profile_;
Shared* shared_;
......
......@@ -51,6 +51,7 @@ class TestExtensionSystem : public ExtensionSystem {
void CreateSocketManager();
void InitForRegularProfile(bool extensions_enabled) override {}
void InitForIncognitoProfile() override {}
void SetExtensionService(ExtensionService* service);
ExtensionService* extension_service() override;
RuntimeData* runtime_data() override;
......
......@@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_NET_CHROME_COOKIE_NOTIFICATION_DETAILS_H_
#define CHROME_BROWSER_NET_CHROME_COOKIE_NOTIFICATION_DETAILS_H_
#include "net/cookies/cookie_monster.h"
#include "services/network/public/interfaces/cookie_manager.mojom.h"
namespace net {
class CanonicalCookie;
......@@ -15,15 +15,12 @@ struct ChromeCookieDetails {
public:
ChromeCookieDetails(const net::CanonicalCookie* cookie_copy,
bool is_removed,
net::CookieStore::ChangeCause cause)
: cookie(cookie_copy),
removed(is_removed),
cause(cause) {
}
network::mojom::CookieChangeCause cause)
: cookie(cookie_copy), removed(is_removed), cause(cause) {}
const net::CanonicalCookie* cookie;
bool removed;
net::CookieStore::ChangeCause cause;
network::mojom::CookieChangeCause cause;
};
#endif // CHROME_BROWSER_NET_CHROME_COOKIE_NOTIFICATION_DETAILS_H_
......@@ -194,6 +194,8 @@ void OffTheRecordProfileImpl::Init() {
new extensions::ExtensionIconSource(profile_);
content::URLDataSource::Add(this, icon_source);
extensions::ExtensionSystem::Get(this)->InitForIncognitoProfile();
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&NotifyOTRProfileCreatedOnIOThread, profile_, this));
......
......@@ -116,7 +116,6 @@
#include "third_party/WebKit/public/public_features.h"
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/extension_cookie_notifier.h"
#include "extensions/browser/extension_protocols.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_throttle_manager.h"
......@@ -433,8 +432,6 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) {
#if BUILDFLAG(ENABLE_EXTENSIONS)
params->extension_info_map =
extensions::ExtensionSystem::Get(profile)->info_map();
params->extension_cookie_notifier =
base::MakeUnique<ExtensionCookieNotifier>(profile);
#endif
if (auto* loading_predictor =
......@@ -1240,14 +1237,6 @@ void ProfileIOData::Init(
!GetMetricsEnabledStateOnIOThread());
}
#if BUILDFLAG(ENABLE_EXTENSIONS)
extension_cookie_notifier_ =
std::move(profile_params_->extension_cookie_notifier);
// Cookie store will outlive notifier by order of declaration in
// profile_io_data.h.
extension_cookie_notifier_->AddStore(main_request_context_->cookie_store());
#endif
// Attach some things to the URLRequestContextBuilder's
// TransportSecurityState. Since no requests have been made yet, safe to do
// this even after the call to Build().
......@@ -1262,7 +1251,7 @@ void ProfileIOData::Init(
"stricter security policies, such as with HTTP Public Key Pinning. "
"Websites can use this feature to discover misconfigurations that "
"prevent them from complying with stricter security policies that "
"they've opted in to."
"they\'ve opted in to."
trigger:
"Chrome observes that a user is loading a resource from a website "
"that has opted in for security policy reports, and the connection "
......
......@@ -42,7 +42,6 @@ class ChromeHttpUserAgentSettings;
class ChromeNetworkDelegate;
class ChromeURLRequestContextGetter;
class ChromeExpectCTReporter;
class ExtensionCookieNotifier;
class HostContentSettingsMap;
class ProtocolHandlerRegistry;
......@@ -338,7 +337,6 @@ class ProfileIOData {
scoped_refptr<net::SSLConfigService> ssl_config_service;
#if BUILDFLAG(ENABLE_EXTENSIONS)
scoped_refptr<extensions::InfoMap> extension_info_map;
std::unique_ptr<ExtensionCookieNotifier> extension_cookie_notifier;
#endif
std::unique_ptr<chrome_browser_net::LoadingPredictorObserver>
loading_predictor_observer_;
......@@ -634,7 +632,6 @@ class ProfileIOData {
// Is NULL if switches::kDisableExtensionsHttpThrottling is on.
mutable std::unique_ptr<extensions::ExtensionThrottleManager>
extension_throttle_manager_;
mutable std::unique_ptr<ExtensionCookieNotifier> extension_cookie_notifier_;
#endif
mutable std::unique_ptr<certificate_transparency::TreeStateTracker>
......
......@@ -29,7 +29,8 @@ ExtensionDataTypeController::~ExtensionDataTypeController() {}
bool ExtensionDataTypeController::StartModels() {
DCHECK(CalledOnValidThread());
extensions::ExtensionSystem::Get(profile_)->InitForRegularProfile(true);
extensions::ExtensionSystem::Get(profile_)->InitForRegularProfile(
true /* extensions_enabled */);
return true;
}
......
......@@ -33,7 +33,8 @@ ExtensionSettingDataTypeController::~ExtensionSettingDataTypeController() {}
bool ExtensionSettingDataTypeController::StartModels() {
DCHECK(CalledOnValidThread());
extensions::ExtensionSystem::Get(profile_)->InitForRegularProfile(true);
extensions::ExtensionSystem::Get(profile_)->InitForRegularProfile(
true /* extensions_enabled */);
return true;
}
......
......@@ -25,7 +25,8 @@ ThemeDataTypeController::~ThemeDataTypeController() {}
bool ThemeDataTypeController::StartModels() {
DCHECK(CalledOnValidThread());
extensions::ExtensionSystem::Get(profile_)->InitForRegularProfile(true);
extensions::ExtensionSystem::Get(profile_)->InitForRegularProfile(
true /* extensions_enabled */);
return true;
}
......
......@@ -149,12 +149,12 @@ void SyncAppHelper::SetupIfNecessary(SyncTest* test) {
return;
for (int i = 0; i < test->num_clients(); ++i) {
extensions::ExtensionSystem::Get(
test->GetProfile(i))->InitForRegularProfile(true);
extensions::ExtensionSystem::Get(test->GetProfile(i))
->InitForRegularProfile(true /* extensions_enabled */);
}
if (test->use_verifier()) {
extensions::ExtensionSystem::Get(test->verifier())
->InitForRegularProfile(true);
->InitForRegularProfile(true /* extensions_enabled */);
}
setup_completed_ = true;
......
......@@ -41,7 +41,8 @@ void SyncAppListHelper::SetupIfNecessary(SyncTest* test) {
}
test_ = test;
for (auto* profile : test_->GetAllProfiles()) {
extensions::ExtensionSystem::Get(profile)->InitForRegularProfile(true);
extensions::ExtensionSystem::Get(profile)->InitForRegularProfile(
true /* extensions_enabled */);
}
setup_completed_ = true;
......
......@@ -312,7 +312,8 @@ bool SyncExtensionHelper::ExtensionNameToIndex(const std::string& name,
}
void SyncExtensionHelper::SetupProfile(Profile* profile) {
extensions::ExtensionSystem::Get(profile)->InitForRegularProfile(true);
extensions::ExtensionSystem::Get(profile)->InitForRegularProfile(
true /* extensions_enabled */);
profile_extensions_.insert(make_pair(profile, ExtensionNameMap()));
}
......
......@@ -389,7 +389,8 @@ IN_PROC_BROWSER_TEST_F(ProfileChooserViewExtensionsTest,
// Create a different profile and then lock it.
Profile* signed_in = CreateTestingProfile("signed_in");
SetupProfilesForLock(signed_in);
extensions::ExtensionSystem::Get(signed_in)->InitForRegularProfile(true);
extensions::ExtensionSystem::Get(signed_in)->InitForRegularProfile(
true /* extensions_enabled */);
Browser* browser_to_lock = CreateBrowser(signed_in);
EXPECT_EQ(2U, BrowserList::GetInstance()->size());
......
......@@ -57,8 +57,12 @@ class ExtensionSystem : public KeyedService {
// Initializes extensions machinery.
// Component extensions are always enabled, external and user extensions are
// controlled by |extensions_enabled|.
// controlled (for both incognito and non-incognito profiles) by the
// |extensions_enabled| flag passed to non-incognito initialization.
// These calls should occur after the profile IO data is initialized,
// as extensions initialization depends on that.
virtual void InitForRegularProfile(bool extensions_enabled) = 0;
virtual void InitForIncognitoProfile() = 0;
// The ExtensionService is created at startup. ExtensionService is only
// defined in Chrome.
......
......@@ -16,8 +16,9 @@ MockExtensionSystem::MockExtensionSystem(content::BrowserContext* context)
MockExtensionSystem::~MockExtensionSystem() {
}
void MockExtensionSystem::InitForRegularProfile(bool extensions_enabled) {
}
void MockExtensionSystem::InitForRegularProfile(bool extensions_enabled) {}
void MockExtensionSystem::InitForIncognitoProfile() {}
ExtensionService* MockExtensionSystem::extension_service() {
return nullptr;
......
......@@ -30,6 +30,7 @@ class MockExtensionSystem : public ExtensionSystem {
// ExtensionSystem overrides:
void InitForRegularProfile(bool extensions_enabled) override;
void InitForIncognitoProfile() override;
ExtensionService* extension_service() override;
RuntimeData* runtime_data() override;
ManagementPolicy* management_policy() override;
......
......@@ -92,7 +92,7 @@ void DefaultShellBrowserMainDelegate::Start(
content::BrowserContext* browser_context) {
ShellExtensionSystem* extension_system =
static_cast<ShellExtensionSystem*>(ExtensionSystem::Get(browser_context));
extension_system->Init();
extension_system->FinishInitialization();
LoadExtensionsFromCommandLine(extension_system);
LoadAppsFromCommandLine(extension_system, browser_context);
......
......@@ -313,7 +313,7 @@ void ShellBrowserMainParts::CreateExtensionSystem() {
DCHECK(browser_context_);
extension_system_ = static_cast<ShellExtensionSystem*>(
ExtensionSystem::Get(browser_context_.get()));
extension_system_->InitForRegularProfile(true);
extension_system_->InitForRegularProfile(true /* extensions_enabled */);
}
} // namespace extensions
......@@ -93,7 +93,7 @@ const Extension* ShellExtensionSystem::LoadApp(const base::FilePath& app_dir) {
return LoadExtension(app_dir);
}
void ShellExtensionSystem::Init() {
void ShellExtensionSystem::FinishInitialization() {
// Inform the rest of the extensions system to start.
ready_.Signal();
content::NotificationService::current()->Notify(
......@@ -125,6 +125,10 @@ void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) {
app_sorting_.reset(new NullAppSorting);
}
void ShellExtensionSystem::InitForIncognitoProfile() {
NOTREACHED();
}
ExtensionService* ShellExtensionSystem::extension_service() {
return nullptr;
}
......
......@@ -43,8 +43,8 @@ class ShellExtensionSystem : public ExtensionSystem {
// than other extensions. Use LaunchApp() to actually launch the loaded app.
const Extension* LoadApp(const base::FilePath& app_dir);
// Initializes the extension system.
void Init();
// Finish initialization for the shell extension system.
void FinishInitialization();
// Launch the app with id |extension_id|.
void LaunchApp(const std::string& extension_id);
......@@ -54,6 +54,7 @@ class ShellExtensionSystem : public ExtensionSystem {
// ExtensionSystem implementation:
void InitForRegularProfile(bool extensions_enabled) override;
void InitForIncognitoProfile() override;
ExtensionService* extension_service() override;
RuntimeData* runtime_data() override;
ManagementPolicy* management_policy() override;
......
......@@ -52,7 +52,7 @@ void AppShellTest::PreRunTestOnMainThread() {
extension_system_ = static_cast<ShellExtensionSystem*>(
ExtensionSystem::Get(browser_context_));
extension_system_->Init();
extension_system_->FinishInitialization();
DCHECK(base::MessageLoopForUI::IsCurrent());
base::RunLoop().RunUntilIdle();
}
......
......@@ -845,6 +845,11 @@
-PPAPINaClPNaClNonSfiTest.FileRef2
-PPAPINaClPNaClNonSfiTest.URLLoader1
# Disabled for first phase of extension system shift; will be re-enabled in
# https://chromium-review.googlesource.com/c/chromium/src/+/776017.
-ExtensionApiTest.CookiesEventsSpanning
-ExtensionApiTest.CookiesEvents
# Prevent tests from making real network requests.
# https://crbug.com/793899
-ExtensionApiTest.DoNotOpenUninstallUrlForBlacklistedExtensions
......
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