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

Side by Side Diff: extensions/browser/api/bluetooth_socket/bluetooth_socket_api.cc

Issue 1841483002: [Extensions] Convert APIs to use movable types [11] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 | « no previous file | extensions/browser/api/declarative/declarative_api.cc » ('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/bluetooth_socket/bluetooth_socket_api.h" 5 #include "extensions/browser/api/bluetooth_socket/bluetooth_socket_api.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
(...skipping 18 matching lines...) Expand all
29 namespace api { 29 namespace api {
30 30
31 namespace { 31 namespace {
32 32
33 const char kDeviceNotFoundError[] = "Device not found"; 33 const char kDeviceNotFoundError[] = "Device not found";
34 const char kInvalidPsmError[] = "Invalid PSM"; 34 const char kInvalidPsmError[] = "Invalid PSM";
35 const char kInvalidUuidError[] = "Invalid UUID"; 35 const char kInvalidUuidError[] = "Invalid UUID";
36 const char kPermissionDeniedError[] = "Permission denied"; 36 const char kPermissionDeniedError[] = "Permission denied";
37 const char kSocketNotFoundError[] = "Socket not found"; 37 const char kSocketNotFoundError[] = "Socket not found";
38 38
39 linked_ptr<SocketInfo> CreateSocketInfo(int socket_id, 39 SocketInfo CreateSocketInfo(int socket_id, BluetoothApiSocket* socket) {
40 BluetoothApiSocket* socket) {
41 DCHECK_CURRENTLY_ON(BluetoothApiSocket::kThreadId); 40 DCHECK_CURRENTLY_ON(BluetoothApiSocket::kThreadId);
42 linked_ptr<SocketInfo> socket_info(new SocketInfo()); 41 SocketInfo socket_info;
43 // This represents what we know about the socket, and does not call through 42 // This represents what we know about the socket, and does not call through
44 // to the system. 43 // to the system.
45 socket_info->socket_id = socket_id; 44 socket_info.socket_id = socket_id;
46 if (socket->name()) { 45 if (socket->name()) {
47 socket_info->name.reset(new std::string(*socket->name())); 46 socket_info.name.reset(new std::string(*socket->name()));
48 } 47 }
49 socket_info->persistent = socket->persistent(); 48 socket_info.persistent = socket->persistent();
50 if (socket->buffer_size() > 0) { 49 if (socket->buffer_size() > 0) {
51 socket_info->buffer_size.reset(new int(socket->buffer_size())); 50 socket_info.buffer_size.reset(new int(socket->buffer_size()));
52 } 51 }
53 socket_info->paused = socket->paused(); 52 socket_info.paused = socket->paused();
54 socket_info->connected = socket->IsConnected(); 53 socket_info.connected = socket->IsConnected();
55 54
56 if (socket->IsConnected()) 55 if (socket->IsConnected())
57 socket_info->address.reset(new std::string(socket->device_address())); 56 socket_info.address.reset(new std::string(socket->device_address()));
58 socket_info->uuid.reset(new std::string(socket->uuid().canonical_value())); 57 socket_info.uuid.reset(new std::string(socket->uuid().canonical_value()));
59 58
60 return socket_info; 59 return socket_info;
61 } 60 }
62 61
63 void SetSocketProperties(BluetoothApiSocket* socket, 62 void SetSocketProperties(BluetoothApiSocket* socket,
64 SocketProperties* properties) { 63 SocketProperties* properties) {
65 if (properties->name.get()) { 64 if (properties->name.get()) {
66 socket->set_name(*properties->name.get()); 65 socket->set_name(*properties->name.get());
67 } 66 }
68 if (properties->persistent.get()) { 67 if (properties->persistent.get()) {
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 return true; 637 return true;
639 } 638 }
640 639
641 void BluetoothSocketGetInfoFunction::Work() { 640 void BluetoothSocketGetInfoFunction::Work() {
642 BluetoothApiSocket* socket = GetSocket(params_->socket_id); 641 BluetoothApiSocket* socket = GetSocket(params_->socket_id);
643 if (!socket) { 642 if (!socket) {
644 error_ = kSocketNotFoundError; 643 error_ = kSocketNotFoundError;
645 return; 644 return;
646 } 645 }
647 646
648 linked_ptr<bluetooth_socket::SocketInfo> socket_info = 647 results_ = bluetooth_socket::GetInfo::Results::Create(
649 CreateSocketInfo(params_->socket_id, socket); 648 CreateSocketInfo(params_->socket_id, socket));
650 results_ = bluetooth_socket::GetInfo::Results::Create(*socket_info);
651 } 649 }
652 650
653 BluetoothSocketGetSocketsFunction::BluetoothSocketGetSocketsFunction() {} 651 BluetoothSocketGetSocketsFunction::BluetoothSocketGetSocketsFunction() {}
654 652
655 BluetoothSocketGetSocketsFunction::~BluetoothSocketGetSocketsFunction() {} 653 BluetoothSocketGetSocketsFunction::~BluetoothSocketGetSocketsFunction() {}
656 654
657 bool BluetoothSocketGetSocketsFunction::Prepare() { return true; } 655 bool BluetoothSocketGetSocketsFunction::Prepare() { return true; }
658 656
659 void BluetoothSocketGetSocketsFunction::Work() { 657 void BluetoothSocketGetSocketsFunction::Work() {
660 std::vector<linked_ptr<bluetooth_socket::SocketInfo> > socket_infos; 658 std::vector<bluetooth_socket::SocketInfo> socket_infos;
661 base::hash_set<int>* resource_ids = GetSocketIds(); 659 base::hash_set<int>* resource_ids = GetSocketIds();
662 if (resource_ids != NULL) { 660 if (resource_ids) {
663 for (base::hash_set<int>::iterator it = resource_ids->begin(); 661 for (int socket_id : *resource_ids) {
664 it != resource_ids->end();
665 ++it) {
666 int socket_id = *it;
667 BluetoothApiSocket* socket = GetSocket(socket_id); 662 BluetoothApiSocket* socket = GetSocket(socket_id);
668 if (socket) { 663 if (socket) {
669 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); 664 socket_infos.push_back(CreateSocketInfo(socket_id, socket));
670 } 665 }
671 } 666 }
672 } 667 }
673 results_ = bluetooth_socket::GetSockets::Results::Create(socket_infos); 668 results_ = bluetooth_socket::GetSockets::Results::Create(socket_infos);
674 } 669 }
675 670
676 } // namespace api 671 } // namespace api
677 } // namespace extensions 672 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/api/declarative/declarative_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698