Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / permissions / media_galleries_permission_data.cc
blobbc41b338fb6ea49b383a7076d4c1043c33be32be
1 // Copyright (c) 2013 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 "chrome/common/extensions/permissions/media_galleries_permission_data.h"
7 #include "base/strings/string_util.h"
8 #include "base/values.h"
9 #include "chrome/common/extensions/permissions/media_galleries_permission.h"
11 namespace extensions {
13 MediaGalleriesPermissionData::MediaGalleriesPermissionData() {
16 bool MediaGalleriesPermissionData::Check(
17 const APIPermission::CheckParam* param) const {
18 if (!param)
19 return false;
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) {
31 if (!value)
32 return false;
34 std::string raw_permission;
35 if (!value->GetAsString(&raw_permission))
36 return false;
38 std::string permission;
39 TrimWhitespaceASCII(raw_permission, TRIM_ALL, &permission);
41 if (permission == MediaGalleriesPermission::kAllAutoDetectedPermission ||
42 permission == MediaGalleriesPermission::kReadPermission ||
43 permission == MediaGalleriesPermission::kCopyToPermission ||
44 permission == MediaGalleriesPermission::kDeletePermission) {
45 permission_ = permission;
46 return true;
48 return false;
51 bool MediaGalleriesPermissionData::operator<(
52 const MediaGalleriesPermissionData& rhs) const {
53 return permission_ < rhs.permission_;
56 bool MediaGalleriesPermissionData::operator==(
57 const MediaGalleriesPermissionData& rhs) const {
58 return permission_ == rhs.permission_;
61 } // namespace extensions