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 "chrome/common/extensions/permissions/bluetooth_permission_data.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h"
11 #include "chrome/common/extensions/permissions/bluetooth_permission.h"
12 #include "device/bluetooth/bluetooth_utils.h"
16 const char* kUuidKey
= "uuid";
20 namespace extensions
{
22 BluetoothPermissionData::BluetoothPermissionData() {}
24 BluetoothPermissionData::BluetoothPermissionData(
25 const std::string
& uuid
) : uuid_(uuid
) {
28 bool BluetoothPermissionData::Check(
29 const APIPermission::CheckParam
* param
) const {
32 const BluetoothPermission::CheckParam
& specific_param
=
33 *static_cast<const BluetoothPermission::CheckParam
*>(param
);
35 std::string canonical_uuid
= device::bluetooth_utils::CanonicalUuid(uuid_
);
36 std::string canonical_param_uuid
= device::bluetooth_utils::CanonicalUuid(
38 return canonical_uuid
== canonical_param_uuid
;
41 scoped_ptr
<base::Value
> BluetoothPermissionData::ToValue() const {
42 base::DictionaryValue
* result
= new base::DictionaryValue();
43 result
->SetString(kUuidKey
, uuid_
);
44 return scoped_ptr
<base::Value
>(result
);
47 bool BluetoothPermissionData::FromValue(const base::Value
* value
) {
51 const base::DictionaryValue
* dict_value
;
52 if (!value
->GetAsDictionary(&dict_value
))
55 if (!dict_value
->GetString(kUuidKey
, &uuid_
)) {
63 bool BluetoothPermissionData::operator<(
64 const BluetoothPermissionData
& rhs
) const {
65 return uuid_
< rhs
.uuid_
;
68 bool BluetoothPermissionData::operator==(
69 const BluetoothPermissionData
& rhs
) const {
70 return uuid_
== rhs
.uuid_
;
73 } // namespace extensions