summaryrefslogtreecommitdiffstats
path: root/extensions/common/permissions/media_galleries_permission_data.cc
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/common/permissions/media_galleries_permission_data.cc')
-rw-r--r--extensions/common/permissions/media_galleries_permission_data.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/extensions/common/permissions/media_galleries_permission_data.cc b/extensions/common/permissions/media_galleries_permission_data.cc
new file mode 100644
index 0000000..d7e7937
--- /dev/null
+++ b/extensions/common/permissions/media_galleries_permission_data.cc
@@ -0,0 +1,62 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/common/permissions/media_galleries_permission_data.h"
+
+#include "base/strings/string_util.h"
+#include "base/values.h"
+#include "extensions/common/permissions/media_galleries_permission.h"
+
+namespace extensions {
+
+MediaGalleriesPermissionData::MediaGalleriesPermissionData() {
+}
+
+bool MediaGalleriesPermissionData::Check(
+ const APIPermission::CheckParam* param) const {
+ if (!param)
+ return false;
+
+ const MediaGalleriesPermission::CheckParam& specific_param =
+ *static_cast<const MediaGalleriesPermission::CheckParam*>(param);
+ return permission_ == specific_param.permission;
+}
+
+scoped_ptr<base::Value> MediaGalleriesPermissionData::ToValue() const {
+ return scoped_ptr<base::Value>(new base::StringValue(permission_));
+}
+
+bool MediaGalleriesPermissionData::FromValue(const base::Value* value) {
+ if (!value)
+ return false;
+
+ std::string raw_permission;
+ if (!value->GetAsString(&raw_permission))
+ return false;
+
+ std::string permission;
+ base::TrimWhitespaceASCII(raw_permission, base::TRIM_ALL, &permission);
+
+ if (permission == MediaGalleriesPermission::kAllAutoDetectedPermission ||
+ permission == MediaGalleriesPermission::kScanPermission ||
+ permission == MediaGalleriesPermission::kReadPermission ||
+ permission == MediaGalleriesPermission::kCopyToPermission ||
+ permission == MediaGalleriesPermission::kDeletePermission) {
+ permission_ = permission;
+ return true;
+ }
+ return false;
+}
+
+bool MediaGalleriesPermissionData::operator<(
+ const MediaGalleriesPermissionData& rhs) const {
+ return permission_ < rhs.permission_;
+}
+
+bool MediaGalleriesPermissionData::operator==(
+ const MediaGalleriesPermissionData& rhs) const {
+ return permission_ == rhs.permission_;
+}
+
+} // namespace extensions