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 // 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 #include "ui/base/l10n/l10n_util.h" | 55 #include "ui/base/l10n/l10n_util.h" |
| 56 | 56 |
| 57 using content::WebContents; | 57 using content::WebContents; |
| 58 using storage_monitor::MediaStorageUtil; | 58 using storage_monitor::MediaStorageUtil; |
| 59 using storage_monitor::StorageInfo; | 59 using storage_monitor::StorageInfo; |
| 60 using web_modal::WebContentsModalDialogManager; | 60 using web_modal::WebContentsModalDialogManager; |
| 61 | 61 |
| 62 namespace extensions { | 62 namespace extensions { |
| 63 | 63 |
| 64 namespace MediaGalleries = api::media_galleries; | 64 namespace MediaGalleries = api::media_galleries; |
| 65 namespace DropPermissionForMediaFileSystem = | |
| 66 MediaGalleries::DropPermissionForMediaFileSystem; | |
| 65 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; | 67 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; |
| 66 | 68 |
| 67 namespace { | 69 namespace { |
| 68 | 70 |
| 69 const char kDisallowedByPolicy[] = | 71 const char kDisallowedByPolicy[] = |
| 70 "Media Galleries API is disallowed by policy: "; | 72 "Media Galleries API is disallowed by policy: "; |
| 71 const char kMissingEventListener[] = | 73 const char kMissingEventListener[] = |
| 72 "Missing event listener registration."; | 74 "Missing event listener registration."; |
| 73 const char kNoScanPermission[] = | 75 const char kNoScanPermission[] = |
| 74 "No permission to scan."; | 76 "No permission to scan."; |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 if (!render_view_host()) { | 638 if (!render_view_host()) { |
| 637 cb.Run(std::vector<MediaFileSystemInfo>()); | 639 cb.Run(std::vector<MediaFileSystemInfo>()); |
| 638 return; | 640 return; |
| 639 } | 641 } |
| 640 MediaFileSystemRegistry* registry = media_file_system_registry(); | 642 MediaFileSystemRegistry* registry = media_file_system_registry(); |
| 641 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); | 643 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); |
| 642 registry->GetMediaFileSystemsForExtension( | 644 registry->GetMediaFileSystemsForExtension( |
| 643 render_view_host(), GetExtension(), cb); | 645 render_view_host(), GetExtension(), cb); |
| 644 } | 646 } |
| 645 | 647 |
| 648 MediaGalleriesDropPermissionForMediaFileSystemFunction:: | |
| 649 ~MediaGalleriesDropPermissionForMediaFileSystemFunction() {} | |
| 650 | |
| 651 bool MediaGalleriesDropPermissionForMediaFileSystemFunction::RunImpl() { | |
| 652 media_galleries::UsageCount( | |
| 653 media_galleries::DROP_PERMISSION_FOR_MEDIA_FILE_SYSTEM); | |
| 654 | |
| 655 scoped_ptr<base::ListValue> default_results(new base::ListValue()); | |
| 656 default_results->AppendString(base::string16()); | |
| 657 default_results->AppendBoolean(false); | |
| 658 SetResult(default_results.release()); | |
| 659 | |
| 660 scoped_ptr<DropPermissionForMediaFileSystem::Params> params( | |
| 661 DropPermissionForMediaFileSystem::Params::Create(*args_)); | |
| 662 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 663 MediaGalleryPrefId pref_id; | |
| 664 if (!base::StringToUint64(params->gallery_id, &pref_id)) | |
| 665 return false; | |
| 666 | |
| 667 // The name of this function is too darn long! | |
| 668 #define DROP_PERMISSION_FUNCTION \ | |
| 669 &MediaGalleriesDropPermissionForMediaFileSystemFunction::OnPreferencesInit | |
|
vandebo (ex-Chrome)
2014/04/08 14:58:45
Would wrapping at the :: be better than a macro?
Lei Zhang
2014/04/08 17:10:18
Done.
| |
| 670 base::Closure callback = base::Bind(DROP_PERMISSION_FUNCTION, this, pref_id); | |
| 671 #undef DROP_PERMISSION_FUNCTION | |
| 672 return Setup(GetProfile(), &error_, callback); | |
|
vandebo (ex-Chrome)
2014/04/08 14:58:45
Consider putting this in the conditional on line 6
Lei Zhang
2014/04/08 17:10:18
Code shuffled.
| |
| 673 } | |
| 674 | |
| 675 void MediaGalleriesDropPermissionForMediaFileSystemFunction::OnPreferencesInit( | |
| 676 MediaGalleryPrefId pref_id) { | |
| 677 MediaGalleriesPreferences* preferences = | |
| 678 media_file_system_registry()->GetPreferences(GetProfile()); | |
| 679 bool dropped = preferences->SetGalleryPermissionForExtension( | |
| 680 *GetExtension(), pref_id, false); | |
| 681 scoped_ptr<base::ListValue> results(new base::ListValue()); | |
| 682 results->AppendString(base::Uint64ToString(pref_id)); | |
| 683 results->AppendBoolean(dropped); | |
| 684 SetResult(results.release()); | |
| 685 SendResponse(true); | |
| 686 } | |
| 687 | |
| 646 MediaGalleriesStartMediaScanFunction::~MediaGalleriesStartMediaScanFunction() {} | 688 MediaGalleriesStartMediaScanFunction::~MediaGalleriesStartMediaScanFunction() {} |
| 647 | 689 |
| 648 bool MediaGalleriesStartMediaScanFunction::RunImpl() { | 690 bool MediaGalleriesStartMediaScanFunction::RunImpl() { |
| 649 media_galleries::UsageCount(media_galleries::START_MEDIA_SCAN); | 691 media_galleries::UsageCount(media_galleries::START_MEDIA_SCAN); |
| 650 if (!CheckScanPermission(GetExtension(), &error_)) { | 692 if (!CheckScanPermission(GetExtension(), &error_)) { |
| 651 MediaGalleriesEventRouter::Get(GetProfile())->OnScanError( | 693 MediaGalleriesEventRouter::Get(GetProfile())->OnScanError( |
| 652 GetExtension()->id()); | 694 GetExtension()->id()); |
| 653 return false; | 695 return false; |
| 654 } | 696 } |
| 655 return Setup(GetProfile(), &error_, base::Bind( | 697 return Setup(GetProfile(), &error_, base::Bind( |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 if (!parse_success) { | 877 if (!parse_success) { |
| 836 SendResponse(false); | 878 SendResponse(false); |
| 837 return; | 879 return; |
| 838 } | 880 } |
| 839 | 881 |
| 840 SetResult(metadata_dictionary->DeepCopy()); | 882 SetResult(metadata_dictionary->DeepCopy()); |
| 841 SendResponse(true); | 883 SendResponse(true); |
| 842 } | 884 } |
| 843 | 885 |
| 844 } // namespace extensions | 886 } // namespace extensions |
| OLD | NEW |