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_
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/api/profile_keyed_api_factory.h"
15 #include "chrome/browser/extensions/chrome_extension_function.h"
16 #include "chrome/browser/extensions/event_router.h"
17 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
18 #include "chrome/common/extensions/api/media_galleries_private.h"
22 namespace extensions {
24 class MediaGalleriesPrivateEventRouter;
26 // The profile-keyed service that manages the media galleries private extension
27 // API. Created at the same time as the Profile.
28 class MediaGalleriesPrivateAPI : public ProfileKeyedAPI,
29 public EventRouter::Observer {
31 explicit MediaGalleriesPrivateAPI(Profile* profile);
32 virtual ~MediaGalleriesPrivateAPI();
34 // BrowserContextKeyedService implementation.
35 virtual void Shutdown() OVERRIDE;
37 // ProfileKeyedAPI implementation.
38 static ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>* GetFactoryInstance();
40 // Convenience method to get the MediaGalleriesPrivateAPI for a profile.
41 static MediaGalleriesPrivateAPI* Get(Profile* profile);
43 // EventRouter::Observer implementation.
44 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
46 MediaGalleriesPrivateEventRouter* GetEventRouter();
47 GalleryWatchStateTracker* GetGalleryWatchStateTracker();
50 friend class ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>;
52 void MaybeInitializeEventRouterAndTracker();
54 // ProfileKeyedAPI implementation.
55 static const char* service_name() {
56 return "MediaGalleriesPrivateAPI";
58 static const bool kServiceIsNULLWhileTesting = true;
63 // Created lazily on first access.
64 scoped_ptr<GalleryWatchStateTracker> tracker_;
66 // Created lazily on first access.
67 scoped_ptr<MediaGalleriesPrivateEventRouter>
68 media_galleries_private_event_router_;
70 base::WeakPtrFactory<MediaGalleriesPrivateAPI> weak_ptr_factory_;
72 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateAPI);
75 // Implements the chrome.mediaGalleriesPrivate.addGalleryWatch method.
76 class MediaGalleriesPrivateAddGalleryWatchFunction
77 : public ChromeAsyncExtensionFunction {
79 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.addGalleryWatch",
80 MEDIAGALLERIESPRIVATE_ADDGALLERYWATCH);
83 virtual ~MediaGalleriesPrivateAddGalleryWatchFunction();
85 // AsyncExtensionFunction overrides.
86 virtual bool RunImpl() OVERRIDE;
89 void OnPreferencesInit(const std::string& pref_id);
91 // Gallery watch request handler.
92 void HandleResponse(MediaGalleryPrefId gallery_id, bool success);
95 // Implements the chrome.mediaGalleriesPrivate.removeGalleryWatch method.
96 class MediaGalleriesPrivateRemoveGalleryWatchFunction
97 : public ChromeAsyncExtensionFunction {
99 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.removeGalleryWatch",
100 MEDIAGALLERIESPRIVATE_REMOVEGALLERYWATCH);
103 virtual ~MediaGalleriesPrivateRemoveGalleryWatchFunction();
105 // SyncExtensionFunction overrides.
106 virtual bool RunImpl() OVERRIDE;
109 void OnPreferencesInit(const std::string& pref_id);
112 // Implements the chrome.mediaGalleriesPrivate.getAllGalleryWatch method.
113 class MediaGalleriesPrivateGetAllGalleryWatchFunction
114 : public ChromeAsyncExtensionFunction {
116 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.getAllGalleryWatch",
117 MEDIAGALLERIESPRIVATE_GETALLGALLERYWATCH);
119 virtual ~MediaGalleriesPrivateGetAllGalleryWatchFunction();
121 // SyncExtensionFunction overrides.
122 virtual bool RunImpl() OVERRIDE;
125 void OnPreferencesInit();
128 // Implements the chrome.mediaGalleriesPrivate.removeAllGalleryWatch method.
129 class MediaGalleriesPrivateRemoveAllGalleryWatchFunction
130 : public ChromeAsyncExtensionFunction {
132 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.removeAllGalleryWatch",
133 MEDIAGALLERIESPRIVATE_REMOVEALLGALLERYWATCH);
135 virtual ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction();
137 // SyncExtensionFunction overrides.
138 virtual bool RunImpl() OVERRIDE;
141 void OnPreferencesInit();
144 // Implements the chrome.mediaGalleriesPrivate.getHandlers method.
145 class MediaGalleriesPrivateGetHandlersFunction
146 : public ChromeAsyncExtensionFunction {
148 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.getHandlers",
149 MEDIAGALLERIESPRIVATE_GETHANDLERS);
152 virtual ~MediaGalleriesPrivateGetHandlersFunction();
154 // AsyncExtensionFunction overrides.
155 virtual bool RunImpl() OVERRIDE;
158 } // namespace extensions
160 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_MEDIA_GALLERIES_PRIVATE_API_H_