OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/common/extensions/permissions/media_galleries_permission_data.h
" | |
6 | |
7 #include "base/strings/string_util.h" | |
8 #include "base/values.h" | |
9 #include "chrome/common/extensions/permissions/media_galleries_permission.h" | |
10 | |
11 namespace extensions { | |
12 | |
13 MediaGalleriesPermissionData::MediaGalleriesPermissionData() { | |
14 } | |
15 | |
16 bool MediaGalleriesPermissionData::Check( | |
17 const APIPermission::CheckParam* param) const { | |
18 if (!param) | |
19 return false; | |
20 | |
21 const MediaGalleriesPermission::CheckParam& specific_param = | |
22 *static_cast<const MediaGalleriesPermission::CheckParam*>(param); | |
23 return permission_ == specific_param.permission; | |
24 } | |
25 | |
26 scoped_ptr<base::Value> MediaGalleriesPermissionData::ToValue() const { | |
27 return scoped_ptr<base::Value>(new base::StringValue(permission_)); | |
28 } | |
29 | |
30 bool MediaGalleriesPermissionData::FromValue(const base::Value* value) { | |
31 if (!value) | |
32 return false; | |
33 | |
34 std::string raw_permission; | |
35 if (!value->GetAsString(&raw_permission)) | |
36 return false; | |
37 | |
38 std::string permission; | |
39 base::TrimWhitespaceASCII(raw_permission, base::TRIM_ALL, &permission); | |
40 | |
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; | |
48 } | |
49 return false; | |
50 } | |
51 | |
52 bool MediaGalleriesPermissionData::operator<( | |
53 const MediaGalleriesPermissionData& rhs) const { | |
54 return permission_ < rhs.permission_; | |
55 } | |
56 | |
57 bool MediaGalleriesPermissionData::operator==( | |
58 const MediaGalleriesPermissionData& rhs) const { | |
59 return permission_ == rhs.permission_; | |
60 } | |
61 | |
62 } // namespace extensions | |
OLD | NEW |