| OLD | NEW |
| 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/socket_permission_entry.h" | 5 #include "extensions/common/permissions/socket_permission_entry.h" |
| 6 | 6 |
| 7 #include <cstdlib> | 7 #include <cstdlib> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 #include <tuple> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 16 #include "extensions/common/permissions/api_permission.h" | 17 #include "extensions/common/permissions/api_permission.h" |
| 17 #include "extensions/common/permissions/socket_permission.h" | 18 #include "extensions/common/permissions/socket_permission.h" |
| 18 #include "url/url_canon.h" | 19 #include "url/url_canon.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 36 | 37 |
| 37 namespace extensions { | 38 namespace extensions { |
| 38 | 39 |
| 39 SocketPermissionEntry::SocketPermissionEntry() | 40 SocketPermissionEntry::SocketPermissionEntry() |
| 40 : pattern_(SocketPermissionRequest::NONE, std::string(), kInvalidPort), | 41 : pattern_(SocketPermissionRequest::NONE, std::string(), kInvalidPort), |
| 41 match_subdomains_(false) {} | 42 match_subdomains_(false) {} |
| 42 | 43 |
| 43 SocketPermissionEntry::~SocketPermissionEntry() {} | 44 SocketPermissionEntry::~SocketPermissionEntry() {} |
| 44 | 45 |
| 45 bool SocketPermissionEntry::operator<(const SocketPermissionEntry& rhs) const { | 46 bool SocketPermissionEntry::operator<(const SocketPermissionEntry& rhs) const { |
| 46 if (pattern_.type < rhs.pattern_.type) | 47 return std::tie(pattern_.type, pattern_.host, match_subdomains_, |
| 47 return true; | 48 pattern_.port) < |
| 48 if (pattern_.type > rhs.pattern_.type) | 49 std::tie(rhs.pattern_.type, rhs.pattern_.host, rhs.match_subdomains_, |
| 49 return false; | 50 rhs.pattern_.port); |
| 50 | |
| 51 if (pattern_.host < rhs.pattern_.host) | |
| 52 return true; | |
| 53 if (pattern_.host > rhs.pattern_.host) | |
| 54 return false; | |
| 55 | |
| 56 if (match_subdomains_ < rhs.match_subdomains_) | |
| 57 return true; | |
| 58 if (match_subdomains_ > rhs.match_subdomains_) | |
| 59 return false; | |
| 60 | |
| 61 if (pattern_.port < rhs.pattern_.port) | |
| 62 return true; | |
| 63 return false; | |
| 64 } | 51 } |
| 65 | 52 |
| 66 bool SocketPermissionEntry::operator==(const SocketPermissionEntry& rhs) const { | 53 bool SocketPermissionEntry::operator==(const SocketPermissionEntry& rhs) const { |
| 67 return (pattern_.type == rhs.pattern_.type) && | 54 return (pattern_.type == rhs.pattern_.type) && |
| 68 (pattern_.host == rhs.pattern_.host) && | 55 (pattern_.host == rhs.pattern_.host) && |
| 69 (match_subdomains_ == rhs.match_subdomains_) && | 56 (match_subdomains_ == rhs.match_subdomains_) && |
| 70 (pattern_.port == rhs.pattern_.port); | 57 (pattern_.port == rhs.pattern_.port); |
| 71 } | 58 } |
| 72 | 59 |
| 73 bool SocketPermissionEntry::Check( | 60 bool SocketPermissionEntry::Check( |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 204 |
| 218 if (pattern_.port == kWildcardPortNumber) | 205 if (pattern_.port == kWildcardPortNumber) |
| 219 result.append(1, kColon).append(kWildcard); | 206 result.append(1, kColon).append(kWildcard); |
| 220 else | 207 else |
| 221 result.append(1, kColon).append(base::UintToString(pattern_.port)); | 208 result.append(1, kColon).append(base::UintToString(pattern_.port)); |
| 222 | 209 |
| 223 return result; | 210 return result; |
| 224 } | 211 } |
| 225 | 212 |
| 226 } // namespace extensions | 213 } // namespace extensions |
| OLD | NEW |