/chromium-webcl/src/chrome/browser/extensions/api/managed_mode_private/managed_mode_private_api.h

https://bitbucket.org/peixuan/chromium_r197479_base · C Header · 122 lines · 73 code · 34 blank · 15 comment · 0 complexity · 7ec5dab2b5f1133790ee178f6b6cf1f8 MD5 · raw file

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