Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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/browser/ui/bluetooth/bluetooth_chooser_context.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/values.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 const char kDeviceIdKey[] = "device-id"; | |
| 15 const char kDeviceNameKey[] = "device-name"; | |
| 16 | |
| 17 const base::DictionaryValue* FindForDevice( | |
| 18 const std::vector<scoped_ptr<base::DictionaryValue>>& device_list, | |
| 19 const base::string16& device_name, | |
| 20 const std::string& device_id) { | |
| 21 for (const scoped_ptr<base::DictionaryValue>& device_dict : device_list) { | |
| 22 base::string16 tmp_device_name; | |
| 23 std::string tmp_device_id; | |
| 24 if (device_dict->GetString(kDeviceNameKey, &tmp_device_name) && | |
| 25 tmp_device_name == device_name && | |
| 26 device_dict->GetString(kDeviceIdKey, &tmp_device_id) && | |
| 27 tmp_device_id == device_id) { | |
| 28 return device_dict.get(); | |
| 29 } | |
| 30 } | |
| 31 return nullptr; | |
| 32 } | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 BluetoothChooserContext::BluetoothChooserContext(Profile* profile) | |
| 37 : ChooserContextBase(profile, | |
| 38 CONTENT_SETTINGS_TYPE_BLUETOOTH_CHOOSER_DATA) {} | |
| 39 | |
| 40 BluetoothChooserContext::~BluetoothChooserContext() {} | |
| 41 | |
| 42 void BluetoothChooserContext::GrantDevicePermission( | |
| 43 const GURL& requesting_origin, | |
| 44 const GURL& embedding_origin, | |
| 45 const base::string16& device_name, | |
| 46 const std::string& device_id) { | |
| 47 scoped_ptr<base::DictionaryValue> device_dict(new base::DictionaryValue()); | |
| 48 device_dict->SetString(kDeviceNameKey, device_name); | |
|
Reilly Grant (use Gerrit)
2016/01/06 18:44:13
No, don't remove this one! We want to store the de
juncai
2016/01/11 21:55:16
Done.
| |
| 49 device_dict->SetString(kDeviceIdKey, device_id); | |
| 50 GrantObjectPermission(requesting_origin, embedding_origin, | |
| 51 std::move(device_dict)); | |
| 52 } | |
| 53 | |
| 54 void BluetoothChooserContext::RevokeDevicePermission( | |
| 55 const GURL& requesting_origin, | |
| 56 const GURL& embedding_origin, | |
| 57 const base::string16& device_name, | |
| 58 const std::string& device_id) { | |
| 59 std::vector<scoped_ptr<base::DictionaryValue>> device_list = | |
| 60 GetGrantedObjects(requesting_origin, embedding_origin); | |
| 61 const base::DictionaryValue* entry = | |
| 62 FindForDevice(device_list, device_name, device_id); | |
| 63 if (entry) | |
| 64 RevokeObjectPermission(requesting_origin, embedding_origin, *entry); | |
| 65 } | |
| 66 | |
| 67 bool BluetoothChooserContext::HasDevicePermission( | |
| 68 const GURL& requesting_origin, | |
| 69 const GURL& embedding_origin, | |
| 70 const base::string16& device_name, | |
| 71 const std::string& device_id) { | |
| 72 std::vector<scoped_ptr<base::DictionaryValue>> device_list = | |
| 73 GetGrantedObjects(requesting_origin, embedding_origin); | |
| 74 return FindForDevice(device_list, device_name, device_id) != nullptr; | |
| 75 } | |
| 76 | |
| 77 bool BluetoothChooserContext::IsValidObject( | |
| 78 const base::DictionaryValue& object) { | |
| 79 return object.size() == 2 && object.HasKey(kDeviceNameKey) && | |
| 80 object.HasKey(kDeviceIdKey); | |
| 81 } | |
| OLD | NEW |