Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: extensions/common/permissions/usb_device_permission_data.cc

Issue 1485853003: Revert of Remove kuint16max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint2
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/permissions/usb_device_permission_data.h" 5 #include "extensions/common/permissions/usb_device_permission_data.h"
6 6
7 #include <limits>
8 #include <string> 7 #include <string>
9 #include <tuple> 8 #include <tuple>
10 #include <vector> 9 #include <vector>
11 10
12 #include "base/basictypes.h" 11 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
16 #include "base/values.h" 15 #include "base/values.h"
17 #include "extensions/common/permissions/api_permission.h" 16 #include "extensions/common/permissions/api_permission.h"
18 #include "extensions/common/permissions/usb_device_permission.h" 17 #include "extensions/common/permissions/usb_device_permission.h"
19 18
20 namespace { 19 namespace {
21 20
22 const char* kProductIdKey = "productId"; 21 const char* kProductIdKey = "productId";
23 const char* kVendorIdKey = "vendorId"; 22 const char* kVendorIdKey = "vendorId";
24 const char* kInterfaceIdKey = "interfaceId"; 23 const char* kInterfaceIdKey = "interfaceId";
25 24
26 } // namespace 25 } // namespace
27 26
28 namespace extensions { 27 namespace extensions {
29 28
30 UsbDevicePermissionData::UsbDevicePermissionData() 29 UsbDevicePermissionData::UsbDevicePermissionData()
31 : vendor_id_(0), product_id_(0), interface_id_(ANY_INTERFACE) { 30 : vendor_id_(0), product_id_(0), interface_id_(ANY_INTERFACE) {
32 } 31 }
33 32
34 UsbDevicePermissionData::UsbDevicePermissionData(uint16_t vendor_id, 33 UsbDevicePermissionData::UsbDevicePermissionData(uint16 vendor_id,
35 uint16_t product_id, 34 uint16 product_id,
36 int interface_id) 35 int interface_id)
37 : vendor_id_(vendor_id), 36 : vendor_id_(vendor_id),
38 product_id_(product_id), 37 product_id_(product_id),
39 interface_id_(interface_id) {} 38 interface_id_(interface_id) {
39 }
40 40
41 bool UsbDevicePermissionData::Check( 41 bool UsbDevicePermissionData::Check(
42 const APIPermission::CheckParam* param) const { 42 const APIPermission::CheckParam* param) const {
43 if (!param) 43 if (!param)
44 return false; 44 return false;
45 const UsbDevicePermission::CheckParam& specific_param = 45 const UsbDevicePermission::CheckParam& specific_param =
46 *static_cast<const UsbDevicePermission::CheckParam*>(param); 46 *static_cast<const UsbDevicePermission::CheckParam*>(param);
47 return vendor_id_ == specific_param.vendor_id && 47 return vendor_id_ == specific_param.vendor_id &&
48 product_id_ == specific_param.product_id && 48 product_id_ == specific_param.product_id &&
49 (specific_param.interface_id == UNSPECIFIED_INTERFACE || 49 (specific_param.interface_id == UNSPECIFIED_INTERFACE ||
(...skipping 12 matching lines...) Expand all
62 if (!value) 62 if (!value)
63 return false; 63 return false;
64 64
65 const base::DictionaryValue* dict_value; 65 const base::DictionaryValue* dict_value;
66 if (!value->GetAsDictionary(&dict_value)) 66 if (!value->GetAsDictionary(&dict_value))
67 return false; 67 return false;
68 68
69 int temp; 69 int temp;
70 if (!dict_value->GetInteger(kVendorIdKey, &temp)) 70 if (!dict_value->GetInteger(kVendorIdKey, &temp))
71 return false; 71 return false;
72 if (temp < 0 || temp > std::numeric_limits<uint16_t>::max()) 72 if (temp < 0 || temp > kuint16max)
73 return false; 73 return false;
74 vendor_id_ = temp; 74 vendor_id_ = temp;
75 75
76 if (!dict_value->GetInteger(kProductIdKey, &temp)) 76 if (!dict_value->GetInteger(kProductIdKey, &temp))
77 return false; 77 return false;
78 if (temp < 0 || temp > std::numeric_limits<uint16_t>::max()) 78 if (temp < 0 || temp > kuint16max)
79 return false; 79 return false;
80 product_id_ = temp; 80 product_id_ = temp;
81 81
82 if (!dict_value->GetInteger(kInterfaceIdKey, &temp)) 82 if (!dict_value->GetInteger(kInterfaceIdKey, &temp))
83 interface_id_ = ANY_INTERFACE; 83 interface_id_ = ANY_INTERFACE;
84 else if (temp < ANY_INTERFACE || temp > std::numeric_limits<uint8_t>::max()) 84 else if (temp < ANY_INTERFACE || temp > kuint8max)
85 return false; 85 return false;
86 else 86 else
87 interface_id_ = temp; 87 interface_id_ = temp;
88 88
89 return true; 89 return true;
90 } 90 }
91 91
92 bool UsbDevicePermissionData::operator<( 92 bool UsbDevicePermissionData::operator<(
93 const UsbDevicePermissionData& rhs) const { 93 const UsbDevicePermissionData& rhs) const {
94 return std::tie(vendor_id_, product_id_, interface_id_) < 94 return std::tie(vendor_id_, product_id_, interface_id_) <
95 std::tie(rhs.vendor_id_, rhs.product_id_, rhs.interface_id_); 95 std::tie(rhs.vendor_id_, rhs.product_id_, rhs.interface_id_);
96 } 96 }
97 97
98 bool UsbDevicePermissionData::operator==( 98 bool UsbDevicePermissionData::operator==(
99 const UsbDevicePermissionData& rhs) const { 99 const UsbDevicePermissionData& rhs) const {
100 return vendor_id_ == rhs.vendor_id_ && 100 return vendor_id_ == rhs.vendor_id_ &&
101 product_id_ == rhs.product_id_ && 101 product_id_ == rhs.product_id_ &&
102 interface_id_ == rhs.interface_id_; 102 interface_id_ == rhs.interface_id_;
103 } 103 }
104 104
105 } // namespace extensions 105 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/permissions/usb_device_permission_data.h ('k') | jingle/notifier/communicator/single_login_attempt.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698