| 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 bool MediaGalleriesEventRouter::ExtensionHasScanProgressListener( | 340 bool MediaGalleriesEventRouter::ExtensionHasScanProgressListener( |
| 341 const std::string& extension_id) const { | 341 const std::string& extension_id) const { |
| 342 return EventRouter::Get(profile_)->ExtensionHasEventListener( | 342 return EventRouter::Get(profile_)->ExtensionHasEventListener( |
| 343 extension_id, MediaGalleries::OnScanProgress::kEventName); | 343 extension_id, MediaGalleries::OnScanProgress::kEventName); |
| 344 } | 344 } |
| 345 | 345 |
| 346 void MediaGalleriesEventRouter::OnScanStarted(const std::string& extension_id) { | 346 void MediaGalleriesEventRouter::OnScanStarted(const std::string& extension_id) { |
| 347 MediaGalleries::ScanProgressDetails details; | 347 MediaGalleries::ScanProgressDetails details; |
| 348 details.type = MediaGalleries::SCAN_PROGRESS_TYPE_START; | 348 details.type = MediaGalleries::SCAN_PROGRESS_TYPE_START; |
| 349 DispatchEventToExtension( | 349 DispatchEventToExtension( |
| 350 extension_id, | 350 extension_id, events::MEDIA_GALLERIES_ON_SCAN_PROGRESS, |
| 351 MediaGalleries::OnScanProgress::kEventName, | 351 MediaGalleries::OnScanProgress::kEventName, |
| 352 MediaGalleries::OnScanProgress::Create(details).Pass()); | 352 MediaGalleries::OnScanProgress::Create(details).Pass()); |
| 353 } | 353 } |
| 354 | 354 |
| 355 void MediaGalleriesEventRouter::OnScanCancelled( | 355 void MediaGalleriesEventRouter::OnScanCancelled( |
| 356 const std::string& extension_id) { | 356 const std::string& extension_id) { |
| 357 MediaGalleries::ScanProgressDetails details; | 357 MediaGalleries::ScanProgressDetails details; |
| 358 details.type = MediaGalleries::SCAN_PROGRESS_TYPE_CANCEL; | 358 details.type = MediaGalleries::SCAN_PROGRESS_TYPE_CANCEL; |
| 359 DispatchEventToExtension( | 359 DispatchEventToExtension( |
| 360 extension_id, | 360 extension_id, events::MEDIA_GALLERIES_ON_SCAN_PROGRESS, |
| 361 MediaGalleries::OnScanProgress::kEventName, | 361 MediaGalleries::OnScanProgress::kEventName, |
| 362 MediaGalleries::OnScanProgress::Create(details).Pass()); | 362 MediaGalleries::OnScanProgress::Create(details).Pass()); |
| 363 } | 363 } |
| 364 | 364 |
| 365 void MediaGalleriesEventRouter::OnScanFinished( | 365 void MediaGalleriesEventRouter::OnScanFinished( |
| 366 const std::string& extension_id, int gallery_count, | 366 const std::string& extension_id, int gallery_count, |
| 367 const MediaGalleryScanResult& file_counts) { | 367 const MediaGalleryScanResult& file_counts) { |
| 368 media_galleries::UsageCount(media_galleries::SCAN_FINISHED); | 368 media_galleries::UsageCount(media_galleries::SCAN_FINISHED); |
| 369 MediaGalleries::ScanProgressDetails details; | 369 MediaGalleries::ScanProgressDetails details; |
| 370 details.type = MediaGalleries::SCAN_PROGRESS_TYPE_FINISH; | 370 details.type = MediaGalleries::SCAN_PROGRESS_TYPE_FINISH; |
| 371 details.gallery_count.reset(new int(gallery_count)); | 371 details.gallery_count.reset(new int(gallery_count)); |
| 372 details.audio_count.reset(new int(file_counts.audio_count)); | 372 details.audio_count.reset(new int(file_counts.audio_count)); |
| 373 details.image_count.reset(new int(file_counts.image_count)); | 373 details.image_count.reset(new int(file_counts.image_count)); |
| 374 details.video_count.reset(new int(file_counts.video_count)); | 374 details.video_count.reset(new int(file_counts.video_count)); |
| 375 DispatchEventToExtension( | 375 DispatchEventToExtension( |
| 376 extension_id, | 376 extension_id, events::MEDIA_GALLERIES_ON_SCAN_PROGRESS, |
| 377 MediaGalleries::OnScanProgress::kEventName, | 377 MediaGalleries::OnScanProgress::kEventName, |
| 378 MediaGalleries::OnScanProgress::Create(details).Pass()); | 378 MediaGalleries::OnScanProgress::Create(details).Pass()); |
| 379 } | 379 } |
| 380 | 380 |
| 381 void MediaGalleriesEventRouter::OnScanError( | 381 void MediaGalleriesEventRouter::OnScanError( |
| 382 const std::string& extension_id) { | 382 const std::string& extension_id) { |
| 383 MediaGalleries::ScanProgressDetails details; | 383 MediaGalleries::ScanProgressDetails details; |
| 384 details.type = MediaGalleries::SCAN_PROGRESS_TYPE_ERROR; | 384 details.type = MediaGalleries::SCAN_PROGRESS_TYPE_ERROR; |
| 385 DispatchEventToExtension( | 385 DispatchEventToExtension( |
| 386 extension_id, | 386 extension_id, events::MEDIA_GALLERIES_ON_SCAN_PROGRESS, |
| 387 MediaGalleries::OnScanProgress::kEventName, | 387 MediaGalleries::OnScanProgress::kEventName, |
| 388 MediaGalleries::OnScanProgress::Create(details).Pass()); | 388 MediaGalleries::OnScanProgress::Create(details).Pass()); |
| 389 } | 389 } |
| 390 | 390 |
| 391 void MediaGalleriesEventRouter::DispatchEventToExtension( | 391 void MediaGalleriesEventRouter::DispatchEventToExtension( |
| 392 const std::string& extension_id, | 392 const std::string& extension_id, |
| 393 events::HistogramValue histogram_value, |
| 393 const std::string& event_name, | 394 const std::string& event_name, |
| 394 scoped_ptr<base::ListValue> event_args) { | 395 scoped_ptr<base::ListValue> event_args) { |
| 395 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 396 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 396 | 397 |
| 397 // TODO(tommycli): Remove these CHECKs after fixing https://crbug.com/467627. | 398 // TODO(tommycli): Remove these CHECKs after fixing https://crbug.com/467627. |
| 398 CHECK(profile_); | 399 CHECK(profile_); |
| 399 EventRouter* router = EventRouter::Get(profile_); | 400 EventRouter* router = EventRouter::Get(profile_); |
| 400 CHECK(router); | 401 CHECK(router); |
| 401 | 402 |
| 402 if (!router->ExtensionHasEventListener(extension_id, event_name)) | 403 if (!router->ExtensionHasEventListener(extension_id, event_name)) |
| 403 return; | 404 return; |
| 404 | 405 |
| 405 scoped_ptr<extensions::Event> event(new extensions::Event( | 406 scoped_ptr<extensions::Event> event( |
| 406 extensions::events::UNKNOWN, event_name, event_args.Pass())); | 407 new extensions::Event(histogram_value, event_name, event_args.Pass())); |
| 407 router->DispatchEventToExtension(extension_id, event.Pass()); | 408 router->DispatchEventToExtension(extension_id, event.Pass()); |
| 408 } | 409 } |
| 409 | 410 |
| 410 void MediaGalleriesEventRouter::OnGalleryChanged( | 411 void MediaGalleriesEventRouter::OnGalleryChanged( |
| 411 const std::string& extension_id, MediaGalleryPrefId gallery_id) { | 412 const std::string& extension_id, MediaGalleryPrefId gallery_id) { |
| 412 MediaGalleries::GalleryChangeDetails details; | 413 MediaGalleries::GalleryChangeDetails details; |
| 413 details.type = MediaGalleries::GALLERY_CHANGE_TYPE_CONTENTS_CHANGED; | 414 details.type = MediaGalleries::GALLERY_CHANGE_TYPE_CONTENTS_CHANGED; |
| 414 details.gallery_id = base::Uint64ToString(gallery_id); | 415 details.gallery_id = base::Uint64ToString(gallery_id); |
| 415 DispatchEventToExtension( | 416 DispatchEventToExtension( |
| 416 extension_id, | 417 extension_id, events::MEDIA_GALLERIES_ON_GALLERY_CHANGED, |
| 417 MediaGalleries::OnGalleryChanged::kEventName, | 418 MediaGalleries::OnGalleryChanged::kEventName, |
| 418 MediaGalleries::OnGalleryChanged::Create(details).Pass()); | 419 MediaGalleries::OnGalleryChanged::Create(details).Pass()); |
| 419 } | 420 } |
| 420 | 421 |
| 421 void MediaGalleriesEventRouter::OnGalleryWatchDropped( | 422 void MediaGalleriesEventRouter::OnGalleryWatchDropped( |
| 422 const std::string& extension_id, MediaGalleryPrefId gallery_id) { | 423 const std::string& extension_id, MediaGalleryPrefId gallery_id) { |
| 423 MediaGalleries::GalleryChangeDetails details; | 424 MediaGalleries::GalleryChangeDetails details; |
| 424 details.type = MediaGalleries::GALLERY_CHANGE_TYPE_WATCH_DROPPED; | 425 details.type = MediaGalleries::GALLERY_CHANGE_TYPE_WATCH_DROPPED; |
| 425 details.gallery_id = gallery_id; | 426 details.gallery_id = gallery_id; |
| 426 DispatchEventToExtension( | 427 DispatchEventToExtension( |
| 427 extension_id, | 428 extension_id, events::MEDIA_GALLERIES_ON_GALLERY_CHANGED, |
| 428 MediaGalleries::OnGalleryChanged::kEventName, | 429 MediaGalleries::OnGalleryChanged::kEventName, |
| 429 MediaGalleries::OnGalleryChanged::Create(details).Pass()); | 430 MediaGalleries::OnGalleryChanged::Create(details).Pass()); |
| 430 } | 431 } |
| 431 | 432 |
| 432 void MediaGalleriesEventRouter::OnListenerRemoved( | 433 void MediaGalleriesEventRouter::OnListenerRemoved( |
| 433 const EventListenerInfo& details) { | 434 const EventListenerInfo& details) { |
| 434 if (details.event_name == MediaGalleries::OnGalleryChanged::kEventName && | 435 if (details.event_name == MediaGalleries::OnGalleryChanged::kEventName && |
| 435 !ExtensionHasGalleryChangeListener(details.extension_id)) { | 436 !ExtensionHasGalleryChangeListener(details.extension_id)) { |
| 436 gallery_watch_manager()->RemoveAllWatches(profile_, details.extension_id); | 437 gallery_watch_manager()->RemoveAllWatches(profile_, details.extension_id); |
| 437 } | 438 } |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 &MediaGalleriesRemoveAllGalleryWatchFunction::OnPreferencesInit, this)); | 1247 &MediaGalleriesRemoveAllGalleryWatchFunction::OnPreferencesInit, this)); |
| 1247 return true; | 1248 return true; |
| 1248 } | 1249 } |
| 1249 | 1250 |
| 1250 void MediaGalleriesRemoveAllGalleryWatchFunction::OnPreferencesInit() { | 1251 void MediaGalleriesRemoveAllGalleryWatchFunction::OnPreferencesInit() { |
| 1251 gallery_watch_manager()->RemoveAllWatches(GetProfile(), extension_id()); | 1252 gallery_watch_manager()->RemoveAllWatches(GetProfile(), extension_id()); |
| 1252 SendResponse(true); | 1253 SendResponse(true); |
| 1253 } | 1254 } |
| 1254 | 1255 |
| 1255 } // namespace extensions | 1256 } // namespace extensions |
| OLD | NEW |