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 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.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_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h"
......@@ -35,7 +34,6 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.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 "components/pref_registry/pref_registry_syncable.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
......@@ -43,9 +41,6 @@
#include "components/signin/core/browser/signin_manager_base.h"
#include "content/public/browser/browser_thread.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 "grit/generated_resources.h"
#include "net/base/escape.h"
......@@ -56,6 +51,14 @@
#include "chrome/browser/chromeos/login/users/user_manager.h"
#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)
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
......@@ -132,7 +135,9 @@ SupervisedUserService::SupervisedUserService(Profile* profile)
: profile_(profile),
active_(false),
delegate_(NULL),
#if defined(ENABLE_EXTENSIONS)
extension_registry_observer_(this),
#endif
waiting_for_sync_initialization_(false),
is_profile_active_(false),
elevated_for_testing_(false),
......@@ -253,6 +258,7 @@ void SupervisedUserService::DidBlockNavigation(
}
}
#if defined(ENABLE_EXTENSIONS)
std::string SupervisedUserService::GetDebugPolicyProviderName() const {
// Save the string space in official builds.
#ifdef NDEBUG
......@@ -306,21 +312,6 @@ bool SupervisedUserService::UserMayModifySettings(
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(
content::BrowserContext* browser_context,
const extensions::Extension* extension) {
......@@ -338,6 +329,22 @@ void SupervisedUserService::OnExtensionUnloaded(
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() {
StartSetupSync();
......@@ -381,6 +388,7 @@ void SupervisedUserService::FinishSetupSync() {
service->SetSyncSetupCompleted();
}
#if defined(ENABLE_EXTENSIONS)
bool SupervisedUserService::ExtensionManagementPolicyImpl(
const extensions::Extension* extension,
base::string16* error) const {
......@@ -423,6 +431,27 @@ SupervisedUserService::GetActiveSiteLists() {
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() {
return SupervisedUserSettingsServiceFactory::GetForProfile(profile_);
}
......@@ -444,7 +473,9 @@ void SupervisedUserService::OnDefaultFilteringBehaviorChanged() {
}
void SupervisedUserService::UpdateSiteLists() {
#if defined(ENABLE_EXTENSIONS)
url_filter_context_.LoadWhitelists(GetActiveSiteLists());
#endif
}
bool SupervisedUserService::AccessRequestsEnabled() {
......@@ -580,10 +611,9 @@ void SupervisedUserService::SetActive(bool active) {
SupervisedUserSettingsService* settings_service = GetSettingsService();
settings_service->SetActive(active_);
extensions::ExtensionSystem* extension_system =
extensions::ExtensionSystem::Get(profile_);
extensions::ManagementPolicy* management_policy =
extension_system->management_policy();
#if defined(ENABLE_EXTENSIONS)
SetExtensionsActive();
#endif
if (active_) {
if (CommandLine::ForCurrentProcess()->HasSwitch(
......@@ -600,12 +630,6 @@ void SupervisedUserService::SetActive(bool active) {
pref_service->GetString(prefs::kSupervisedUserId)));
}
if (management_policy)
management_policy->RegisterProvider(this);
extension_registry_observer_.Add(
extensions::ExtensionRegistry::Get(profile_));
pref_change_registrar_.Add(
prefs::kDefaultSupervisedUserFilteringBehavior,
base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged,
......@@ -631,11 +655,6 @@ void SupervisedUserService::SetActive(bool active) {
} else {
permissions_creator_.reset();
if (management_policy)
management_policy->UnregisterProvider(this);
extension_registry_observer_.RemoveAll();
pref_change_registrar_.Remove(
prefs::kDefaultSupervisedUserFilteringBehavior);
pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts);
......
......@@ -20,8 +20,11 @@
#include "chrome/browser/ui/browser_list_observer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/web_contents.h"
#if defined(ENABLE_EXTENSIONS)
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/management_policy.h"
#endif
class Browser;
class GoogleServiceAuthError;
......@@ -44,9 +47,11 @@ class PrefRegistrySyncable;
// (e.g. the installed content packs, the default URL filtering behavior, or
// manual whitelist/blacklist overrides).
class SupervisedUserService : public KeyedService,
#if defined(ENABLE_EXTENSIONS)
public extensions::ManagementPolicy::Provider,
public ProfileSyncServiceObserver,
public extensions::ExtensionRegistryObserver,
#endif
public ProfileSyncServiceObserver,
public chrome::BrowserListObserver {
public:
typedef std::vector<base::string16> CategoryList;
......@@ -149,6 +154,7 @@ class SupervisedUserService : public KeyedService,
void AddNavigationBlockedCallback(const NavigationBlockedCallback& callback);
void DidBlockNavigation(content::WebContents* web_contents);
#if defined(ENABLE_EXTENSIONS)
// extensions::ManagementPolicy::Provider implementation:
virtual std::string GetDebugPolicyProviderName() const OVERRIDE;
virtual bool UserMayLoad(const extensions::Extension* extension,
......@@ -156,9 +162,6 @@ class SupervisedUserService : public KeyedService,
virtual bool UserMayModifySettings(const extensions::Extension* extension,
base::string16* error) const OVERRIDE;
// ProfileSyncServiceObserver implementation:
virtual void OnStateChanged() OVERRIDE;
// extensions::ExtensionRegistryObserver implementation.
virtual void OnExtensionLoaded(
content::BrowserContext* browser_context,
......@@ -167,6 +170,10 @@ class SupervisedUserService : public KeyedService,
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
#endif
// ProfileSyncServiceObserver implementation:
virtual void OnStateChanged() OVERRIDE;
// chrome::BrowserListObserver implementation:
virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE;
......@@ -226,6 +233,7 @@ class SupervisedUserService : public KeyedService,
bool ProfileIsSupervised() const;
#if defined(ENABLE_EXTENSIONS)
// Internal implementation for ExtensionManagementPolicy::Delegate methods.
// 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.
......@@ -236,6 +244,10 @@ class SupervisedUserService : public KeyedService,
// supervised profile.
ScopedVector<SupervisedUserSiteList> GetActiveSiteLists();
// Extensions helper to SetActive().
void SetExtensionsActive();
#endif
SupervisedUserSettingsService* GetSettingsService();
void OnSupervisedUserIdChanged();
......@@ -259,9 +271,11 @@ class SupervisedUserService : public KeyedService,
Delegate* delegate_;
#if defined(ENABLE_EXTENSIONS)
ScopedObserver<extensions::ExtensionRegistry,
extensions::ExtensionRegistryObserver>
extension_registry_observer_;
#endif
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