Enable Enterprise enrollment on desktop builds.
[chromium-blink-merge.git] / chrome / browser / extensions / api / media_galleries_private / media_galleries_private_api.h
blobbb897de7b16d941140692aca11675ab8dbcf3d0f
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_MEDIA_GALLERIES_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_MEDIA_GALLERIES_PRIVATE_API_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.h"
14 #include "chrome/browser/extensions/chrome_extension_function.h"
15 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
16 #include "chrome/common/extensions/api/media_galleries_private.h"
17 #include "extensions/browser/browser_context_keyed_api_factory.h"
18 #include "extensions/browser/event_router.h"
20 class Profile;
22 namespace content {
23 class BrowserContext;
26 namespace extensions {
28 class MediaGalleriesPrivateEventRouter;
30 // The profile-keyed service that manages the media galleries private extension
31 // API. Created at the same time as the Profile.
32 class MediaGalleriesPrivateAPI : public BrowserContextKeyedAPI,
33 public EventRouter::Observer {
34 public:
35 explicit MediaGalleriesPrivateAPI(content::BrowserContext* context);
36 virtual ~MediaGalleriesPrivateAPI();
38 // KeyedService implementation.
39 virtual void Shutdown() OVERRIDE;
41 // BrowserContextKeyedAPI implementation.
42 static BrowserContextKeyedAPIFactory<MediaGalleriesPrivateAPI>*
43 GetFactoryInstance();
45 // Convenience method to get the MediaGalleriesPrivateAPI for a profile.
46 static MediaGalleriesPrivateAPI* Get(content::BrowserContext* context);
48 // EventRouter::Observer implementation.
49 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
51 MediaGalleriesPrivateEventRouter* GetEventRouter();
52 GalleryWatchStateTracker* GetGalleryWatchStateTracker();
54 private:
55 friend class BrowserContextKeyedAPIFactory<MediaGalleriesPrivateAPI>;
57 void MaybeInitializeEventRouterAndTracker();
59 // BrowserContextKeyedAPI implementation.
60 static const char* service_name() {
61 return "MediaGalleriesPrivateAPI";
63 static const bool kServiceIsNULLWhileTesting = true;
65 // Current profile.
66 Profile* profile_;
68 // Created lazily on first access.
69 scoped_ptr<GalleryWatchStateTracker> tracker_;
71 // Created lazily on first access.
72 scoped_ptr<MediaGalleriesPrivateEventRouter>
73 media_galleries_private_event_router_;
75 base::WeakPtrFactory<MediaGalleriesPrivateAPI> weak_ptr_factory_;
77 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateAPI);
80 // Implements the chrome.mediaGalleriesPrivate.addGalleryWatch method.
81 class MediaGalleriesPrivateAddGalleryWatchFunction
82 : public ChromeAsyncExtensionFunction {
83 public:
84 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.addGalleryWatch",
85 MEDIAGALLERIESPRIVATE_ADDGALLERYWATCH);
87 protected:
88 virtual ~MediaGalleriesPrivateAddGalleryWatchFunction();
90 // AsyncExtensionFunction overrides.
91 virtual bool RunImpl() OVERRIDE;
93 private:
94 void OnPreferencesInit(const std::string& pref_id);
96 // Gallery watch request handler.
97 void HandleResponse(MediaGalleryPrefId gallery_id, bool success);
100 // Implements the chrome.mediaGalleriesPrivate.removeGalleryWatch method.
101 class MediaGalleriesPrivateRemoveGalleryWatchFunction
102 : public ChromeAsyncExtensionFunction {
103 public:
104 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.removeGalleryWatch",
105 MEDIAGALLERIESPRIVATE_REMOVEGALLERYWATCH);
107 protected:
108 virtual ~MediaGalleriesPrivateRemoveGalleryWatchFunction();
110 // SyncExtensionFunction overrides.
111 virtual bool RunImpl() OVERRIDE;
113 private:
114 void OnPreferencesInit(const std::string& pref_id);
117 // Implements the chrome.mediaGalleriesPrivate.getAllGalleryWatch method.
118 class MediaGalleriesPrivateGetAllGalleryWatchFunction
119 : public ChromeAsyncExtensionFunction {
120 public:
121 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.getAllGalleryWatch",
122 MEDIAGALLERIESPRIVATE_GETALLGALLERYWATCH);
123 protected:
124 virtual ~MediaGalleriesPrivateGetAllGalleryWatchFunction();
126 // SyncExtensionFunction overrides.
127 virtual bool RunImpl() OVERRIDE;
129 private:
130 void OnPreferencesInit();
133 // Implements the chrome.mediaGalleriesPrivate.removeAllGalleryWatch method.
134 class MediaGalleriesPrivateRemoveAllGalleryWatchFunction
135 : public ChromeAsyncExtensionFunction {
136 public:
137 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.removeAllGalleryWatch",
138 MEDIAGALLERIESPRIVATE_REMOVEALLGALLERYWATCH);
139 protected:
140 virtual ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction();
142 // SyncExtensionFunction overrides.
143 virtual bool RunImpl() OVERRIDE;
145 private:
146 void OnPreferencesInit();
149 // Implements the chrome.mediaGalleriesPrivate.getHandlers method.
150 class MediaGalleriesPrivateGetHandlersFunction
151 : public ChromeAsyncExtensionFunction {
152 public:
153 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.getHandlers",
154 MEDIAGALLERIESPRIVATE_GETHANDLERS);
156 protected:
157 virtual ~MediaGalleriesPrivateGetHandlersFunction();
159 // AsyncExtensionFunction overrides.
160 virtual bool RunImpl() OVERRIDE;
163 } // namespace extensions
165 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_MEDIA_GALLERIES_PRIVATE_API_H_