Extract SIGPIPE ignoring code to a common place.
[chromium-blink-merge.git] / chrome / common / extensions / permissions / socket_permission.h
blobe148379c39df7562da5b558ddd2878ca6701a106
1 // Copyright (c) 2012 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 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_H_
6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_H_
8 #include <set>
9 #include <string>
11 #include "chrome/common/extensions/permissions/api_permission.h"
12 #include "chrome/common/extensions/permissions/socket_permission_data.h"
14 namespace base {
15 class Value;
18 namespace IPC {
19 class Message;
22 namespace extensions {
24 // There's room to share code with related classes, see http://crbug.com/147531
26 class SocketPermission : public APIPermission {
27 public:
28 struct CheckParam : APIPermission::CheckParam {
29 CheckParam(content::SocketPermissionRequest::OperationType type,
30 const std::string& host,
31 int port)
32 : request(type, host, port) { }
33 content::SocketPermissionRequest request;
36 explicit SocketPermission(const APIPermissionInfo* info);
38 virtual ~SocketPermission();
40 // Returns true if this permission has PermissionMessages.
41 virtual bool HasMessages() const OVERRIDE;
43 // Returns the localized permission messages of this permission.
44 virtual PermissionMessages GetMessages() const OVERRIDE;
46 // Returns true if the given permission in param is allowed.
47 virtual bool Check(
48 const APIPermission::CheckParam* param) const OVERRIDE;
50 // Returns true if |rhs| is a subset of this.
51 virtual bool Contains(const APIPermission* rhs) const OVERRIDE;
53 // Returns true if |rhs| is equal to this.
54 virtual bool Equal(const APIPermission* rhs) const OVERRIDE;
56 // Parses the rhs from |value|. Returns false if error happens.
57 virtual bool FromValue(const base::Value* value) OVERRIDE;
59 // Stores this into a new created |value|.
60 virtual void ToValue(base::Value** value) const OVERRIDE;
62 // Clones this.
63 virtual APIPermission* Clone() const OVERRIDE;
65 // Returns a new API permission rhs which equals this - |rhs|.
66 virtual APIPermission* Diff(const APIPermission* rhs) const OVERRIDE;
68 // Returns a new API permission rhs which equals the union of this and
69 // |rhs|.
70 virtual APIPermission* Union(const APIPermission* rhs) const OVERRIDE;
72 // Returns a new API permission rhs which equals the intersect of this and
73 // |rhs|.
74 virtual APIPermission* Intersect(const APIPermission* rhs) const OVERRIDE;
76 // IPC functions
77 // Writes this into the given IPC message |m|.
78 virtual void Write(IPC::Message* m) const OVERRIDE;
80 // Reads from the given IPC message |m|.
81 virtual bool Read(const IPC::Message* m, PickleIterator* iter) OVERRIDE;
83 // Logs this rhs.
84 virtual void Log(std::string* log) const OVERRIDE;
86 private:
87 bool AddAnyHostMessage(PermissionMessages& messages) const;
88 void AddSubdomainHostMessage(PermissionMessages& messages) const;
89 void AddSpecificHostMessage(PermissionMessages& messages) const;
91 std::set<SocketPermissionData> data_set_;
94 } // namespace extensions
96 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_H_