1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/common/permissions/media_galleries_permission_data.h"
7 #include "base/strings/string_util.h"
8 #include "base/values.h"
9 #include "extensions/common/permissions/media_galleries_permission.h"
11 namespace extensions
{
13 MediaGalleriesPermissionData::MediaGalleriesPermissionData() {
16 bool MediaGalleriesPermissionData::Check(
17 const APIPermission::CheckParam
* param
) const {
21 const MediaGalleriesPermission::CheckParam
& specific_param
=
22 *static_cast<const MediaGalleriesPermission::CheckParam
*>(param
);
23 return permission_
== specific_param
.permission
;
26 scoped_ptr
<base::Value
> MediaGalleriesPermissionData::ToValue() const {
27 return scoped_ptr
<base::Value
>(new base::StringValue(permission_
));
30 bool MediaGalleriesPermissionData::FromValue(const base::Value
* value
) {
34 std::string raw_permission
;
35 if (!value
->GetAsString(&raw_permission
))
38 std::string permission
;
39 base::TrimWhitespaceASCII(raw_permission
, base::TRIM_ALL
, &permission
);
41 if (permission
== MediaGalleriesPermission::kAllAutoDetectedPermission
||
42 permission
== MediaGalleriesPermission::kScanPermission
||
43 permission
== MediaGalleriesPermission::kReadPermission
||
44 permission
== MediaGalleriesPermission::kCopyToPermission
||
45 permission
== MediaGalleriesPermission::kDeletePermission
) {
46 permission_
= permission
;
52 bool MediaGalleriesPermissionData::operator<(
53 const MediaGalleriesPermissionData
& rhs
) const {
54 return permission_
< rhs
.permission_
;
57 bool MediaGalleriesPermissionData::operator==(
58 const MediaGalleriesPermissionData
& rhs
) const {
59 return permission_
== rhs
.permission_
;
62 } // namespace extensions