/chromium-webcl/src/chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.h

https://bitbucket.org/peixuan/chromium_r197479_base · C Header · 190 lines · 113 code · 43 blank · 34 comment · 0 complexity · addee814a5c33262fcd11b9450fd0cd3 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. #ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_MEDIA_GALLERIES_PRIVATE_API_H_
  5. #define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_MEDIA_GALLERIES_PRIVATE_API_H_
  6. #include <string>
  7. #include "base/memory/scoped_ptr.h"
  8. #include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.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 "chrome/browser/media_galleries/media_galleries_preferences.h"
  13. #include "chrome/browser/storage_monitor/storage_monitor.h"
  14. #include "chrome/common/extensions/api/media_galleries_private.h"
  15. class Profile;
  16. namespace extensions {
  17. class MediaGalleriesPrivateEventRouter;
  18. // The profile-keyed service that manages the media galleries private extension
  19. // API.
  20. class MediaGalleriesPrivateAPI : public ProfileKeyedAPI,
  21. public EventRouter::Observer {
  22. public:
  23. explicit MediaGalleriesPrivateAPI(Profile* profile);
  24. virtual ~MediaGalleriesPrivateAPI();
  25. // ProfileKeyedService implementation.
  26. virtual void Shutdown() OVERRIDE;
  27. // ProfileKeyedAPI implementation.
  28. static ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>* GetFactoryInstance();
  29. // Convenience method to get the MediaGalleriesPrivateAPI for a profile.
  30. static MediaGalleriesPrivateAPI* Get(Profile* profile);
  31. // Sets permission for the media galleries identified by |gallery_id| for the
  32. // extension in the given |prefs|.
  33. static void SetMediaGalleryPermission(ExtensionPrefs* prefs,
  34. const std::string& extension_id,
  35. chrome::MediaGalleryPrefId gallery_id,
  36. bool has_access);
  37. // Removes the entry for the media galleries permissions identified by
  38. // |gallery_id| for the extension in the given |prefs|.
  39. static void UnsetMediaGalleryPermission(
  40. ExtensionPrefs* prefs,
  41. const std::string& extension_id,
  42. chrome::MediaGalleryPrefId gallery_id);
  43. // Populate |result| with all media gallery permissions for the extension in
  44. // the given |prefs|.
  45. static void GetMediaGalleryPermissions(
  46. ExtensionPrefs* prefs,
  47. const std::string& extension_id,
  48. std::vector<chrome::MediaGalleryPermission>* result);
  49. // Remove all the media gallery permissions in |prefs| for the gallery
  50. // specified by |gallery_id|.
  51. static void RemoveMediaGalleryPermissions(
  52. ExtensionPrefs* prefs, chrome::MediaGalleryPrefId gallery_id);
  53. // EventRouter::Observer implementation.
  54. virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
  55. MediaGalleriesPrivateEventRouter* GetEventRouter();
  56. GalleryWatchStateTracker* GetGalleryWatchStateTracker();
  57. private:
  58. friend class ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>;
  59. void MaybeInitializeEventRouter();
  60. // ProfileKeyedAPI implementation.
  61. static const char* service_name() {
  62. return "MediaGalleriesPrivateAPI";
  63. }
  64. static const bool kServiceIsNULLWhileTesting = true;
  65. // Current profile.
  66. Profile* profile_;
  67. GalleryWatchStateTracker tracker_;
  68. // Created lazily on first access.
  69. scoped_ptr<MediaGalleriesPrivateEventRouter>
  70. media_galleries_private_event_router_;
  71. DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateAPI);
  72. };
  73. // Implements the chrome.mediaGalleriesPrivate.addGalleryWatch method.
  74. class MediaGalleriesPrivateAddGalleryWatchFunction
  75. : public AsyncExtensionFunction {
  76. public:
  77. DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.addGalleryWatch",
  78. MEDIAGALLERIESPRIVATE_ADDGALLERYWATCH);
  79. protected:
  80. virtual ~MediaGalleriesPrivateAddGalleryWatchFunction();
  81. // AsyncExtensionFunction overrides.
  82. virtual bool RunImpl() OVERRIDE;
  83. private:
  84. // Gallery watch request handler.
  85. void HandleResponse(chrome::MediaGalleryPrefId gallery_id,
  86. bool success);
  87. };
  88. // Implements the chrome.mediaGalleriesPrivate.removeGalleryWatch method.
  89. class MediaGalleriesPrivateRemoveGalleryWatchFunction
  90. : public SyncExtensionFunction {
  91. public:
  92. DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.removeGalleryWatch",
  93. MEDIAGALLERIESPRIVATE_REMOVEGALLERYWATCH);
  94. protected:
  95. virtual ~MediaGalleriesPrivateRemoveGalleryWatchFunction();
  96. // SyncExtensionFunction overrides.
  97. virtual bool RunImpl() OVERRIDE;
  98. };
  99. // Implements the chrome.mediaGalleriesPrivate.getAllGalleryWatch method.
  100. class MediaGalleriesPrivateGetAllGalleryWatchFunction
  101. : public SyncExtensionFunction {
  102. public:
  103. DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.getAllGalleryWatch",
  104. MEDIAGALLERIESPRIVATE_GETALLGALLERYWATCH);
  105. protected:
  106. virtual ~MediaGalleriesPrivateGetAllGalleryWatchFunction();
  107. // SyncExtensionFunction overrides.
  108. virtual bool RunImpl() OVERRIDE;
  109. };
  110. // Implements the chrome.mediaGalleriesPrivate.removeAllGalleryWatch method.
  111. class MediaGalleriesPrivateRemoveAllGalleryWatchFunction
  112. : public SyncExtensionFunction {
  113. public:
  114. DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.removeAllGalleryWatch",
  115. MEDIAGALLERIESPRIVATE_REMOVEALLGALLERYWATCH);
  116. protected:
  117. virtual ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction();
  118. // SyncExtensionFunction overrides.
  119. virtual bool RunImpl() OVERRIDE;
  120. };
  121. // Implements the chrome.mediaGalleriesPrivate.ejectDevice method.
  122. class MediaGalleriesPrivateEjectDeviceFunction
  123. : public AsyncExtensionFunction {
  124. public:
  125. DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.ejectDevice",
  126. MEDIAGALLERIESPRIVATE_EJECTDEVICE);
  127. protected:
  128. virtual ~MediaGalleriesPrivateEjectDeviceFunction();
  129. // AsyncExtensionFunction overrides.
  130. virtual bool RunImpl() OVERRIDE;
  131. private:
  132. // Eject device request handler.
  133. void HandleResponse(chrome::StorageMonitor::EjectStatus status);
  134. };
  135. // Implements the chrome.mediaGalleriesPrivate.getHandlers method.
  136. class MediaGalleriesPrivateGetHandlersFunction
  137. : public AsyncExtensionFunction {
  138. public:
  139. DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.getHandlers",
  140. MEDIAGALLERIESPRIVATE_GETHANDLERS);
  141. protected:
  142. virtual ~MediaGalleriesPrivateGetHandlersFunction();
  143. // AsyncExtensionFunction overrides.
  144. virtual bool RunImpl() OVERRIDE;
  145. };
  146. } // namespace extensions
  147. #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_MEDIA_GALLERIES_PRIVATE_API_H_