Commit c14a6807 authored by thestig@chromium.org's avatar thestig@chromium.org

Add #ifdefs for the extensions parts of SupervisedUserService.

BUG=349436

Review URL: https://codereview.chromium.org/384893002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282709 0039d316-1c4b-4281-b951-d872f2087c98
parent 0beca257
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
...@@ -35,7 +34,6 @@ ...@@ -35,7 +34,6 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/supervised_user_private/supervised_user_handler.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h" #include "components/signin/core/browser/profile_oauth2_token_service.h"
...@@ -43,9 +41,6 @@ ...@@ -43,9 +41,6 @@
#include "components/signin/core/browser/signin_manager_base.h" #include "components/signin/core/browser/signin_manager_base.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/user_metrics.h" #include "content/public/browser/user_metrics.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension_set.h"
#include "google_apis/gaia/google_service_auth_error.h" #include "google_apis/gaia/google_service_auth_error.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "net/base/escape.h" #include "net/base/escape.h"
...@@ -56,6 +51,14 @@ ...@@ -56,6 +51,14 @@
#include "chrome/browser/chromeos/login/users/user_manager.h" #include "chrome/browser/chromeos/login/users/user_manager.h"
#endif #endif
#if defined(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/common/extensions/api/supervised_user_private/supervised_user_handler.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension_set.h"
#endif
#if defined(ENABLE_THEMES) #if defined(ENABLE_THEMES)
#include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/themes/theme_service_factory.h"
...@@ -132,7 +135,9 @@ SupervisedUserService::SupervisedUserService(Profile* profile) ...@@ -132,7 +135,9 @@ SupervisedUserService::SupervisedUserService(Profile* profile)
: profile_(profile), : profile_(profile),
active_(false), active_(false),
delegate_(NULL), delegate_(NULL),
#if defined(ENABLE_EXTENSIONS)
extension_registry_observer_(this), extension_registry_observer_(this),
#endif
waiting_for_sync_initialization_(false), waiting_for_sync_initialization_(false),
is_profile_active_(false), is_profile_active_(false),
elevated_for_testing_(false), elevated_for_testing_(false),
...@@ -253,6 +258,7 @@ void SupervisedUserService::DidBlockNavigation( ...@@ -253,6 +258,7 @@ void SupervisedUserService::DidBlockNavigation(
} }
} }
#if defined(ENABLE_EXTENSIONS)
std::string SupervisedUserService::GetDebugPolicyProviderName() const { std::string SupervisedUserService::GetDebugPolicyProviderName() const {
// Save the string space in official builds. // Save the string space in official builds.
#ifdef NDEBUG #ifdef NDEBUG
...@@ -306,21 +312,6 @@ bool SupervisedUserService::UserMayModifySettings( ...@@ -306,21 +312,6 @@ bool SupervisedUserService::UserMayModifySettings(
return ExtensionManagementPolicyImpl(extension, error); return ExtensionManagementPolicyImpl(extension, error);
} }
void SupervisedUserService::OnStateChanged() {
ProfileSyncService* service =
ProfileSyncServiceFactory::GetForProfile(profile_);
if (waiting_for_sync_initialization_ && service->sync_initialized()) {
waiting_for_sync_initialization_ = false;
service->RemoveObserver(this);
FinishSetupSync();
return;
}
DLOG_IF(ERROR, service->GetAuthError().state() ==
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)
<< "Credentials rejected";
}
void SupervisedUserService::OnExtensionLoaded( void SupervisedUserService::OnExtensionLoaded(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const extensions::Extension* extension) { const extensions::Extension* extension) {
...@@ -338,6 +329,22 @@ void SupervisedUserService::OnExtensionUnloaded( ...@@ -338,6 +329,22 @@ void SupervisedUserService::OnExtensionUnloaded(
UpdateSiteLists(); UpdateSiteLists();
} }
} }
#endif // defined(ENABLE_EXTENSIONS)
void SupervisedUserService::OnStateChanged() {
ProfileSyncService* service =
ProfileSyncServiceFactory::GetForProfile(profile_);
if (waiting_for_sync_initialization_ && service->sync_initialized()) {
waiting_for_sync_initialization_ = false;
service->RemoveObserver(this);
FinishSetupSync();
return;
}
DLOG_IF(ERROR, service->GetAuthError().state() ==
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)
<< "Credentials rejected";
}
void SupervisedUserService::SetupSync() { void SupervisedUserService::SetupSync() {
StartSetupSync(); StartSetupSync();
...@@ -381,6 +388,7 @@ void SupervisedUserService::FinishSetupSync() { ...@@ -381,6 +388,7 @@ void SupervisedUserService::FinishSetupSync() {
service->SetSyncSetupCompleted(); service->SetSyncSetupCompleted();
} }
#if defined(ENABLE_EXTENSIONS)
bool SupervisedUserService::ExtensionManagementPolicyImpl( bool SupervisedUserService::ExtensionManagementPolicyImpl(
const extensions::Extension* extension, const extensions::Extension* extension,
base::string16* error) const { base::string16* error) const {
...@@ -423,6 +431,27 @@ SupervisedUserService::GetActiveSiteLists() { ...@@ -423,6 +431,27 @@ SupervisedUserService::GetActiveSiteLists() {
return site_lists.Pass(); return site_lists.Pass();
} }
void SupervisedUserService::SetExtensionsActive() {
extensions::ExtensionSystem* extension_system =
extensions::ExtensionSystem::Get(profile_);
extensions::ManagementPolicy* management_policy =
extension_system->management_policy();
if (active_) {
if (management_policy)
management_policy->RegisterProvider(this);
extension_registry_observer_.Add(
extensions::ExtensionRegistry::Get(profile_));
} else {
if (management_policy)
management_policy->UnregisterProvider(this);
extension_registry_observer_.RemoveAll();
}
}
#endif // defined(ENABLE_EXTENSIONS)
SupervisedUserSettingsService* SupervisedUserService::GetSettingsService() { SupervisedUserSettingsService* SupervisedUserService::GetSettingsService() {
return SupervisedUserSettingsServiceFactory::GetForProfile(profile_); return SupervisedUserSettingsServiceFactory::GetForProfile(profile_);
} }
...@@ -444,7 +473,9 @@ void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { ...@@ -444,7 +473,9 @@ void SupervisedUserService::OnDefaultFilteringBehaviorChanged() {
} }
void SupervisedUserService::UpdateSiteLists() { void SupervisedUserService::UpdateSiteLists() {
#if defined(ENABLE_EXTENSIONS)
url_filter_context_.LoadWhitelists(GetActiveSiteLists()); url_filter_context_.LoadWhitelists(GetActiveSiteLists());
#endif
} }
bool SupervisedUserService::AccessRequestsEnabled() { bool SupervisedUserService::AccessRequestsEnabled() {
...@@ -580,10 +611,9 @@ void SupervisedUserService::SetActive(bool active) { ...@@ -580,10 +611,9 @@ void SupervisedUserService::SetActive(bool active) {
SupervisedUserSettingsService* settings_service = GetSettingsService(); SupervisedUserSettingsService* settings_service = GetSettingsService();
settings_service->SetActive(active_); settings_service->SetActive(active_);
extensions::ExtensionSystem* extension_system = #if defined(ENABLE_EXTENSIONS)
extensions::ExtensionSystem::Get(profile_); SetExtensionsActive();
extensions::ManagementPolicy* management_policy = #endif
extension_system->management_policy();
if (active_) { if (active_) {
if (CommandLine::ForCurrentProcess()->HasSwitch( if (CommandLine::ForCurrentProcess()->HasSwitch(
...@@ -600,12 +630,6 @@ void SupervisedUserService::SetActive(bool active) { ...@@ -600,12 +630,6 @@ void SupervisedUserService::SetActive(bool active) {
pref_service->GetString(prefs::kSupervisedUserId))); pref_service->GetString(prefs::kSupervisedUserId)));
} }
if (management_policy)
management_policy->RegisterProvider(this);
extension_registry_observer_.Add(
extensions::ExtensionRegistry::Get(profile_));
pref_change_registrar_.Add( pref_change_registrar_.Add(
prefs::kDefaultSupervisedUserFilteringBehavior, prefs::kDefaultSupervisedUserFilteringBehavior,
base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged,
...@@ -631,11 +655,6 @@ void SupervisedUserService::SetActive(bool active) { ...@@ -631,11 +655,6 @@ void SupervisedUserService::SetActive(bool active) {
} else { } else {
permissions_creator_.reset(); permissions_creator_.reset();
if (management_policy)
management_policy->UnregisterProvider(this);
extension_registry_observer_.RemoveAll();
pref_change_registrar_.Remove( pref_change_registrar_.Remove(
prefs::kDefaultSupervisedUserFilteringBehavior); prefs::kDefaultSupervisedUserFilteringBehavior);
pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts);
......
...@@ -20,8 +20,11 @@ ...@@ -20,8 +20,11 @@
#include "chrome/browser/ui/browser_list_observer.h" #include "chrome/browser/ui/browser_list_observer.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#if defined(ENABLE_EXTENSIONS)
#include "extensions/browser/extension_registry_observer.h" #include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/management_policy.h" #include "extensions/browser/management_policy.h"
#endif
class Browser; class Browser;
class GoogleServiceAuthError; class GoogleServiceAuthError;
...@@ -44,9 +47,11 @@ class PrefRegistrySyncable; ...@@ -44,9 +47,11 @@ class PrefRegistrySyncable;
// (e.g. the installed content packs, the default URL filtering behavior, or // (e.g. the installed content packs, the default URL filtering behavior, or
// manual whitelist/blacklist overrides). // manual whitelist/blacklist overrides).
class SupervisedUserService : public KeyedService, class SupervisedUserService : public KeyedService,
#if defined(ENABLE_EXTENSIONS)
public extensions::ManagementPolicy::Provider, public extensions::ManagementPolicy::Provider,
public ProfileSyncServiceObserver,
public extensions::ExtensionRegistryObserver, public extensions::ExtensionRegistryObserver,
#endif
public ProfileSyncServiceObserver,
public chrome::BrowserListObserver { public chrome::BrowserListObserver {
public: public:
typedef std::vector<base::string16> CategoryList; typedef std::vector<base::string16> CategoryList;
...@@ -149,6 +154,7 @@ class SupervisedUserService : public KeyedService, ...@@ -149,6 +154,7 @@ class SupervisedUserService : public KeyedService,
void AddNavigationBlockedCallback(const NavigationBlockedCallback& callback); void AddNavigationBlockedCallback(const NavigationBlockedCallback& callback);
void DidBlockNavigation(content::WebContents* web_contents); void DidBlockNavigation(content::WebContents* web_contents);
#if defined(ENABLE_EXTENSIONS)
// extensions::ManagementPolicy::Provider implementation: // extensions::ManagementPolicy::Provider implementation:
virtual std::string GetDebugPolicyProviderName() const OVERRIDE; virtual std::string GetDebugPolicyProviderName() const OVERRIDE;
virtual bool UserMayLoad(const extensions::Extension* extension, virtual bool UserMayLoad(const extensions::Extension* extension,
...@@ -156,9 +162,6 @@ class SupervisedUserService : public KeyedService, ...@@ -156,9 +162,6 @@ class SupervisedUserService : public KeyedService,
virtual bool UserMayModifySettings(const extensions::Extension* extension, virtual bool UserMayModifySettings(const extensions::Extension* extension,
base::string16* error) const OVERRIDE; base::string16* error) const OVERRIDE;
// ProfileSyncServiceObserver implementation:
virtual void OnStateChanged() OVERRIDE;
// extensions::ExtensionRegistryObserver implementation. // extensions::ExtensionRegistryObserver implementation.
virtual void OnExtensionLoaded( virtual void OnExtensionLoaded(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
...@@ -167,6 +170,10 @@ class SupervisedUserService : public KeyedService, ...@@ -167,6 +170,10 @@ class SupervisedUserService : public KeyedService,
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const extensions::Extension* extension, const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
#endif
// ProfileSyncServiceObserver implementation:
virtual void OnStateChanged() OVERRIDE;
// chrome::BrowserListObserver implementation: // chrome::BrowserListObserver implementation:
virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE; virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE;
...@@ -226,6 +233,7 @@ class SupervisedUserService : public KeyedService, ...@@ -226,6 +233,7 @@ class SupervisedUserService : public KeyedService,
bool ProfileIsSupervised() const; bool ProfileIsSupervised() const;
#if defined(ENABLE_EXTENSIONS)
// Internal implementation for ExtensionManagementPolicy::Delegate methods. // Internal implementation for ExtensionManagementPolicy::Delegate methods.
// If |error| is not NULL, it will be filled with an error message if the // If |error| is not NULL, it will be filled with an error message if the
// requested extension action (install, modify status, etc.) is not permitted. // requested extension action (install, modify status, etc.) is not permitted.
...@@ -236,6 +244,10 @@ class SupervisedUserService : public KeyedService, ...@@ -236,6 +244,10 @@ class SupervisedUserService : public KeyedService,
// supervised profile. // supervised profile.
ScopedVector<SupervisedUserSiteList> GetActiveSiteLists(); ScopedVector<SupervisedUserSiteList> GetActiveSiteLists();
// Extensions helper to SetActive().
void SetExtensionsActive();
#endif
SupervisedUserSettingsService* GetSettingsService(); SupervisedUserSettingsService* GetSettingsService();
void OnSupervisedUserIdChanged(); void OnSupervisedUserIdChanged();
...@@ -259,9 +271,11 @@ class SupervisedUserService : public KeyedService, ...@@ -259,9 +271,11 @@ class SupervisedUserService : public KeyedService,
Delegate* delegate_; Delegate* delegate_;
#if defined(ENABLE_EXTENSIONS)
ScopedObserver<extensions::ExtensionRegistry, ScopedObserver<extensions::ExtensionRegistry,
extensions::ExtensionRegistryObserver> extensions::ExtensionRegistryObserver>
extension_registry_observer_; extension_registry_observer_;
#endif
PrefChangeRegistrar pref_change_registrar_; PrefChangeRegistrar pref_change_registrar_;
......
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