Extensions: Remove the legacy GetMessages/HasMessages
[chromium-blink-merge.git] / extensions / common / permissions / api_permission.cc
blob70b71ce63fa2925fc268504451fd3ccac061b3a6
1 // Copyright 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 "extensions/common/permissions/api_permission.h"
7 #include "extensions/common/permissions/api_permission_set.h"
8 #include "ui/base/l10n/l10n_util.h"
10 namespace {
12 using extensions::APIPermission;
13 using extensions::APIPermissionInfo;
14 using extensions::PermissionMessage;
15 using extensions::PermissionMessages;
17 class SimpleAPIPermission : public APIPermission {
18 public:
19 explicit SimpleAPIPermission(const APIPermissionInfo* permission)
20 : APIPermission(permission) { }
22 ~SimpleAPIPermission() override {}
24 extensions::PermissionIDSet GetPermissions() const override {
25 extensions::PermissionIDSet permissions;
26 permissions.insert(id());
27 return permissions;
30 bool Check(const APIPermission::CheckParam* param) const override {
31 return !param;
34 bool Contains(const APIPermission* rhs) const override {
35 CHECK_EQ(info(), rhs->info());
36 return true;
39 bool Equal(const APIPermission* rhs) const override {
40 if (this != rhs)
41 CHECK_EQ(info(), rhs->info());
42 return true;
45 bool FromValue(const base::Value* value,
46 std::string* /*error*/,
47 std::vector<std::string>* /*unhandled_permissions*/) override {
48 return (value == NULL);
51 scoped_ptr<base::Value> ToValue() const override {
52 return scoped_ptr<base::Value>();
55 APIPermission* Clone() const override {
56 return new SimpleAPIPermission(info());
59 APIPermission* Diff(const APIPermission* rhs) const override {
60 CHECK_EQ(info(), rhs->info());
61 return NULL;
64 APIPermission* Union(const APIPermission* rhs) const override {
65 CHECK_EQ(info(), rhs->info());
66 return new SimpleAPIPermission(info());
69 APIPermission* Intersect(const APIPermission* rhs) const override {
70 CHECK_EQ(info(), rhs->info());
71 return new SimpleAPIPermission(info());
74 void Write(IPC::Message* m) const override {}
76 bool Read(const IPC::Message* m, base::PickleIterator* iter) override {
77 return true;
80 void Log(std::string* log) const override {}
83 } // namespace
85 namespace extensions {
87 APIPermission::APIPermission(const APIPermissionInfo* info)
88 : info_(info) {
89 DCHECK(info_);
92 APIPermission::~APIPermission() { }
94 APIPermission::ID APIPermission::id() const {
95 return info()->id();
98 const char* APIPermission::name() const {
99 return info()->name();
103 // APIPermissionInfo
106 APIPermissionInfo::APIPermissionInfo(const APIPermissionInfo::InitInfo& info)
107 : id_(info.id),
108 name_(info.name),
109 flags_(info.flags),
110 api_permission_constructor_(info.constructor) {
113 APIPermissionInfo::~APIPermissionInfo() { }
115 APIPermission* APIPermissionInfo::CreateAPIPermission() const {
116 return api_permission_constructor_ ?
117 api_permission_constructor_(this) : new SimpleAPIPermission(this);
120 } // namespace extensions