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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 | 57 |
58 namespace MediaGalleries = api::media_galleries; | 58 namespace MediaGalleries = api::media_galleries; |
59 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; | 59 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; |
60 | 60 |
61 namespace { | 61 namespace { |
62 | 62 |
63 const char kDisallowedByPolicy[] = | 63 const char kDisallowedByPolicy[] = |
64 "Media Galleries API is disallowed by policy: "; | 64 "Media Galleries API is disallowed by policy: "; |
65 const char kMissingEventListener[] = | 65 const char kMissingEventListener[] = |
66 "Missing event listener registration."; | 66 "Missing event listener registration."; |
67 const char kNoScanPermission[] = | |
68 "No permission to scan."; | |
67 | 69 |
68 const char kDeviceIdKey[] = "deviceId"; | 70 const char kDeviceIdKey[] = "deviceId"; |
69 const char kGalleryIdKey[] = "galleryId"; | 71 const char kGalleryIdKey[] = "galleryId"; |
70 const char kIsAvailableKey[] = "isAvailable"; | 72 const char kIsAvailableKey[] = "isAvailable"; |
71 const char kIsMediaDeviceKey[] = "isMediaDevice"; | 73 const char kIsMediaDeviceKey[] = "isMediaDevice"; |
72 const char kIsRemovableKey[] = "isRemovable"; | 74 const char kIsRemovableKey[] = "isRemovable"; |
73 const char kNameKey[] = "name"; | 75 const char kNameKey[] = "name"; |
74 | 76 |
75 MediaFileSystemRegistry* media_file_system_registry() { | 77 MediaFileSystemRegistry* media_file_system_registry() { |
76 return g_browser_process->media_file_system_registry(); | 78 return g_browser_process->media_file_system_registry(); |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
611 | 613 |
612 void MediaGalleriesStartMediaScanFunction::OnPreferencesInit() { | 614 void MediaGalleriesStartMediaScanFunction::OnPreferencesInit() { |
613 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 615 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
614 MediaGalleriesEventRouter* api = MediaGalleriesEventRouter::Get(GetProfile()); | 616 MediaGalleriesEventRouter* api = MediaGalleriesEventRouter::Get(GetProfile()); |
615 if (!api->ExtensionHasScanProgressListener(GetExtension()->id())) { | 617 if (!api->ExtensionHasScanProgressListener(GetExtension()->id())) { |
616 error_ = kMissingEventListener; | 618 error_ = kMissingEventListener; |
617 SendResponse(false); | 619 SendResponse(false); |
618 return; | 620 return; |
619 } | 621 } |
620 | 622 |
623 MediaGalleriesPermission::CheckParam scan_param( | |
Lei Zhang
2014/01/29 21:18:11
Why do this here and not earlier in RunImpl() ?
tommycli
2014/01/29 22:30:18
Done.
| |
624 MediaGalleriesPermission::kScanPermission); | |
625 bool has_scan_permission = PermissionsData::CheckAPIPermissionWithParam( | |
626 GetExtension(), APIPermission::kMediaGalleries, &scan_param); | |
627 if (!has_scan_permission) { | |
628 error_ = kNoScanPermission; | |
629 SendResponse(false); | |
630 return; | |
631 } | |
632 | |
621 media_scan_manager()->StartScan(GetProfile(), GetExtension()->id()); | 633 media_scan_manager()->StartScan(GetProfile(), GetExtension()->id()); |
622 SendResponse(true); | 634 SendResponse(true); |
623 } | 635 } |
624 | 636 |
625 MediaGalleriesCancelMediaScanFunction:: | 637 MediaGalleriesCancelMediaScanFunction:: |
626 ~MediaGalleriesCancelMediaScanFunction() { | 638 ~MediaGalleriesCancelMediaScanFunction() { |
627 } | 639 } |
628 | 640 |
629 bool MediaGalleriesCancelMediaScanFunction::RunImpl() { | 641 bool MediaGalleriesCancelMediaScanFunction::RunImpl() { |
630 media_galleries::UsageCount(media_galleries::CANCEL_MEDIA_SCAN); | 642 media_galleries::UsageCount(media_galleries::CANCEL_MEDIA_SCAN); |
631 return Setup(GetProfile(), &error_, base::Bind( | 643 return Setup(GetProfile(), &error_, base::Bind( |
632 &MediaGalleriesCancelMediaScanFunction::OnPreferencesInit, this)); | 644 &MediaGalleriesCancelMediaScanFunction::OnPreferencesInit, this)); |
633 } | 645 } |
634 | 646 |
635 void MediaGalleriesCancelMediaScanFunction::OnPreferencesInit() { | 647 void MediaGalleriesCancelMediaScanFunction::OnPreferencesInit() { |
636 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 648 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
649 | |
650 MediaGalleriesPermission::CheckParam scan_param( | |
651 MediaGalleriesPermission::kScanPermission); | |
652 bool has_scan_permission = PermissionsData::CheckAPIPermissionWithParam( | |
653 GetExtension(), APIPermission::kMediaGalleries, &scan_param); | |
654 if (!has_scan_permission) { | |
655 error_ = kNoScanPermission; | |
656 SendResponse(false); | |
657 return; | |
658 } | |
659 | |
637 media_scan_manager()->CancelScan(GetProfile(), GetExtension()->id()); | 660 media_scan_manager()->CancelScan(GetProfile(), GetExtension()->id()); |
638 SendResponse(true); | 661 SendResponse(true); |
639 } | 662 } |
640 | 663 |
641 MediaGalleriesAddScanResultsFunction::~MediaGalleriesAddScanResultsFunction() {} | 664 MediaGalleriesAddScanResultsFunction::~MediaGalleriesAddScanResultsFunction() {} |
642 | 665 |
643 bool MediaGalleriesAddScanResultsFunction::RunImpl() { | 666 bool MediaGalleriesAddScanResultsFunction::RunImpl() { |
644 media_galleries::UsageCount(media_galleries::ADD_SCAN_RESULTS); | 667 media_galleries::UsageCount(media_galleries::ADD_SCAN_RESULTS); |
645 return Setup(GetProfile(), &error_, base::Bind( | 668 return Setup(GetProfile(), &error_, base::Bind( |
646 &MediaGalleriesAddScanResultsFunction::OnPreferencesInit, this)); | 669 &MediaGalleriesAddScanResultsFunction::OnPreferencesInit, this)); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
738 if (mime_type_sniffed) | 761 if (mime_type_sniffed) |
739 metadata.mime_type = mime_type; | 762 metadata.mime_type = mime_type; |
740 | 763 |
741 // TODO(tommycli): Kick off SafeMediaMetadataParser if |mime_type_only| false. | 764 // TODO(tommycli): Kick off SafeMediaMetadataParser if |mime_type_only| false. |
742 | 765 |
743 SetResult(metadata.ToValue().release()); | 766 SetResult(metadata.ToValue().release()); |
744 SendResponse(true); | 767 SendResponse(true); |
745 } | 768 } |
746 | 769 |
747 } // namespace extensions | 770 } // namespace extensions |
OLD | NEW |