Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc

Issue 224963010: Media Galleries: Add a dropPermissionForMediaFileSystem() API. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 ForgetMediaFileSystem = MediaGalleries::ForgetMediaFileSystem;
65 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; 66 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems;
66 67
67 namespace { 68 namespace {
68 69
69 const char kDisallowedByPolicy[] = 70 const char kDisallowedByPolicy[] =
70 "Media Galleries API is disallowed by policy: "; 71 "Media Galleries API is disallowed by policy: ";
71 const char kMissingEventListener[] = 72 const char kMissingEventListener[] =
72 "Missing event listener registration."; 73 "Missing event listener registration.";
73 const char kNoScanPermission[] = 74 const char kNoScanPermission[] =
74 "No permission to scan."; 75 "No permission to scan.";
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 if (!render_view_host()) { 637 if (!render_view_host()) {
637 cb.Run(std::vector<MediaFileSystemInfo>()); 638 cb.Run(std::vector<MediaFileSystemInfo>());
638 return; 639 return;
639 } 640 }
640 MediaFileSystemRegistry* registry = media_file_system_registry(); 641 MediaFileSystemRegistry* registry = media_file_system_registry();
641 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); 642 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized());
642 registry->GetMediaFileSystemsForExtension( 643 registry->GetMediaFileSystemsForExtension(
643 render_view_host(), GetExtension(), cb); 644 render_view_host(), GetExtension(), cb);
644 } 645 }
645 646
647 MediaGalleriesForgetMediaFileSystemFunction::
648 ~MediaGalleriesForgetMediaFileSystemFunction() {}
649
650 bool MediaGalleriesForgetMediaFileSystemFunction::RunImpl() {
651 media_galleries::UsageCount(media_galleries::FORGET_MEDIA_FILE_SYSTEM);
652
653 // Default callback return value is false.
654 SetResult(new base::FundamentalValue(false));
655
656 scoped_ptr<ForgetMediaFileSystem::Params> params(
657 ForgetMediaFileSystem::Params::Create(*args_));
658 EXTENSION_FUNCTION_VALIDATE(params.get());
659 const base::DictionaryValue& file_system =
660 params->media_file_system.additional_properties;
661 if (!file_system.HasKey(kGalleryIdKey))
662 return false;
663 base::string16 pref_id_str;
664 if (!file_system.GetString(kGalleryIdKey, &pref_id_str))
665 return false;
666 MediaGalleryPrefId pref_id;
667 if (!base::StringToUint64(pref_id_str, &pref_id))
668 return false;
669
670 return Setup(GetProfile(), &error_, base::Bind(
671 &MediaGalleriesForgetMediaFileSystemFunction::OnPreferencesInit,
672 this, pref_id));
673 }
674
675 void MediaGalleriesForgetMediaFileSystemFunction::OnPreferencesInit(
676 MediaGalleryPrefId pref_id) {
677 MediaGalleriesPreferences* preferences =
678 media_file_system_registry()->GetPreferences(GetProfile());
679 bool forgotten = preferences->SetGalleryPermissionForExtension(
680 *GetExtension(), pref_id, false);
681 SetResult(new base::FundamentalValue(forgotten));
682 SendResponse(true);
683 }
684
646 MediaGalleriesStartMediaScanFunction::~MediaGalleriesStartMediaScanFunction() {} 685 MediaGalleriesStartMediaScanFunction::~MediaGalleriesStartMediaScanFunction() {}
647 686
648 bool MediaGalleriesStartMediaScanFunction::RunImpl() { 687 bool MediaGalleriesStartMediaScanFunction::RunImpl() {
649 media_galleries::UsageCount(media_galleries::START_MEDIA_SCAN); 688 media_galleries::UsageCount(media_galleries::START_MEDIA_SCAN);
650 if (!CheckScanPermission(GetExtension(), &error_)) { 689 if (!CheckScanPermission(GetExtension(), &error_)) {
651 MediaGalleriesEventRouter::Get(GetProfile())->OnScanError( 690 MediaGalleriesEventRouter::Get(GetProfile())->OnScanError(
652 GetExtension()->id()); 691 GetExtension()->id());
653 return false; 692 return false;
654 } 693 }
655 return Setup(GetProfile(), &error_, base::Bind( 694 return Setup(GetProfile(), &error_, base::Bind(
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 if (!parse_success) { 874 if (!parse_success) {
836 SendResponse(false); 875 SendResponse(false);
837 return; 876 return;
838 } 877 }
839 878
840 SetResult(metadata_dictionary->DeepCopy()); 879 SetResult(metadata_dictionary->DeepCopy());
841 SendResponse(true); 880 SendResponse(true);
842 } 881 }
843 882
844 } // namespace extensions 883 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698