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 // Defines the Chrome Extensions Managed Mode API relevant classes to realize |
| 6 // the API as specified in the extension API JSON. |
| 7 |
| 8 #ifndef CHROME_BROWSER_EXTENSIONS_API_MANAGED_MODE_PRIVATE_MANAGED_MODE_PRIVATE_
API_H_ |
| 9 #define CHROME_BROWSER_EXTENSIONS_API_MANAGED_MODE_PRIVATE_MANAGED_MODE_PRIVATE_
API_H_ |
| 10 |
| 11 #include "base/prefs/public/pref_change_registrar.h" |
| 12 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
| 13 #include "chrome/browser/extensions/event_router.h" |
| 14 #include "chrome/browser/extensions/extension_function.h" |
| 15 #include "content/public/browser/notification_observer.h" |
| 16 |
| 17 class Profile; |
| 18 |
| 19 namespace extensions { |
| 20 |
| 21 class ManagedModeEventRouter { |
| 22 public: |
| 23 explicit ManagedModeEventRouter(Profile* profile); |
| 24 virtual ~ManagedModeEventRouter(); |
| 25 |
| 26 private: |
| 27 void OnInManagedModeChanged(); |
| 28 |
| 29 PrefChangeRegistrar registrar_; |
| 30 Profile* profile_; |
| 31 |
| 32 DISALLOW_COPY_AND_ASSIGN(ManagedModeEventRouter); |
| 33 }; |
| 34 |
| 35 class ManagedModePrivateGetFunction : public SyncExtensionFunction { |
| 36 public: |
| 37 DECLARE_EXTENSION_FUNCTION("managedModePrivate.get", MANAGEDMODEPRIVATE_GET) |
| 38 |
| 39 protected: |
| 40 virtual ~ManagedModePrivateGetFunction(); |
| 41 |
| 42 // ExtensionFunction: |
| 43 virtual bool RunImpl() OVERRIDE; |
| 44 }; |
| 45 |
| 46 class ManagedModePrivateEnterFunction : public AsyncExtensionFunction { |
| 47 public: |
| 48 DECLARE_EXTENSION_FUNCTION("managedModePrivate.enter", |
| 49 MANAGEDMODEPRIVATE_ENTER) |
| 50 |
| 51 protected: |
| 52 virtual ~ManagedModePrivateEnterFunction(); |
| 53 |
| 54 // ExtensionFunction: |
| 55 virtual bool RunImpl() OVERRIDE; |
| 56 |
| 57 private: |
| 58 // Called when we have either successfully entered managed mode or failed. |
| 59 void SendResult(bool success); |
| 60 }; |
| 61 |
| 62 |
| 63 class ManagedModePrivateGetPolicyFunction : public SyncExtensionFunction { |
| 64 public: |
| 65 DECLARE_EXTENSION_FUNCTION("managedModePrivate.getPolicy", |
| 66 MANAGEDMODEPRIVATE_GETPOLICY) |
| 67 |
| 68 protected: |
| 69 virtual ~ManagedModePrivateGetPolicyFunction(); |
| 70 |
| 71 // ExtensionFunction: |
| 72 virtual bool RunImpl() OVERRIDE; |
| 73 }; |
| 74 |
| 75 class ManagedModePrivateSetPolicyFunction : public SyncExtensionFunction { |
| 76 public: |
| 77 DECLARE_EXTENSION_FUNCTION("managedModePrivate.setPolicy", |
| 78 MANAGEDMODEPRIVATE_SETPOLICY) |
| 79 |
| 80 protected: |
| 81 virtual ~ManagedModePrivateSetPolicyFunction(); |
| 82 |
| 83 // ExtensionFunction: |
| 84 virtual bool RunImpl() OVERRIDE; |
| 85 }; |
| 86 |
| 87 class ManagedModeAPI : public ProfileKeyedAPI, |
| 88 public extensions::EventRouter::Observer { |
| 89 public: |
| 90 explicit ManagedModeAPI(Profile* profile); |
| 91 virtual ~ManagedModeAPI(); |
| 92 |
| 93 // ProfileKeyedService implementation. |
| 94 virtual void Shutdown() OVERRIDE; |
| 95 |
| 96 // ProfileKeyedAPIFactory implementation. |
| 97 static ProfileKeyedAPIFactory<ManagedModeAPI>* GetFactoryInstance(); |
| 98 |
| 99 // EventRouter::Observer implementation. |
| 100 virtual void OnListenerAdded(const extensions::EventListenerInfo& details) |
| 101 OVERRIDE; |
| 102 |
| 103 private: |
| 104 friend class ProfileKeyedAPIFactory<ManagedModeAPI>; |
| 105 |
| 106 Profile* profile_; |
| 107 |
| 108 // ProfileKeyedAPI implementation. |
| 109 static const char* service_name() { |
| 110 return "ManagedModeAPI"; |
| 111 } |
| 112 static const bool kServiceIsNULLWhileTesting = true; |
| 113 |
| 114 // Created lazily upon OnListenerAdded. |
| 115 scoped_ptr<ManagedModeEventRouter> managed_mode_event_router_; |
| 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(ManagedModeAPI); |
| 118 }; |
| 119 |
| 120 } // namespace extensions |
| 121 |
| 122 #endif // CHROME_BROWSER_EXTENSIONS_API_MANAGED_MODE_PRIVATE_MANAGED_MODE_PRIVA
TE_API_H_ |
OLD | NEW |