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