| 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 // Implements the Chrome Extensions Media Galleries API. | 5 // Implements the Chrome Extensions Media Galleries API. |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" | 7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 MediaGalleriesEventRouter* MediaGalleriesEventRouter::Get( | 295 MediaGalleriesEventRouter* MediaGalleriesEventRouter::Get( |
| 296 content::BrowserContext* context) { | 296 content::BrowserContext* context) { |
| 297 DCHECK(media_file_system_registry() | 297 DCHECK(media_file_system_registry() |
| 298 ->GetPreferences(Profile::FromBrowserContext(context)) | 298 ->GetPreferences(Profile::FromBrowserContext(context)) |
| 299 ->IsInitialized()); | 299 ->IsInitialized()); |
| 300 return BrowserContextKeyedAPIFactory<MediaGalleriesEventRouter>::Get(context); | 300 return BrowserContextKeyedAPIFactory<MediaGalleriesEventRouter>::Get(context); |
| 301 } | 301 } |
| 302 | 302 |
| 303 bool MediaGalleriesEventRouter::ExtensionHasScanProgressListener( | 303 bool MediaGalleriesEventRouter::ExtensionHasScanProgressListener( |
| 304 const std::string& extension_id) const { | 304 const std::string& extension_id) const { |
| 305 EventRouter* router = ExtensionSystem::Get(profile_)->event_router(); | 305 return EventRouter::Get(profile_)->ExtensionHasEventListener( |
| 306 return router->ExtensionHasEventListener( | 306 extension_id, MediaGalleries::OnScanProgress::kEventName); |
| 307 extension_id, | |
| 308 MediaGalleries::OnScanProgress::kEventName); | |
| 309 } | 307 } |
| 310 | 308 |
| 311 void MediaGalleriesEventRouter::OnScanStarted(const std::string& extension_id) { | 309 void MediaGalleriesEventRouter::OnScanStarted(const std::string& extension_id) { |
| 312 MediaGalleries::ScanProgressDetails details; | 310 MediaGalleries::ScanProgressDetails details; |
| 313 details.type = MediaGalleries::SCAN_PROGRESS_TYPE_START; | 311 details.type = MediaGalleries::SCAN_PROGRESS_TYPE_START; |
| 314 DispatchEventToExtension( | 312 DispatchEventToExtension( |
| 315 extension_id, | 313 extension_id, |
| 316 MediaGalleries::OnScanProgress::kEventName, | 314 MediaGalleries::OnScanProgress::kEventName, |
| 317 MediaGalleries::OnScanProgress::Create(details).Pass()); | 315 MediaGalleries::OnScanProgress::Create(details).Pass()); |
| 318 } | 316 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 extension_id, | 349 extension_id, |
| 352 MediaGalleries::OnScanProgress::kEventName, | 350 MediaGalleries::OnScanProgress::kEventName, |
| 353 MediaGalleries::OnScanProgress::Create(details).Pass()); | 351 MediaGalleries::OnScanProgress::Create(details).Pass()); |
| 354 } | 352 } |
| 355 | 353 |
| 356 void MediaGalleriesEventRouter::DispatchEventToExtension( | 354 void MediaGalleriesEventRouter::DispatchEventToExtension( |
| 357 const std::string& extension_id, | 355 const std::string& extension_id, |
| 358 const std::string& event_name, | 356 const std::string& event_name, |
| 359 scoped_ptr<base::ListValue> event_args) { | 357 scoped_ptr<base::ListValue> event_args) { |
| 360 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 358 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 361 EventRouter* router = | 359 EventRouter* router = EventRouter::Get(profile_); |
| 362 extensions::ExtensionSystem::Get(profile_)->event_router(); | |
| 363 if (!router->ExtensionHasEventListener(extension_id, event_name)) | 360 if (!router->ExtensionHasEventListener(extension_id, event_name)) |
| 364 return; | 361 return; |
| 365 | 362 |
| 366 scoped_ptr<extensions::Event> event( | 363 scoped_ptr<extensions::Event> event( |
| 367 new extensions::Event(event_name, event_args.Pass())); | 364 new extensions::Event(event_name, event_args.Pass())); |
| 368 router->DispatchEventToExtension(extension_id, event.Pass()); | 365 router->DispatchEventToExtension(extension_id, event.Pass()); |
| 369 } | 366 } |
| 370 | 367 |
| 371 MediaGalleriesGetMediaFileSystemsFunction:: | 368 MediaGalleriesGetMediaFileSystemsFunction:: |
| 372 ~MediaGalleriesGetMediaFileSystemsFunction() {} | 369 ~MediaGalleriesGetMediaFileSystemsFunction() {} |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 if (!parse_success) { | 879 if (!parse_success) { |
| 883 SendResponse(false); | 880 SendResponse(false); |
| 884 return; | 881 return; |
| 885 } | 882 } |
| 886 | 883 |
| 887 SetResult(metadata_dictionary->DeepCopy()); | 884 SetResult(metadata_dictionary->DeepCopy()); |
| 888 SendResponse(true); | 885 SendResponse(true); |
| 889 } | 886 } |
| 890 | 887 |
| 891 } // namespace extensions | 888 } // namespace extensions |
| OLD | NEW |