| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_H_ | 5 #ifndef CHROME_BROWSER_MANAGED_MODE_H_ |
| 6 #define CHROME_BROWSER_MANAGED_MODE_H_ | 6 #define CHROME_BROWSER_MANAGED_MODE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 15 #include "chrome/browser/extensions/management_policy.h" | 16 #include "chrome/browser/extensions/management_policy.h" |
| 16 #include "chrome/browser/ui/browser_list_observer.h" | 17 #include "chrome/browser/ui/browser_list_observer.h" |
| 17 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 19 | 20 |
| 20 class Browser; | 21 class Browser; |
| 21 template<typename T> | 22 template<typename T> |
| 22 struct DefaultSingletonTraits; | 23 struct DefaultSingletonTraits; |
| 24 class ManagedModeURLFilter; |
| 23 class PrefService; | 25 class PrefService; |
| 24 class Profile; | 26 class Profile; |
| 25 | 27 |
| 26 // Managed mode allows one person to manage the Chrome experience for another | 28 // Managed mode allows one person to manage the Chrome experience for another |
| 27 // person by pre-configuring and then locking a managed User profile. | 29 // person by pre-configuring and then locking a managed User profile. |
| 28 // The ManagedMode class provides methods to check whether the browser is in | 30 // The ManagedMode class provides methods to check whether the browser is in |
| 29 // managed mode, and to attempt to enter or leave managed mode. | 31 // managed mode, and to attempt to enter or leave managed mode. |
| 32 // Except where otherwise noted, this class should be used on the UI thread. |
| 30 class ManagedMode : public chrome::BrowserListObserver, | 33 class ManagedMode : public chrome::BrowserListObserver, |
| 31 public extensions::ManagementPolicy::Provider, | 34 public extensions::ManagementPolicy::Provider, |
| 32 public content::NotificationObserver { | 35 public content::NotificationObserver { |
| 33 public: | 36 public: |
| 34 typedef base::Callback<void(bool)> EnterCallback; | 37 typedef base::Callback<void(bool)> EnterCallback; |
| 35 | 38 |
| 36 static void RegisterPrefs(PrefService* prefs); | 39 static void RegisterPrefs(PrefService* prefs); |
| 37 | 40 |
| 38 // Initializes the singleton, setting the managed_profile_. Must be called | 41 // Initializes the singleton, setting the managed_profile_. Must be called |
| 39 // after g_browser_process and the LocalState have been created. | 42 // after g_browser_process and the LocalState have been created. |
| 40 static void Init(Profile* profile); | 43 static void Init(Profile* profile); |
| 41 static bool IsInManagedMode(); | 44 static bool IsInManagedMode(); |
| 42 | 45 |
| 43 // Calls |callback| with the argument true iff managed mode was entered | 46 // Calls |callback| with the argument true iff managed mode was entered |
| 44 // sucessfully. | 47 // sucessfully. |
| 45 static void EnterManagedMode(Profile* profile, const EnterCallback& callback); | 48 static void EnterManagedMode(Profile* profile, const EnterCallback& callback); |
| 46 static void LeaveManagedMode(); | 49 static void LeaveManagedMode(); |
| 47 | 50 |
| 51 // Returns the URL filter. This method should only be called on the IO thread. |
| 52 static const ManagedModeURLFilter* GetURLFilter(); |
| 53 |
| 48 // ExtensionManagementPolicy::Provider implementation: | 54 // ExtensionManagementPolicy::Provider implementation: |
| 49 virtual std::string GetDebugPolicyProviderName() const OVERRIDE; | 55 virtual std::string GetDebugPolicyProviderName() const OVERRIDE; |
| 50 virtual bool UserMayLoad(const extensions::Extension* extension, | 56 virtual bool UserMayLoad(const extensions::Extension* extension, |
| 51 string16* error) const OVERRIDE; | 57 string16* error) const OVERRIDE; |
| 52 virtual bool UserMayModifySettings(const extensions::Extension* extension, | 58 virtual bool UserMayModifySettings(const extensions::Extension* extension, |
| 53 string16* error) const OVERRIDE; | 59 string16* error) const OVERRIDE; |
| 54 | 60 |
| 55 // chrome::BrowserListObserver implementation: | 61 // chrome::BrowserListObserver implementation: |
| 56 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; | 62 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; |
| 57 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | 63 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; |
| 58 | 64 |
| 59 // content::NotificationObserver implementation: | 65 // content::NotificationObserver implementation: |
| 60 virtual void Observe(int type, | 66 virtual void Observe(int type, |
| 61 const content::NotificationSource& source, | 67 const content::NotificationSource& source, |
| 62 const content::NotificationDetails& details) OVERRIDE; | 68 const content::NotificationDetails& details) OVERRIDE; |
| 63 | 69 |
| 64 protected: | 70 protected: |
| 65 ManagedMode(); | 71 ManagedMode(); |
| 66 virtual ~ManagedMode(); | 72 virtual ~ManagedMode(); |
| 67 void EnterManagedModeImpl(Profile* profile, const EnterCallback& callback); | 73 void EnterManagedModeImpl(Profile* profile, const EnterCallback& callback); |
| 68 | 74 |
| 69 // The managed profile. This is NULL iff we are not in managed mode. | 75 // The managed profile. This is NULL iff we are not in managed mode. |
| 70 Profile* managed_profile_; | 76 Profile* managed_profile_; |
| 71 | 77 |
| 72 private: | 78 private: |
| 79 class URLFilterContext; |
| 80 |
| 81 friend class Singleton<ManagedMode, LeakySingletonTraits<ManagedMode> >; |
| 73 friend struct DefaultSingletonTraits<ManagedMode>; | 82 friend struct DefaultSingletonTraits<ManagedMode>; |
| 74 friend class Singleton<ManagedMode>; | |
| 75 FRIEND_TEST_ALL_PREFIXES(ExtensionApiTest, ManagedModeOnChange); | 83 FRIEND_TEST_ALL_PREFIXES(ExtensionApiTest, ManagedModeOnChange); |
| 76 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 84 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 77 ManagedModeProhibitsModification); | 85 ManagedModeProhibitsModification); |
| 78 | 86 |
| 79 static ManagedMode* GetInstance(); | 87 static ManagedMode* GetInstance(); |
| 80 | 88 |
| 81 virtual void InitImpl(Profile* profile); | 89 virtual void InitImpl(Profile* profile); |
| 82 | 90 |
| 83 // Internal implementation for ExtensionManagementPolicy::Delegate methods. | 91 // Internal implementation for ExtensionManagementPolicy::Delegate methods. |
| 84 // If |error| is not NULL, it will be filled with an error message if the | 92 // If |error| is not NULL, it will be filled with an error message if the |
| 85 // requested extension action (install, modify status, etc.) is not permitted. | 93 // requested extension action (install, modify status, etc.) is not permitted. |
| 86 bool ExtensionManagementPolicyImpl(string16* error) const; | 94 bool ExtensionManagementPolicyImpl(string16* error) const; |
| 87 | 95 |
| 88 void LeaveManagedModeImpl(); | 96 void LeaveManagedModeImpl(); |
| 89 | 97 |
| 98 const ManagedModeURLFilter* GetURLFilterImpl(); |
| 99 |
| 90 void FinalizeEnter(bool result); | 100 void FinalizeEnter(bool result); |
| 91 | 101 |
| 92 // Platform-specific methods that confirm whether we can enter or leave | 102 // Platform-specific methods that confirm whether we can enter or leave |
| 93 // managed mode. | 103 // managed mode. |
| 94 virtual bool PlatformConfirmEnter(); | 104 virtual bool PlatformConfirmEnter(); |
| 95 virtual bool PlatformConfirmLeave(); | 105 virtual bool PlatformConfirmLeave(); |
| 96 | 106 |
| 97 virtual bool IsInManagedModeImpl() const; | 107 virtual bool IsInManagedModeImpl() const; |
| 98 | 108 |
| 99 // Enables or disables managed mode and registers or unregisters it with the | 109 // Enables or disables managed mode and registers or unregisters it with the |
| 100 // ManagementPolicy. If |newly_managed_profile| is NULL, managed mode will | 110 // ManagementPolicy. If |newly_managed_profile| is NULL, managed mode will |
| 101 // be disabled. Otherwise, managed mode will be enabled for that profile | 111 // be disabled. Otherwise, managed mode will be enabled for that profile |
| 102 // (typically |managed_profile_|, but other values are possible during | 112 // (typically |managed_profile_|, but other values are possible during |
| 103 // testing). | 113 // testing). |
| 104 virtual void SetInManagedMode(Profile* newly_managed_profile); | 114 virtual void SetInManagedMode(Profile* newly_managed_profile); |
| 105 | 115 |
| 116 void UpdateWhitelist(); |
| 117 |
| 106 content::NotificationRegistrar registrar_; | 118 content::NotificationRegistrar registrar_; |
| 107 | 119 |
| 120 scoped_ptr<URLFilterContext> url_filter_context_; |
| 121 |
| 108 std::set<Browser*> browsers_to_close_; | 122 std::set<Browser*> browsers_to_close_; |
| 109 std::vector<EnterCallback> callbacks_; | 123 std::vector<EnterCallback> callbacks_; |
| 110 | 124 |
| 111 DISALLOW_COPY_AND_ASSIGN(ManagedMode); | 125 DISALLOW_COPY_AND_ASSIGN(ManagedMode); |
| 112 }; | 126 }; |
| 113 | 127 |
| 114 #endif // CHROME_BROWSER_MANAGED_MODE_H_ | 128 #endif // CHROME_BROWSER_MANAGED_MODE_H_ |
| OLD | NEW |