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. 4 5 #include "chrome/common/extensions/permissions/bluetooth_permission_data.h" 6 7 #include <string> 8 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" 13 14 namespace { 15 16 const char* kUuidKey = "uuid"; 17 18 } // namespace 19 20 namespace extensions { 21 BluetoothPermissionData()22BluetoothPermissionData::BluetoothPermissionData() {} 23 BluetoothPermissionData(const std::string & uuid)24BluetoothPermissionData::BluetoothPermissionData( 25 const std::string& uuid) : uuid_(uuid) { 26 } 27 Check(const APIPermission::CheckParam * param) const28bool BluetoothPermissionData::Check( 29 const APIPermission::CheckParam* param) const { 30 if (!param) 31 return false; 32 const BluetoothPermission::CheckParam& specific_param = 33 *static_cast<const BluetoothPermission::CheckParam*>(param); 34 35 std::string canonical_uuid = device::bluetooth_utils::CanonicalUuid(uuid_); 36 std::string canonical_param_uuid = device::bluetooth_utils::CanonicalUuid( 37 specific_param.uuid); 38 return canonical_uuid == canonical_param_uuid; 39 } 40 ToValue() const41scoped_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); 45 } 46 FromValue(const base::Value * value)47bool BluetoothPermissionData::FromValue(const base::Value* value) { 48 if (!value) 49 return false; 50 51 const base::DictionaryValue* dict_value; 52 if (!value->GetAsDictionary(&dict_value)) 53 return false; 54 55 if (!dict_value->GetString(kUuidKey, &uuid_)) { 56 uuid_.clear(); 57 return false; 58 } 59 60 return true; 61 } 62 operator <(const BluetoothPermissionData & rhs) const63bool BluetoothPermissionData::operator<( 64 const BluetoothPermissionData& rhs) const { 65 return uuid_ < rhs.uuid_; 66 } 67 operator ==(const BluetoothPermissionData & rhs) const68bool BluetoothPermissionData::operator==( 69 const BluetoothPermissionData& rhs) const { 70 return uuid_ == rhs.uuid_; 71 } 72 73 } // namespace extensions 74