Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_MEDIA_GALLERIES_PR IVATE_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_MEDIA_GALLERIES_PR IVATE_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_MEDIA_GALLERIES_PR IVATE_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_MEDIA_GALLERIES_PR IVATE_API_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | |
| 12 #include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_st ate_tracker.h" | 13 #include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_st ate_tracker.h" |
| 13 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" | 14 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
| 14 #include "chrome/browser/extensions/event_router.h" | 15 #include "chrome/browser/extensions/event_router.h" |
| 15 #include "chrome/browser/extensions/extension_function.h" | 16 #include "chrome/browser/extensions/extension_function.h" |
| 16 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 17 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
| 17 #include "chrome/browser/storage_monitor/storage_monitor.h" | 18 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 18 #include "chrome/common/extensions/api/media_galleries_private.h" | 19 #include "chrome/common/extensions/api/media_galleries_private.h" |
| 19 | 20 |
| 20 class Profile; | 21 class Profile; |
| 21 | 22 |
| 22 namespace extensions { | 23 namespace extensions { |
| 23 | 24 |
| 24 class MediaGalleriesPrivateEventRouter; | 25 class MediaGalleriesPrivateEventRouter; |
| 25 | 26 |
| 26 // The profile-keyed service that manages the media galleries private extension | 27 // The profile-keyed service that manages the media galleries private extension |
| 27 // API. | 28 // API. Created at the same time as the Profile. |
| 28 class MediaGalleriesPrivateAPI : public ProfileKeyedAPI, | 29 class MediaGalleriesPrivateAPI : public ProfileKeyedAPI, |
| 29 public EventRouter::Observer { | 30 public EventRouter::Observer { |
| 30 public: | 31 public: |
| 31 explicit MediaGalleriesPrivateAPI(Profile* profile); | 32 explicit MediaGalleriesPrivateAPI(Profile* profile); |
| 32 virtual ~MediaGalleriesPrivateAPI(); | 33 virtual ~MediaGalleriesPrivateAPI(); |
| 33 | 34 |
| 34 // BrowserContextKeyedService implementation. | 35 // BrowserContextKeyedService implementation. |
| 35 virtual void Shutdown() OVERRIDE; | 36 virtual void Shutdown() OVERRIDE; |
| 36 | 37 |
| 37 // ProfileKeyedAPI implementation. | 38 // ProfileKeyedAPI implementation. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 | 79 |
| 79 // ProfileKeyedAPI implementation. | 80 // ProfileKeyedAPI implementation. |
| 80 static const char* service_name() { | 81 static const char* service_name() { |
| 81 return "MediaGalleriesPrivateAPI"; | 82 return "MediaGalleriesPrivateAPI"; |
| 82 } | 83 } |
| 83 static const bool kServiceIsNULLWhileTesting = true; | 84 static const bool kServiceIsNULLWhileTesting = true; |
| 84 | 85 |
| 85 // Current profile. | 86 // Current profile. |
| 86 Profile* profile_; | 87 Profile* profile_; |
| 87 | 88 |
| 89 // Created lazily on first access. | |
| 88 scoped_ptr<GalleryWatchStateTracker> tracker_; | 90 scoped_ptr<GalleryWatchStateTracker> tracker_; |
| 89 | 91 |
| 90 // Created lazily on first access. | 92 // Created lazily on first access. |
| 91 scoped_ptr<MediaGalleriesPrivateEventRouter> | 93 scoped_ptr<MediaGalleriesPrivateEventRouter> |
| 92 media_galleries_private_event_router_; | 94 media_galleries_private_event_router_; |
| 93 | 95 |
| 96 base::WeakPtrFactory<MediaGalleriesPrivateAPI> weak_ptr_factory_; | |
| 97 | |
| 94 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateAPI); | 98 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateAPI); |
| 95 }; | 99 }; |
| 96 | 100 |
| 97 // Implements the chrome.mediaGalleriesPrivate.addGalleryWatch method. | 101 // Implements the chrome.mediaGalleriesPrivate.addGalleryWatch method. |
| 98 class MediaGalleriesPrivateAddGalleryWatchFunction | 102 class MediaGalleriesPrivateAddGalleryWatchFunction |
| 99 : public AsyncExtensionFunction { | 103 : public AsyncExtensionFunction { |
| 100 public: | 104 public: |
| 101 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.addGalleryWatch", | 105 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.addGalleryWatch", |
| 102 MEDIAGALLERIESPRIVATE_ADDGALLERYWATCH); | 106 MEDIAGALLERIESPRIVATE_ADDGALLERYWATCH); |
| 103 | 107 |
| 104 protected: | 108 protected: |
| 105 virtual ~MediaGalleriesPrivateAddGalleryWatchFunction(); | 109 virtual ~MediaGalleriesPrivateAddGalleryWatchFunction(); |
| 106 | 110 |
| 107 // AsyncExtensionFunction overrides. | 111 // AsyncExtensionFunction overrides. |
| 108 virtual bool RunImpl() OVERRIDE; | 112 virtual bool RunImpl() OVERRIDE; |
| 109 | 113 |
| 110 private: | 114 private: |
| 115 void OnStorageMonitorInit(const std::string& pref_id); | |
| 116 | |
| 111 // Gallery watch request handler. | 117 // Gallery watch request handler. |
| 112 void HandleResponse(chrome::MediaGalleryPrefId gallery_id, | 118 void HandleResponse(chrome::MediaGalleryPrefId gallery_id, |
| 113 bool success); | 119 bool success); |
| 114 }; | 120 }; |
| 115 | 121 |
| 116 // Implements the chrome.mediaGalleriesPrivate.removeGalleryWatch method. | 122 // Implements the chrome.mediaGalleriesPrivate.removeGalleryWatch method. |
| 117 class MediaGalleriesPrivateRemoveGalleryWatchFunction | 123 class MediaGalleriesPrivateRemoveGalleryWatchFunction |
| 118 : public SyncExtensionFunction { | 124 : public AsyncExtensionFunction { |
| 119 public: | 125 public: |
| 120 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.removeGalleryWatch", | 126 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.removeGalleryWatch", |
| 121 MEDIAGALLERIESPRIVATE_REMOVEGALLERYWATCH); | 127 MEDIAGALLERIESPRIVATE_REMOVEGALLERYWATCH); |
| 122 | 128 |
| 123 protected: | 129 protected: |
| 124 virtual ~MediaGalleriesPrivateRemoveGalleryWatchFunction(); | 130 virtual ~MediaGalleriesPrivateRemoveGalleryWatchFunction(); |
| 125 | 131 |
| 126 // SyncExtensionFunction overrides. | 132 // SyncExtensionFunction overrides. |
| 127 virtual bool RunImpl() OVERRIDE; | 133 virtual bool RunImpl() OVERRIDE; |
| 134 | |
| 135 private: | |
| 136 void OnStorageMonitorInit(const std::string& pref_id); | |
| 128 }; | 137 }; |
| 129 | 138 |
| 130 // Implements the chrome.mediaGalleriesPrivate.getAllGalleryWatch method. | 139 // Implements the chrome.mediaGalleriesPrivate.getAllGalleryWatch method. |
| 131 class MediaGalleriesPrivateGetAllGalleryWatchFunction | 140 class MediaGalleriesPrivateGetAllGalleryWatchFunction |
| 132 : public SyncExtensionFunction { | 141 : public AsyncExtensionFunction { |
| 133 public: | 142 public: |
| 134 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.getAllGalleryWatch", | 143 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.getAllGalleryWatch", |
| 135 MEDIAGALLERIESPRIVATE_GETALLGALLERYWATCH); | 144 MEDIAGALLERIESPRIVATE_GETALLGALLERYWATCH); |
| 136 protected: | 145 protected: |
| 137 virtual ~MediaGalleriesPrivateGetAllGalleryWatchFunction(); | 146 virtual ~MediaGalleriesPrivateGetAllGalleryWatchFunction(); |
| 138 | 147 |
| 139 // SyncExtensionFunction overrides. | 148 // SyncExtensionFunction overrides. |
| 140 virtual bool RunImpl() OVERRIDE; | 149 virtual bool RunImpl() OVERRIDE; |
| 150 | |
| 151 private: | |
| 152 void OnStorageMonitorInit(); | |
| 141 }; | 153 }; |
| 142 | 154 |
| 143 // Implements the chrome.mediaGalleriesPrivate.removeAllGalleryWatch method. | 155 // Implements the chrome.mediaGalleriesPrivate.removeAllGalleryWatch method. |
| 144 class MediaGalleriesPrivateRemoveAllGalleryWatchFunction | 156 class MediaGalleriesPrivateRemoveAllGalleryWatchFunction |
| 145 : public SyncExtensionFunction { | 157 : public SyncExtensionFunction { |
|
Lei Zhang
2013/06/03 06:01:35
async
Greg Billock
2013/06/03 15:30:57
Done.
| |
| 146 public: | 158 public: |
| 147 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.removeAllGalleryWatch", | 159 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.removeAllGalleryWatch", |
| 148 MEDIAGALLERIESPRIVATE_REMOVEALLGALLERYWATCH); | 160 MEDIAGALLERIESPRIVATE_REMOVEALLGALLERYWATCH); |
| 149 protected: | 161 protected: |
| 150 virtual ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction(); | 162 virtual ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction(); |
| 151 | 163 |
| 152 // SyncExtensionFunction overrides. | 164 // SyncExtensionFunction overrides. |
| 153 virtual bool RunImpl() OVERRIDE; | 165 virtual bool RunImpl() OVERRIDE; |
| 166 | |
| 167 private: | |
| 168 void OnStorageMonitorInit(); | |
| 154 }; | 169 }; |
| 155 | 170 |
| 156 // Implements the chrome.mediaGalleriesPrivate.ejectDevice method. | 171 // Implements the chrome.mediaGalleriesPrivate.ejectDevice method. |
| 157 class MediaGalleriesPrivateEjectDeviceFunction | 172 class MediaGalleriesPrivateEjectDeviceFunction |
| 158 : public AsyncExtensionFunction { | 173 : public AsyncExtensionFunction { |
| 159 public: | 174 public: |
| 160 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.ejectDevice", | 175 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.ejectDevice", |
| 161 MEDIAGALLERIESPRIVATE_EJECTDEVICE); | 176 MEDIAGALLERIESPRIVATE_EJECTDEVICE); |
| 162 | 177 |
| 163 protected: | 178 protected: |
| 164 virtual ~MediaGalleriesPrivateEjectDeviceFunction(); | 179 virtual ~MediaGalleriesPrivateEjectDeviceFunction(); |
| 165 | 180 |
| 166 // AsyncExtensionFunction overrides. | 181 // AsyncExtensionFunction overrides. |
| 167 virtual bool RunImpl() OVERRIDE; | 182 virtual bool RunImpl() OVERRIDE; |
| 168 | 183 |
| 169 private: | 184 private: |
| 185 void OnStorageMonitorInit(const std::string& transient_device_id); | |
| 186 | |
| 170 // Eject device request handler. | 187 // Eject device request handler. |
| 171 void HandleResponse(chrome::StorageMonitor::EjectStatus status); | 188 void HandleResponse(chrome::StorageMonitor::EjectStatus status); |
| 172 }; | 189 }; |
| 173 | 190 |
| 174 // Implements the chrome.mediaGalleriesPrivate.getHandlers method. | 191 // Implements the chrome.mediaGalleriesPrivate.getHandlers method. |
| 175 class MediaGalleriesPrivateGetHandlersFunction | 192 class MediaGalleriesPrivateGetHandlersFunction |
| 176 : public AsyncExtensionFunction { | 193 : public AsyncExtensionFunction { |
| 177 public: | 194 public: |
| 178 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.getHandlers", | 195 DECLARE_EXTENSION_FUNCTION("mediaGalleriesPrivate.getHandlers", |
| 179 MEDIAGALLERIESPRIVATE_GETHANDLERS); | 196 MEDIAGALLERIESPRIVATE_GETHANDLERS); |
| 180 | 197 |
| 181 protected: | 198 protected: |
| 182 virtual ~MediaGalleriesPrivateGetHandlersFunction(); | 199 virtual ~MediaGalleriesPrivateGetHandlersFunction(); |
| 183 | 200 |
| 184 // AsyncExtensionFunction overrides. | 201 // AsyncExtensionFunction overrides. |
| 185 virtual bool RunImpl() OVERRIDE; | 202 virtual bool RunImpl() OVERRIDE; |
| 186 }; | 203 }; |
| 187 | 204 |
| 188 } // namespace extensions | 205 } // namespace extensions |
| 189 | 206 |
| 190 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_MEDIA_GALLERIES _PRIVATE_API_H_ | 207 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_PRIVATE_MEDIA_GALLERIES _PRIVATE_API_H_ |
| OLD | NEW |