forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebLayer] Make CaptivePortalService available
In preparation for sharing //chrome's SSLErrorHandler implementation, this CL makes CaptivePortalService available in WebLayer by adding a KeyedServiceFactory for it. //chrome's SSLErrorHandler requires a CaptivePortalService when captive portal detection is enabled (which it is on desktop platforms, i.e., Linux). The factory is modeled after that from //chrome, with a difference for the //weblayer environment: - The PrefService is passed via user_prefs::UserPrefs::Get() rather than via Profile::GetPrefs(). //weblayer's BrowserContextImpl has no getter for the PrefService, and as that getter is just a synonym for user_prefs::UserPrefs::Get() in //chrome, I see no reason to add it here. Note that this CL (and the bringup of support for Chrome's captive portal detection in WebLayer) will have no impact on Android, where Chrome's captive portal detection service is not enabled as SSLErrorHandler relies on the OS support. As this is the first instance of a KeyedServiceFactory in //weblayer, this CL also brings up the KeyedServiceFactory infrastructure in the //weblayer embedder. Bug: 1030692 Change-Id: Ic24c8a003f53598f9dd08f0da0ac87869398074f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2022671 Reviewed-by: Evan Stade <estade@chromium.org> Commit-Queue: Colin Blundell <blundell@chromium.org> Cr-Commit-Position: refs/heads/master@{#736777}
- Loading branch information
1 parent
2b4cb7d
commit 1fa65d2
Showing
6 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "weblayer/browser/captive_portal_service_factory.h" | ||
|
||
#include "components/captive_portal/content/captive_portal_service.h" | ||
#include "components/keyed_service/content/browser_context_dependency_manager.h" | ||
#include "components/user_prefs/user_prefs.h" | ||
#include "content/public/browser/browser_context.h" | ||
|
||
// static | ||
CaptivePortalService* CaptivePortalServiceFactory::GetForBrowserContext( | ||
content::BrowserContext* browser_context) { | ||
return static_cast<CaptivePortalService*>( | ||
GetInstance()->GetServiceForBrowserContext(browser_context, true)); | ||
} | ||
|
||
// static | ||
CaptivePortalServiceFactory* CaptivePortalServiceFactory::GetInstance() { | ||
return base::Singleton<CaptivePortalServiceFactory>::get(); | ||
} | ||
|
||
CaptivePortalServiceFactory::CaptivePortalServiceFactory() | ||
: BrowserContextKeyedServiceFactory( | ||
"CaptivePortalService", | ||
BrowserContextDependencyManager::GetInstance()) {} | ||
|
||
CaptivePortalServiceFactory::~CaptivePortalServiceFactory() = default; | ||
|
||
KeyedService* CaptivePortalServiceFactory::BuildServiceInstanceFor( | ||
content::BrowserContext* browser_context) const { | ||
return new CaptivePortalService(browser_context, | ||
user_prefs::UserPrefs::Get(browser_context)); | ||
} | ||
|
||
content::BrowserContext* CaptivePortalServiceFactory::GetBrowserContextToUse( | ||
content::BrowserContext* context) const { | ||
return context; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef WEBLAYER_BROWSER_CAPTIVE_PORTAL_SERVICE_FACTORY_H_ | ||
#define WEBLAYER_BROWSER_CAPTIVE_PORTAL_SERVICE_FACTORY_H_ | ||
|
||
#include "base/compiler_specific.h" | ||
#include "base/macros.h" | ||
#include "base/memory/singleton.h" | ||
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" | ||
|
||
class CaptivePortalService; | ||
|
||
// Singleton that owns all CaptivePortalServices and associates them with | ||
// BrowserContextImpl instances. | ||
class CaptivePortalServiceFactory : public BrowserContextKeyedServiceFactory { | ||
public: | ||
// Returns the CaptivePortalService for |browser_context|. | ||
static CaptivePortalService* GetForBrowserContext( | ||
content::BrowserContext* browser_context); | ||
|
||
static CaptivePortalServiceFactory* GetInstance(); | ||
|
||
private: | ||
friend struct base::DefaultSingletonTraits<CaptivePortalServiceFactory>; | ||
|
||
CaptivePortalServiceFactory(); | ||
~CaptivePortalServiceFactory() override; | ||
CaptivePortalServiceFactory(const CaptivePortalServiceFactory&) = delete; | ||
CaptivePortalServiceFactory& operator=(const CaptivePortalServiceFactory&) = | ||
delete; | ||
|
||
// BrowserContextKeyedServiceFactory: | ||
KeyedService* BuildServiceInstanceFor( | ||
content::BrowserContext* profile) const override; | ||
|
||
// Incognito profiles have their own instance of CaptivePortalService rather | ||
// than the default behavior of the service being null if the profile is | ||
// incognito. | ||
content::BrowserContext* GetBrowserContextToUse( | ||
content::BrowserContext* context) const override; | ||
}; | ||
|
||
#endif // WEBLAYER_BROWSER_CAPTIVE_PORTAL_SERVICE_FACTORY_H_ |