| 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 // Defines the Chrome Extensions Media Galleries API functions for accessing | 5 // Defines the Chrome Extensions Media Galleries API functions for accessing |
| 6 // user's media files, as specified in the extension API IDL. | 6 // user's media files, as specified in the extension API IDL. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ | 8 #ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ |
| 9 #define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ | 9 #define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ |
| 10 | 10 |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/callback_forward.h" | 16 #include "base/callback_forward.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "chrome/browser/extensions/chrome_extension_function.h" | 20 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 21 #include "chrome/browser/media_galleries/gallery_watch_manager_observer.h" | 21 #include "chrome/browser/media_galleries/gallery_watch_manager_observer.h" |
| 22 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 22 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 23 #include "chrome/browser/media_galleries/media_scan_manager_observer.h" | |
| 24 #include "chrome/common/extensions/api/media_galleries.h" | 23 #include "chrome/common/extensions/api/media_galleries.h" |
| 25 #include "chrome/common/media_galleries/metadata_types.h" | 24 #include "chrome/common/media_galleries/metadata_types.h" |
| 26 #include "components/storage_monitor/media_storage_util.h" | 25 #include "components/storage_monitor/media_storage_util.h" |
| 27 #include "extensions/browser/browser_context_keyed_api_factory.h" | 26 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 28 #include "extensions/browser/event_router.h" | 27 #include "extensions/browser/event_router.h" |
| 29 #include "extensions/browser/extension_event_histogram_value.h" | 28 #include "extensions/browser/extension_event_histogram_value.h" |
| 30 | 29 |
| 31 namespace MediaGalleries = extensions::api::media_galleries; | 30 namespace MediaGalleries = extensions::api::media_galleries; |
| 32 | 31 |
| 33 class MediaGalleriesScanResultController; | |
| 34 | |
| 35 namespace content { | 32 namespace content { |
| 36 class BlobHandle; | 33 class BlobHandle; |
| 37 class WebContents; | 34 class WebContents; |
| 38 } | 35 } |
| 39 | 36 |
| 40 namespace metadata { | 37 namespace metadata { |
| 41 class SafeMediaMetadataParser; | 38 class SafeMediaMetadataParser; |
| 42 } | 39 } |
| 43 | 40 |
| 44 namespace extensions { | 41 namespace extensions { |
| 45 | 42 |
| 46 class Extension; | 43 class Extension; |
| 47 | 44 |
| 48 // The profile-keyed service that manages the media galleries extension API. | 45 // The profile-keyed service that manages the media galleries extension API. |
| 49 // Created at the same time as the Profile. This is also the event router. | 46 // Created at the same time as the Profile. This is also the event router. |
| 50 class MediaGalleriesEventRouter : public BrowserContextKeyedAPI, | 47 class MediaGalleriesEventRouter : public BrowserContextKeyedAPI, |
| 51 public GalleryWatchManagerObserver, | 48 public GalleryWatchManagerObserver, |
| 52 public MediaScanManagerObserver, | |
| 53 public extensions::EventRouter::Observer { | 49 public extensions::EventRouter::Observer { |
| 54 public: | 50 public: |
| 55 // KeyedService implementation. | 51 // KeyedService implementation. |
| 56 void Shutdown() override; | 52 void Shutdown() override; |
| 57 | 53 |
| 58 // BrowserContextKeyedAPI implementation. | 54 // BrowserContextKeyedAPI implementation. |
| 59 static BrowserContextKeyedAPIFactory<MediaGalleriesEventRouter>* | 55 static BrowserContextKeyedAPIFactory<MediaGalleriesEventRouter>* |
| 60 GetFactoryInstance(); | 56 GetFactoryInstance(); |
| 61 | 57 |
| 62 // Convenience method to get the MediaGalleriesAPI for a profile. | 58 // Convenience method to get the MediaGalleriesAPI for a profile. |
| 63 static MediaGalleriesEventRouter* Get(content::BrowserContext* context); | 59 static MediaGalleriesEventRouter* Get(content::BrowserContext* context); |
| 64 | 60 |
| 65 bool ExtensionHasGalleryChangeListener(const std::string& extension_id) const; | 61 bool ExtensionHasGalleryChangeListener(const std::string& extension_id) const; |
| 66 bool ExtensionHasScanProgressListener(const std::string& extension_id) const; | |
| 67 | |
| 68 // MediaScanManagerObserver implementation. | |
| 69 void OnScanStarted(const std::string& extension_id) override; | |
| 70 void OnScanCancelled(const std::string& extension_id) override; | |
| 71 void OnScanFinished(const std::string& extension_id, | |
| 72 int gallery_count, | |
| 73 const MediaGalleryScanResult& file_counts) override; | |
| 74 void OnScanError(const std::string& extension_id) override; | |
| 75 | 62 |
| 76 private: | 63 private: |
| 77 friend class BrowserContextKeyedAPIFactory<MediaGalleriesEventRouter>; | 64 friend class BrowserContextKeyedAPIFactory<MediaGalleriesEventRouter>; |
| 78 | 65 |
| 79 void DispatchEventToExtension(const std::string& extension_id, | 66 void DispatchEventToExtension(const std::string& extension_id, |
| 80 events::HistogramValue histogram_value, | 67 events::HistogramValue histogram_value, |
| 81 const std::string& event_name, | 68 const std::string& event_name, |
| 82 scoped_ptr<base::ListValue> event_args); | 69 scoped_ptr<base::ListValue> event_args); |
| 83 | 70 |
| 84 explicit MediaGalleriesEventRouter(content::BrowserContext* context); | 71 explicit MediaGalleriesEventRouter(content::BrowserContext* context); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 194 |
| 208 protected: | 195 protected: |
| 209 ~MediaGalleriesDropPermissionForMediaFileSystemFunction() override; | 196 ~MediaGalleriesDropPermissionForMediaFileSystemFunction() override; |
| 210 bool RunAsync() override; | 197 bool RunAsync() override; |
| 211 | 198 |
| 212 private: | 199 private: |
| 213 // Bottom half for RunAsync, invoked after the preferences is initialized. | 200 // Bottom half for RunAsync, invoked after the preferences is initialized. |
| 214 void OnPreferencesInit(MediaGalleryPrefId pref_id); | 201 void OnPreferencesInit(MediaGalleryPrefId pref_id); |
| 215 }; | 202 }; |
| 216 | 203 |
| 217 class MediaGalleriesStartMediaScanFunction | |
| 218 : public ChromeAsyncExtensionFunction { | |
| 219 public: | |
| 220 DECLARE_EXTENSION_FUNCTION("mediaGalleries.startMediaScan", | |
| 221 MEDIAGALLERIES_STARTMEDIASCAN) | |
| 222 | |
| 223 protected: | |
| 224 ~MediaGalleriesStartMediaScanFunction() override; | |
| 225 bool RunAsync() override; | |
| 226 | |
| 227 private: | |
| 228 // Bottom half for RunAsync, invoked after the preferences is initialized. | |
| 229 void OnPreferencesInit(); | |
| 230 }; | |
| 231 | |
| 232 class MediaGalleriesCancelMediaScanFunction | |
| 233 : public ChromeAsyncExtensionFunction { | |
| 234 public: | |
| 235 DECLARE_EXTENSION_FUNCTION("mediaGalleries.cancelMediaScan", | |
| 236 MEDIAGALLERIES_CANCELMEDIASCAN) | |
| 237 | |
| 238 protected: | |
| 239 ~MediaGalleriesCancelMediaScanFunction() override; | |
| 240 bool RunAsync() override; | |
| 241 | |
| 242 private: | |
| 243 // Bottom half for RunAsync, invoked after the preferences is initialized. | |
| 244 void OnPreferencesInit(); | |
| 245 }; | |
| 246 | |
| 247 class MediaGalleriesAddScanResultsFunction | |
| 248 : public ChromeAsyncExtensionFunction { | |
| 249 public: | |
| 250 DECLARE_EXTENSION_FUNCTION("mediaGalleries.addScanResults", | |
| 251 MEDIAGALLERIES_ADDSCANRESULTS) | |
| 252 | |
| 253 protected: | |
| 254 ~MediaGalleriesAddScanResultsFunction() override; | |
| 255 bool RunAsync() override; | |
| 256 | |
| 257 // Pulled out for testing. | |
| 258 virtual MediaGalleriesScanResultController* MakeDialog( | |
| 259 content::WebContents* web_contents, | |
| 260 const extensions::Extension& extension, | |
| 261 const base::Closure& on_finish); | |
| 262 | |
| 263 private: | |
| 264 // Bottom half for RunAsync, invoked after the preferences is initialized. | |
| 265 void OnPreferencesInit(); | |
| 266 | |
| 267 // Grabs galleries from the media file system registry and passes them to | |
| 268 // ReturnGalleries(). | |
| 269 void GetAndReturnGalleries(); | |
| 270 | |
| 271 // Returns galleries to the caller. | |
| 272 void ReturnGalleries(const std::vector<MediaFileSystemInfo>& filesystems); | |
| 273 }; | |
| 274 | |
| 275 class MediaGalleriesGetMetadataFunction : public ChromeAsyncExtensionFunction { | 204 class MediaGalleriesGetMetadataFunction : public ChromeAsyncExtensionFunction { |
| 276 public: | 205 public: |
| 277 DECLARE_EXTENSION_FUNCTION("mediaGalleries.getMetadata", | 206 DECLARE_EXTENSION_FUNCTION("mediaGalleries.getMetadata", |
| 278 MEDIAGALLERIES_GETMETADATA) | 207 MEDIAGALLERIES_GETMETADATA) |
| 279 | 208 |
| 280 protected: | 209 protected: |
| 281 ~MediaGalleriesGetMetadataFunction() override; | 210 ~MediaGalleriesGetMetadataFunction() override; |
| 282 bool RunAsync() override; | 211 bool RunAsync() override; |
| 283 | 212 |
| 284 private: | 213 private: |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 ~MediaGalleriesRemoveAllGalleryWatchFunction() override; | 286 ~MediaGalleriesRemoveAllGalleryWatchFunction() override; |
| 358 bool RunAsync() override; | 287 bool RunAsync() override; |
| 359 | 288 |
| 360 private: | 289 private: |
| 361 void OnPreferencesInit(); | 290 void OnPreferencesInit(); |
| 362 }; | 291 }; |
| 363 | 292 |
| 364 } // namespace extensions | 293 } // namespace extensions |
| 365 | 294 |
| 366 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ | 295 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ |
| OLD | NEW |