Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / extensions / common / permissions / media_galleries_permission_data.cc
blobd7e793797c402a522fddee98b6bd2e477ad3e18f
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 {
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 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;
47 return true;
49 return false;
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