Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / permissions / bluetooth_permission_data.cc
blob70eb747b7fe83a2aaadfe3529053155de1f59394
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"
7 #include <string>
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"
14 namespace {
16 const char* kUuidKey = "uuid";
18 } // namespace
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 {
30 if (!param)
31 return false;
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(
37 specific_param.uuid);
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) {
48 if (!value)
49 return false;
51 const base::DictionaryValue* dict_value;
52 if (!value->GetAsDictionary(&dict_value))
53 return false;
55 if (!dict_value->GetString(kUuidKey, &uuid_)) {
56 uuid_.clear();
57 return false;
60 return true;
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