| OLD | NEW |
| 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 <memory> |
| 8 |
| 8 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "device/bluetooth/bluetooth_uuid.h" | 12 #include "device/bluetooth/bluetooth_uuid.h" |
| 12 #include "extensions/common/api/bluetooth/bluetooth_manifest_data.h" | 13 #include "extensions/common/api/bluetooth/bluetooth_manifest_data.h" |
| 13 #include "extensions/common/api/extensions_manifest_types.h" | 14 #include "extensions/common/api/extensions_manifest_types.h" |
| 14 #include "extensions/common/error_utils.h" | 15 #include "extensions/common/error_utils.h" |
| 15 #include "extensions/common/features/behavior_feature.h" | 16 #include "extensions/common/features/behavior_feature.h" |
| 16 #include "extensions/common/features/feature_provider.h" | 17 #include "extensions/common/features/feature_provider.h" |
| 17 #include "extensions/common/manifest_constants.h" | 18 #include "extensions/common/manifest_constants.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 36 if (!bt_uuid.IsValid()) { | 37 if (!bt_uuid.IsValid()) { |
| 37 *error = ErrorUtils::FormatErrorMessageUTF16( | 38 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 38 errors::kErrorInvalidUuid, uuid); | 39 errors::kErrorInvalidUuid, uuid); |
| 39 return false; | 40 return false; |
| 40 } | 41 } |
| 41 permission->AddPermission(uuid); | 42 permission->AddPermission(uuid); |
| 42 return true; | 43 return true; |
| 43 } | 44 } |
| 44 | 45 |
| 45 bool ParseUuidArray(BluetoothManifestPermission* permission, | 46 bool ParseUuidArray(BluetoothManifestPermission* permission, |
| 46 const scoped_ptr<std::vector<std::string> >& uuids, | 47 const std::unique_ptr<std::vector<std::string>>& uuids, |
| 47 base::string16* error) { | 48 base::string16* error) { |
| 48 for (std::vector<std::string>::const_iterator it = uuids->begin(); | 49 for (std::vector<std::string>::const_iterator it = uuids->begin(); |
| 49 it != uuids->end(); | 50 it != uuids->end(); |
| 50 ++it) { | 51 ++it) { |
| 51 if (!ParseUuid(permission, *it, error)) { | 52 if (!ParseUuid(permission, *it, error)) { |
| 52 return false; | 53 return false; |
| 53 } | 54 } |
| 54 } | 55 } |
| 55 return true; | 56 return true; |
| 56 } | 57 } |
| 57 | 58 |
| 58 } // namespace | 59 } // namespace |
| 59 | 60 |
| 60 BluetoothManifestPermission::BluetoothManifestPermission() | 61 BluetoothManifestPermission::BluetoothManifestPermission() |
| 61 : socket_(false), low_energy_(false), peripheral_(false) { | 62 : socket_(false), low_energy_(false), peripheral_(false) { |
| 62 } | 63 } |
| 63 | 64 |
| 64 BluetoothManifestPermission::~BluetoothManifestPermission() {} | 65 BluetoothManifestPermission::~BluetoothManifestPermission() {} |
| 65 | 66 |
| 66 // static | 67 // static |
| 67 scoped_ptr<BluetoothManifestPermission> BluetoothManifestPermission::FromValue( | 68 std::unique_ptr<BluetoothManifestPermission> |
| 68 const base::Value& value, | 69 BluetoothManifestPermission::FromValue(const base::Value& value, |
| 69 base::string16* error) { | 70 base::string16* error) { |
| 70 scoped_ptr<api::extensions_manifest_types::Bluetooth> bluetooth = | 71 std::unique_ptr<api::extensions_manifest_types::Bluetooth> bluetooth = |
| 71 api::extensions_manifest_types::Bluetooth::FromValue(value, error); | 72 api::extensions_manifest_types::Bluetooth::FromValue(value, error); |
| 72 if (!bluetooth) | 73 if (!bluetooth) |
| 73 return scoped_ptr<BluetoothManifestPermission>(); | 74 return std::unique_ptr<BluetoothManifestPermission>(); |
| 74 | 75 |
| 75 scoped_ptr<BluetoothManifestPermission> result( | 76 std::unique_ptr<BluetoothManifestPermission> result( |
| 76 new BluetoothManifestPermission()); | 77 new BluetoothManifestPermission()); |
| 77 if (bluetooth->uuids) { | 78 if (bluetooth->uuids) { |
| 78 if (!ParseUuidArray(result.get(), bluetooth->uuids, error)) { | 79 if (!ParseUuidArray(result.get(), bluetooth->uuids, error)) { |
| 79 return scoped_ptr<BluetoothManifestPermission>(); | 80 return std::unique_ptr<BluetoothManifestPermission>(); |
| 80 } | 81 } |
| 81 } | 82 } |
| 82 if (bluetooth->socket) { | 83 if (bluetooth->socket) { |
| 83 result->socket_ = *(bluetooth->socket); | 84 result->socket_ = *(bluetooth->socket); |
| 84 } | 85 } |
| 85 if (bluetooth->low_energy) { | 86 if (bluetooth->low_energy) { |
| 86 result->low_energy_ = *(bluetooth->low_energy); | 87 result->low_energy_ = *(bluetooth->low_energy); |
| 87 } | 88 } |
| 88 if (bluetooth->peripheral) { | 89 if (bluetooth->peripheral) { |
| 89 result->peripheral_ = *(bluetooth->peripheral); | 90 result->peripheral_ = *(bluetooth->peripheral); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (!uuids_.empty()) { | 134 if (!uuids_.empty()) { |
| 134 permissions.insert(APIPermission::kBluetoothDevices); | 135 permissions.insert(APIPermission::kBluetoothDevices); |
| 135 } | 136 } |
| 136 return permissions; | 137 return permissions; |
| 137 } | 138 } |
| 138 | 139 |
| 139 bool BluetoothManifestPermission::FromValue(const base::Value* value) { | 140 bool BluetoothManifestPermission::FromValue(const base::Value* value) { |
| 140 if (!value) | 141 if (!value) |
| 141 return false; | 142 return false; |
| 142 base::string16 error; | 143 base::string16 error; |
| 143 scoped_ptr<BluetoothManifestPermission> manifest_permission( | 144 std::unique_ptr<BluetoothManifestPermission> manifest_permission( |
| 144 BluetoothManifestPermission::FromValue(*value, &error)); | 145 BluetoothManifestPermission::FromValue(*value, &error)); |
| 145 | 146 |
| 146 if (!manifest_permission) | 147 if (!manifest_permission) |
| 147 return false; | 148 return false; |
| 148 | 149 |
| 149 uuids_ = manifest_permission->uuids_; | 150 uuids_ = manifest_permission->uuids_; |
| 150 return true; | 151 return true; |
| 151 } | 152 } |
| 152 | 153 |
| 153 scoped_ptr<base::Value> BluetoothManifestPermission::ToValue() const { | 154 std::unique_ptr<base::Value> BluetoothManifestPermission::ToValue() const { |
| 154 api::extensions_manifest_types::Bluetooth bluetooth; | 155 api::extensions_manifest_types::Bluetooth bluetooth; |
| 155 bluetooth.uuids.reset(new std::vector<std::string>(uuids_.begin(), | 156 bluetooth.uuids.reset(new std::vector<std::string>(uuids_.begin(), |
| 156 uuids_.end())); | 157 uuids_.end())); |
| 157 return bluetooth.ToValue(); | 158 return bluetooth.ToValue(); |
| 158 } | 159 } |
| 159 | 160 |
| 160 ManifestPermission* BluetoothManifestPermission::Diff( | 161 ManifestPermission* BluetoothManifestPermission::Diff( |
| 161 const ManifestPermission* rhs) const { | 162 const ManifestPermission* rhs) const { |
| 162 const BluetoothManifestPermission* other = | 163 const BluetoothManifestPermission* other = |
| 163 static_cast<const BluetoothManifestPermission*>(rhs); | 164 static_cast<const BluetoothManifestPermission*>(rhs); |
| 164 | 165 |
| 165 scoped_ptr<BluetoothManifestPermission> result( | 166 std::unique_ptr<BluetoothManifestPermission> result( |
| 166 new BluetoothManifestPermission()); | 167 new BluetoothManifestPermission()); |
| 167 result->uuids_ = base::STLSetDifference<BluetoothUuidSet>( | 168 result->uuids_ = base::STLSetDifference<BluetoothUuidSet>( |
| 168 uuids_, other->uuids_); | 169 uuids_, other->uuids_); |
| 169 return result.release(); | 170 return result.release(); |
| 170 } | 171 } |
| 171 | 172 |
| 172 ManifestPermission* BluetoothManifestPermission::Union( | 173 ManifestPermission* BluetoothManifestPermission::Union( |
| 173 const ManifestPermission* rhs) const { | 174 const ManifestPermission* rhs) const { |
| 174 const BluetoothManifestPermission* other = | 175 const BluetoothManifestPermission* other = |
| 175 static_cast<const BluetoothManifestPermission*>(rhs); | 176 static_cast<const BluetoothManifestPermission*>(rhs); |
| 176 | 177 |
| 177 scoped_ptr<BluetoothManifestPermission> result( | 178 std::unique_ptr<BluetoothManifestPermission> result( |
| 178 new BluetoothManifestPermission()); | 179 new BluetoothManifestPermission()); |
| 179 result->uuids_ = base::STLSetUnion<BluetoothUuidSet>( | 180 result->uuids_ = base::STLSetUnion<BluetoothUuidSet>( |
| 180 uuids_, other->uuids_); | 181 uuids_, other->uuids_); |
| 181 return result.release(); | 182 return result.release(); |
| 182 } | 183 } |
| 183 | 184 |
| 184 ManifestPermission* BluetoothManifestPermission::Intersect( | 185 ManifestPermission* BluetoothManifestPermission::Intersect( |
| 185 const ManifestPermission* rhs) const { | 186 const ManifestPermission* rhs) const { |
| 186 const BluetoothManifestPermission* other = | 187 const BluetoothManifestPermission* other = |
| 187 static_cast<const BluetoothManifestPermission*>(rhs); | 188 static_cast<const BluetoothManifestPermission*>(rhs); |
| 188 | 189 |
| 189 scoped_ptr<BluetoothManifestPermission> result( | 190 std::unique_ptr<BluetoothManifestPermission> result( |
| 190 new BluetoothManifestPermission()); | 191 new BluetoothManifestPermission()); |
| 191 result->uuids_ = base::STLSetIntersection<BluetoothUuidSet>( | 192 result->uuids_ = base::STLSetIntersection<BluetoothUuidSet>( |
| 192 uuids_, other->uuids_); | 193 uuids_, other->uuids_); |
| 193 return result.release(); | 194 return result.release(); |
| 194 } | 195 } |
| 195 | 196 |
| 196 void BluetoothManifestPermission::AddPermission(const std::string& uuid) { | 197 void BluetoothManifestPermission::AddPermission(const std::string& uuid) { |
| 197 uuids_.insert(uuid); | 198 uuids_.insert(uuid); |
| 198 } | 199 } |
| 199 | 200 |
| 200 } // namespace extensions | 201 } // namespace extensions |
| OLD | NEW |