Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: extensions/common/api/bluetooth/bluetooth_manifest_permission.cc

Issue 1096393002: API stubs for the BLE advertisement API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/common/api/bluetooth/bluetooth_manifest_permission.h" 5 #include "extensions/common/api/bluetooth/bluetooth_manifest_permission.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 if (!ParseUuid(permission, *it, error)) { 49 if (!ParseUuid(permission, *it, error)) {
50 return false; 50 return false;
51 } 51 }
52 } 52 }
53 return true; 53 return true;
54 } 54 }
55 55
56 } // namespace 56 } // namespace
57 57
58 BluetoothManifestPermission::BluetoothManifestPermission() 58 BluetoothManifestPermission::BluetoothManifestPermission()
59 : socket_(false), 59 : socket_(false), low_energy_(false), peripheral_(false) {
60 low_energy_(false) {} 60 }
61 61
62 BluetoothManifestPermission::~BluetoothManifestPermission() {} 62 BluetoothManifestPermission::~BluetoothManifestPermission() {}
63 63
64 // static 64 // static
65 scoped_ptr<BluetoothManifestPermission> BluetoothManifestPermission::FromValue( 65 scoped_ptr<BluetoothManifestPermission> BluetoothManifestPermission::FromValue(
66 const base::Value& value, 66 const base::Value& value,
67 base::string16* error) { 67 base::string16* error) {
68 scoped_ptr<core_api::extensions_manifest_types::Bluetooth> bluetooth = 68 scoped_ptr<core_api::extensions_manifest_types::Bluetooth> bluetooth =
69 core_api::extensions_manifest_types::Bluetooth::FromValue(value, error); 69 core_api::extensions_manifest_types::Bluetooth::FromValue(value, error);
70 if (!bluetooth) 70 if (!bluetooth)
71 return scoped_ptr<BluetoothManifestPermission>(); 71 return scoped_ptr<BluetoothManifestPermission>();
72 72
73 scoped_ptr<BluetoothManifestPermission> result( 73 scoped_ptr<BluetoothManifestPermission> result(
74 new BluetoothManifestPermission()); 74 new BluetoothManifestPermission());
75 if (bluetooth->uuids) { 75 if (bluetooth->uuids) {
76 if (!ParseUuidArray(result.get(), bluetooth->uuids, error)) { 76 if (!ParseUuidArray(result.get(), bluetooth->uuids, error)) {
77 return scoped_ptr<BluetoothManifestPermission>(); 77 return scoped_ptr<BluetoothManifestPermission>();
78 } 78 }
79 } 79 }
80 if (bluetooth->socket) { 80 if (bluetooth->socket) {
81 result->socket_ = *(bluetooth->socket); 81 result->socket_ = *(bluetooth->socket);
82 } 82 }
83 if (bluetooth->low_energy) { 83 if (bluetooth->low_energy) {
84 result->low_energy_ = *(bluetooth->low_energy); 84 result->low_energy_ = *(bluetooth->low_energy);
85 } 85 }
86 if (bluetooth->peripheral) {
87 result->peripheral_ = *(bluetooth->peripheral);
88 }
86 return result.Pass(); 89 return result.Pass();
87 } 90 }
88 91
89 bool BluetoothManifestPermission::CheckRequest( 92 bool BluetoothManifestPermission::CheckRequest(
90 const Extension* extension, 93 const Extension* extension,
91 const BluetoothPermissionRequest& request) const { 94 const BluetoothPermissionRequest& request) const {
92 95
93 device::BluetoothUUID param_uuid(request.uuid); 96 device::BluetoothUUID param_uuid(request.uuid);
94 for (BluetoothUuidSet::const_iterator it = uuids_.begin(); 97 for (BluetoothUuidSet::const_iterator it = uuids_.begin();
95 it != uuids_.end(); 98 it != uuids_.end();
96 ++it) { 99 ++it) {
97 device::BluetoothUUID uuid(*it); 100 device::BluetoothUUID uuid(*it);
98 if (param_uuid == uuid) 101 if (param_uuid == uuid)
99 return true; 102 return true;
100 } 103 }
101 return false; 104 return false;
102 } 105 }
103 106
104 bool BluetoothManifestPermission::CheckSocketPermitted( 107 bool BluetoothManifestPermission::CheckSocketPermitted(
105 const Extension* extension) const { 108 const Extension* extension) const {
106 return socket_; 109 return socket_;
107 } 110 }
108 111
109 bool BluetoothManifestPermission::CheckLowEnergyPermitted( 112 bool BluetoothManifestPermission::CheckLowEnergyPermitted(
110 const Extension* extension) const { 113 const Extension* extension) const {
111 return low_energy_; 114 return low_energy_;
112 } 115 }
113 116
117 bool BluetoothManifestPermission::CheckPeripheralPermitted(
118 const Extension* extension) const {
119 return peripheral_;
120 }
121
114 std::string BluetoothManifestPermission::name() const { 122 std::string BluetoothManifestPermission::name() const {
115 return manifest_keys::kBluetooth; 123 return manifest_keys::kBluetooth;
116 } 124 }
117 125
118 std::string BluetoothManifestPermission::id() const { return name(); } 126 std::string BluetoothManifestPermission::id() const { return name(); }
119 127
120 PermissionIDSet BluetoothManifestPermission::GetPermissions() const { 128 PermissionIDSet BluetoothManifestPermission::GetPermissions() const {
121 PermissionIDSet permissions; 129 PermissionIDSet permissions;
122 permissions.insert(APIPermission::kBluetooth); 130 permissions.insert(APIPermission::kBluetooth);
123 if (!uuids_.empty()) { 131 if (!uuids_.empty()) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 result->uuids_ = base::STLSetIntersection<BluetoothUuidSet>( 211 result->uuids_ = base::STLSetIntersection<BluetoothUuidSet>(
204 uuids_, other->uuids_); 212 uuids_, other->uuids_);
205 return result.release(); 213 return result.release();
206 } 214 }
207 215
208 void BluetoothManifestPermission::AddPermission(const std::string& uuid) { 216 void BluetoothManifestPermission::AddPermission(const std::string& uuid) {
209 uuids_.insert(uuid); 217 uuids_.insert(uuid);
210 } 218 }
211 219
212 } // namespace extensions 220 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698