| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_ |
| 6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_ | 6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/prefs/pref_change_registrar.h" | 12 #include "base/prefs/pref_change_registrar.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "chrome/browser/extensions/management_policy.h" | 14 #include "chrome/browser/extensions/management_policy.h" |
| 15 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 15 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 17 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 17 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 18 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
| 18 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
| 20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 21 | 22 |
| 22 class Browser; | 23 class Browser; |
| 23 class GoogleServiceAuthError; | 24 class GoogleServiceAuthError; |
| 24 class ManagedModeURLFilter; | 25 class ManagedModeURLFilter; |
| 25 class ManagedModeSiteList; | 26 class ManagedModeSiteList; |
| 26 class ManagedUserRegistrationService; | 27 class ManagedUserRegistrationService; |
| 27 class Profile; | 28 class Profile; |
| 28 | 29 |
| 29 namespace policy { | 30 namespace policy { |
| 30 class ManagedModePolicyProvider; | 31 class ManagedModePolicyProvider; |
| 31 } | 32 } |
| 32 | 33 |
| 33 namespace user_prefs { | 34 namespace user_prefs { |
| 34 class PrefRegistrySyncable; | 35 class PrefRegistrySyncable; |
| 35 } | 36 } |
| 36 | 37 |
| 37 // This class handles all the information related to a given managed profile | 38 // This class handles all the information related to a given managed profile |
| 38 // (e.g. the installed content packs, the default URL filtering behavior, or | 39 // (e.g. the installed content packs, the default URL filtering behavior, or |
| 39 // manual whitelist/blacklist overrides). | 40 // manual whitelist/blacklist overrides). |
| 40 class ManagedUserService : public BrowserContextKeyedService, | 41 class ManagedUserService : public BrowserContextKeyedService, |
| 41 public extensions::ManagementPolicy::Provider, | 42 public extensions::ManagementPolicy::Provider, |
| 43 public ProfileSyncServiceObserver, |
| 42 public content::NotificationObserver { | 44 public content::NotificationObserver { |
| 43 public: | 45 public: |
| 44 typedef std::vector<string16> CategoryList; | 46 typedef std::vector<string16> CategoryList; |
| 45 | 47 |
| 46 enum ManualBehavior { | 48 enum ManualBehavior { |
| 47 MANUAL_NONE = 0, | 49 MANUAL_NONE = 0, |
| 48 MANUAL_ALLOW, | 50 MANUAL_ALLOW, |
| 49 MANUAL_BLOCK | 51 MANUAL_BLOCK |
| 50 }; | 52 }; |
| 51 | 53 |
| 52 explicit ManagedUserService(Profile* profile); | 54 explicit ManagedUserService(Profile* profile); |
| 53 virtual ~ManagedUserService(); | 55 virtual ~ManagedUserService(); |
| 54 | 56 |
| 57 // ProfileKeyedService override: |
| 58 virtual void Shutdown() OVERRIDE; |
| 59 |
| 55 bool ProfileIsManaged() const; | 60 bool ProfileIsManaged() const; |
| 56 | 61 |
| 57 // Checks whether the given profile is managed without constructing a | 62 // Checks whether the given profile is managed without constructing a |
| 58 // ManagedUserService (which could lead to cyclic dependencies). | 63 // ManagedUserService (which could lead to cyclic dependencies). |
| 59 static bool ProfileIsManaged(Profile* profile); | 64 static bool ProfileIsManaged(Profile* profile); |
| 60 | 65 |
| 61 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); | 66 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); |
| 62 | 67 |
| 63 // Returns whether managed users are enabled by Finch or the command line | 68 // Returns whether managed users are enabled by Finch or the command line |
| 64 // flag. | 69 // flag. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 void GetManualExceptionsForHost(const std::string& host, | 107 void GetManualExceptionsForHost(const std::string& host, |
| 103 std::vector<GURL>* urls); | 108 std::vector<GURL>* urls); |
| 104 | 109 |
| 105 // Initializes this object. This method does nothing if the profile is not | 110 // Initializes this object. This method does nothing if the profile is not |
| 106 // managed. | 111 // managed. |
| 107 void Init(); | 112 void Init(); |
| 108 | 113 |
| 109 // Marks the profile as managed and initializes it. | 114 // Marks the profile as managed and initializes it. |
| 110 void InitForTesting(); | 115 void InitForTesting(); |
| 111 | 116 |
| 112 // Initializes this profile for syncing, using the provided |token| to | 117 // Initializes this profile for syncing, using the provided |refresh_token| to |
| 113 // authenticate requests. | 118 // mint access tokens for Sync. |
| 114 void InitSync(const std::string& token); | 119 void InitSync(const std::string& refresh_token); |
| 115 | 120 |
| 116 // Convenience method that registers this managed user with | 121 // Convenience method that registers this managed user with |
| 117 // |registration_service| and initializes sync with the returned token. | 122 // |registration_service| and initializes sync with the returned token. |
| 118 // Note that |registration_service| should belong to the custodian's profile, | 123 // Note that |registration_service| should belong to the custodian's profile, |
| 119 // not this one. The |callback| will be called when registration is complete, | 124 // not this one. The |callback| will be called when registration is complete, |
| 120 // whether it suceeded or not -- unless registration was cancelled in the | 125 // whether it suceeded or not -- unless registration was cancelled in the |
| 121 // ManagedUserRegistrationService manually, in which case the callback will | 126 // ManagedUserRegistrationService manually, in which case the callback will |
| 122 // be ignored. | 127 // be ignored. |
| 123 void RegisterAndInitSync(Profile* custodian_profile, | 128 void RegisterAndInitSync(Profile* custodian_profile, |
| 124 const ProfileManager::CreateCallback& callback); | 129 const ProfileManager::CreateCallback& callback); |
| 125 | 130 |
| 126 // Returns a pseudo-email address for systems that expect well-formed email | 131 // Returns a pseudo-email address for systems that expect well-formed email |
| 127 // addresses (like Sync), even though we're not signed in. | 132 // addresses (like Sync), even though we're not signed in. |
| 128 static const char* GetManagedUserPseudoEmail(); | 133 static const char* GetManagedUserPseudoEmail(); |
| 129 | 134 |
| 130 void set_elevated_for_testing(bool skip) { | 135 void set_elevated_for_testing(bool skip) { |
| 131 elevated_for_testing_ = skip; | 136 elevated_for_testing_ = skip; |
| 132 } | 137 } |
| 133 | 138 |
| 134 // extensions::ManagementPolicy::Provider implementation: | 139 // extensions::ManagementPolicy::Provider implementation: |
| 135 virtual std::string GetDebugPolicyProviderName() const OVERRIDE; | 140 virtual std::string GetDebugPolicyProviderName() const OVERRIDE; |
| 136 virtual bool UserMayLoad(const extensions::Extension* extension, | 141 virtual bool UserMayLoad(const extensions::Extension* extension, |
| 137 string16* error) const OVERRIDE; | 142 string16* error) const OVERRIDE; |
| 138 virtual bool UserMayModifySettings(const extensions::Extension* extension, | 143 virtual bool UserMayModifySettings(const extensions::Extension* extension, |
| 139 string16* error) const OVERRIDE; | 144 string16* error) const OVERRIDE; |
| 140 | 145 |
| 146 // ProfileSyncServiceObserver implementation: |
| 147 virtual void OnStateChanged() OVERRIDE; |
| 148 |
| 141 // content::NotificationObserver implementation: | 149 // content::NotificationObserver implementation: |
| 142 virtual void Observe(int type, | 150 virtual void Observe(int type, |
| 143 const content::NotificationSource& source, | 151 const content::NotificationSource& source, |
| 144 const content::NotificationDetails& details) OVERRIDE; | 152 const content::NotificationDetails& details) OVERRIDE; |
| 145 | 153 |
| 146 private: | 154 private: |
| 147 friend class ManagedUserServiceExtensionTest; | 155 friend class ManagedUserServiceExtensionTest; |
| 148 | 156 |
| 149 // A bridge from ManagedMode (which lives on the UI thread) to the | 157 // A bridge from ManagedMode (which lives on the UI thread) to the |
| 150 // ManagedModeURLFilters, one of which lives on the IO thread. This class | 158 // ManagedModeURLFilters, one of which lives on the IO thread. This class |
| (...skipping 23 matching lines...) Expand all Loading... |
| 174 scoped_refptr<ManagedModeURLFilter> io_url_filter_; | 182 scoped_refptr<ManagedModeURLFilter> io_url_filter_; |
| 175 | 183 |
| 176 DISALLOW_COPY_AND_ASSIGN(URLFilterContext); | 184 DISALLOW_COPY_AND_ASSIGN(URLFilterContext); |
| 177 }; | 185 }; |
| 178 | 186 |
| 179 void OnManagedUserRegistered(const ProfileManager::CreateCallback& callback, | 187 void OnManagedUserRegistered(const ProfileManager::CreateCallback& callback, |
| 180 Profile* custodian_profile, | 188 Profile* custodian_profile, |
| 181 const GoogleServiceAuthError& auth_error, | 189 const GoogleServiceAuthError& auth_error, |
| 182 const std::string& token); | 190 const std::string& token); |
| 183 | 191 |
| 192 void SetupSync(); |
| 193 |
| 184 // Internal implementation for ExtensionManagementPolicy::Delegate methods. | 194 // Internal implementation for ExtensionManagementPolicy::Delegate methods. |
| 185 // If |error| is not NULL, it will be filled with an error message if the | 195 // If |error| is not NULL, it will be filled with an error message if the |
| 186 // requested extension action (install, modify status, etc.) is not permitted. | 196 // requested extension action (install, modify status, etc.) is not permitted. |
| 187 bool ExtensionManagementPolicyImpl(const std::string& extension_id, | 197 bool ExtensionManagementPolicyImpl(const std::string& extension_id, |
| 188 string16* error) const; | 198 string16* error) const; |
| 189 | 199 |
| 190 // Returns a list of all installed and enabled site lists in the current | 200 // Returns a list of all installed and enabled site lists in the current |
| 191 // managed profile. | 201 // managed profile. |
| 192 ScopedVector<ManagedModeSiteList> GetActiveSiteLists(); | 202 ScopedVector<ManagedModeSiteList> GetActiveSiteLists(); |
| 193 | 203 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 206 void UpdateManualURLs(); | 216 void UpdateManualURLs(); |
| 207 | 217 |
| 208 base::WeakPtrFactory<ManagedUserService> weak_ptr_factory_; | 218 base::WeakPtrFactory<ManagedUserService> weak_ptr_factory_; |
| 209 | 219 |
| 210 // Owns us via the BrowserContextKeyedService mechanism. | 220 // Owns us via the BrowserContextKeyedService mechanism. |
| 211 Profile* profile_; | 221 Profile* profile_; |
| 212 | 222 |
| 213 content::NotificationRegistrar registrar_; | 223 content::NotificationRegistrar registrar_; |
| 214 PrefChangeRegistrar pref_change_registrar_; | 224 PrefChangeRegistrar pref_change_registrar_; |
| 215 | 225 |
| 226 // True iff we're waiting for the Sync service to be initialized. |
| 227 bool waiting_for_sync_initialization_; |
| 228 |
| 216 // Sets a profile in elevated state for testing if set to true. | 229 // Sets a profile in elevated state for testing if set to true. |
| 217 bool elevated_for_testing_; | 230 bool elevated_for_testing_; |
| 218 | 231 |
| 219 URLFilterContext url_filter_context_; | 232 URLFilterContext url_filter_context_; |
| 220 }; | 233 }; |
| 221 | 234 |
| 222 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_ | 235 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_ |
| OLD | NEW |