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

Side by Side Diff: extensions/browser/api/usb/usb_api.cc

Issue 1098823003: Separate USB device permissions prompt logic into subclasses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address jyasskin@'s comments. Created 5 years, 8 months 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
« no previous file with comments | « extensions/browser/api/usb/usb_api.h ('k') | extensions/extensions_strings.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/browser/api/usb/usb_api.h" 5 #include "extensions/browser/api/usb/usb_api.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/barrier_closure.h" 10 #include "base/barrier_closure.h"
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 &filters[i]); 634 &filters[i]);
635 } 635 }
636 } 636 }
637 637
638 prompt_ = ExtensionsAPIClient::Get()->CreateDevicePermissionsPrompt( 638 prompt_ = ExtensionsAPIClient::Get()->CreateDevicePermissionsPrompt(
639 GetAssociatedWebContents()); 639 GetAssociatedWebContents());
640 if (!prompt_) { 640 if (!prompt_) {
641 return RespondNow(Error(kErrorNotSupported)); 641 return RespondNow(Error(kErrorNotSupported));
642 } 642 }
643 643
644 AddRef();
645 prompt_->AskForUsbDevices( 644 prompt_->AskForUsbDevices(
646 this, extension(), browser_context(), multiple, filters); 645 extension(), browser_context(), multiple, filters,
646 base::Bind(&UsbGetUserSelectedDevicesFunction::OnDevicesChosen, this));
647 return RespondLater(); 647 return RespondLater();
648 } 648 }
649 649
650 void UsbGetUserSelectedDevicesFunction::OnUsbDevicesChosen( 650 void UsbGetUserSelectedDevicesFunction::OnDevicesChosen(
651 const std::vector<scoped_refptr<UsbDevice>>& devices) { 651 const std::vector<scoped_refptr<UsbDevice>>& devices) {
652 scoped_ptr<base::ListValue> result(new base::ListValue()); 652 scoped_ptr<base::ListValue> result(new base::ListValue());
653 for (const auto& device : devices) { 653 for (const auto& device : devices) {
654 result->Append(PopulateDevice(device.get())); 654 result->Append(PopulateDevice(device.get()));
655 } 655 }
656 656
657 Respond(OneArgument(result.release())); 657 Respond(OneArgument(result.release()));
658 Release();
659 } 658 }
660 659
661 UsbRequestAccessFunction::UsbRequestAccessFunction() { 660 UsbRequestAccessFunction::UsbRequestAccessFunction() {
662 } 661 }
663 662
664 UsbRequestAccessFunction::~UsbRequestAccessFunction() { 663 UsbRequestAccessFunction::~UsbRequestAccessFunction() {
665 } 664 }
666 665
667 ExtensionFunction::ResponseAction UsbRequestAccessFunction::Run() { 666 ExtensionFunction::ResponseAction UsbRequestAccessFunction::Run() {
668 scoped_ptr<extensions::core_api::usb::RequestAccess::Params> parameters = 667 scoped_ptr<extensions::core_api::usb::RequestAccess::Params> parameters =
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 ReleaseDeviceHandle(parameters_->handle); 1182 ReleaseDeviceHandle(parameters_->handle);
1184 1183
1185 scoped_ptr<base::ListValue> error_args(new base::ListValue()); 1184 scoped_ptr<base::ListValue> error_args(new base::ListValue());
1186 error_args->AppendBoolean(false); 1185 error_args->AppendBoolean(false);
1187 // Returning arguments with an error is wrong but we're stuck with it. 1186 // Returning arguments with an error is wrong but we're stuck with it.
1188 Respond(ErrorWithArguments(error_args.Pass(), kErrorResetDevice)); 1187 Respond(ErrorWithArguments(error_args.Pass(), kErrorResetDevice));
1189 } 1188 }
1190 } 1189 }
1191 1190
1192 } // namespace extensions 1191 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/usb/usb_api.h ('k') | extensions/extensions_strings.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698