| Index: chrome/browser/usb/usb_common.cc
|
| diff --git a/chrome/browser/usb/usb_common.cc b/chrome/browser/usb/usb_common.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f7dc5103c29f58a88da1727cf4ef138ed40e13d9
|
| --- /dev/null
|
| +++ b/chrome/browser/usb/usb_common.cc
|
| @@ -0,0 +1,37 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/usb/usb_common.h"
|
| +
|
| +#include "base/metrics/histogram_macros.h"
|
| +#include "base/stl_util.h"
|
| +#include "device/usb/webusb_descriptors.h"
|
| +#include "url/gurl.h"
|
| +
|
| +void RecordChooserClosure(WebUsbChooserClosed disposition) {
|
| + UMA_HISTOGRAM_ENUMERATION("WebUsb.ChooserClosed", disposition,
|
| + WEBUSB_CHOOSER_CLOSED_MAX);
|
| +}
|
| +
|
| +// Check if the origin is allowed.
|
| +bool FindInAllowedOrigins(const device::WebUsbAllowedOrigins* allowed_origins,
|
| + const GURL& origin) {
|
| + if (!allowed_origins)
|
| + return false;
|
| +
|
| + if (ContainsValue(allowed_origins->origins, origin))
|
| + return true;
|
| +
|
| + for (const auto& config : allowed_origins->configurations) {
|
| + if (ContainsValue(config.origins, origin))
|
| + return true;
|
| +
|
| + for (const auto& function : config.functions) {
|
| + if (ContainsValue(function.origins, origin))
|
| + return true;
|
| + }
|
| + }
|
| +
|
| + return false;
|
| +}
|
|
|