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