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

Side by Side Diff: chrome/browser/chromeos/bluetooth/bluetooth_service_record_dbus.cc

Issue 10899037: Refactoring bluetooth API code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated the interfaces with class-level comments. Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" 5 #include "chrome/browser/chromeos/bluetooth/bluetooth_service_record_dbus.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" 12 #include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h"
13 #include "third_party/libxml/chromium/libxml_utils.h" 13 #include "third_party/libxml/chromium/libxml_utils.h"
14 14
15 namespace { 15 namespace {
(...skipping 23 matching lines...) Expand all
39 reader->NodeAttribute(kValueAttribute, value_out); 39 reader->NodeAttribute(kValueAttribute, value_out);
40 return true; 40 return true;
41 } 41 }
42 return false; 42 return false;
43 } 43 }
44 44
45 } // namespace 45 } // namespace
46 46
47 namespace chromeos { 47 namespace chromeos {
48 48
49 BluetoothServiceRecord::BluetoothServiceRecord( 49 BluetoothServiceRecordDBus::BluetoothServiceRecordDBus(
50 const std::string& address, 50 const std::string& address,
51 const std::string& xml_data) 51 const std::string& xml_data)
52 : address_(address), 52 : address_(address),
53 supports_rfcomm_(false) { 53 supports_rfcomm_(false) {
54 54
55 XmlReader reader; 55 XmlReader reader;
56 if (!reader.Load(xml_data)) 56 if (!reader.Load(xml_data))
57 return; 57 return;
58 58
59 while (AdvanceToTag(&reader, kAttributeNode)) { 59 while (AdvanceToTag(&reader, kAttributeNode)) {
60 std::string id; 60 std::string id;
61 if (reader.NodeAttribute(kIdAttribute, &id)) { 61 if (reader.NodeAttribute(kIdAttribute, &id)) {
62 if (id == kSdpNameId) { 62 if (id == kSdpNameId) {
63 ExtractTextValue(&reader, &name_); 63 ExtractTextValue(&reader, &name_);
64 } else if (id == kProtocolDescriptorListId) { 64 } else if (id == kProtocolDescriptorListId) {
65 if (AdvanceToTag(&reader, kSequenceNode)) { 65 if (AdvanceToTag(&reader, kSequenceNode)) {
66 ExtractChannels(&reader); 66 ExtractChannels(&reader);
67 } 67 }
68 } else if (id == kUuidId) { 68 } else if (id == kUuidId) {
69 if (AdvanceToTag(&reader, kSequenceNode)) { 69 if (AdvanceToTag(&reader, kSequenceNode)) {
70 ExtractUuid(&reader); 70 ExtractUuid(&reader);
71 } 71 }
72 } 72 }
73 } 73 }
74 // We don't care about anything else here, so find the closing tag 74 // We don't care about anything else here, so find the closing tag
75 AdvanceToTag(&reader, kAttributeNode); 75 AdvanceToTag(&reader, kAttributeNode);
76 } 76 }
77 } 77 }
78 78
79 void BluetoothServiceRecord::ExtractChannels(XmlReader* reader) { 79 void BluetoothServiceRecordDBus::ExtractChannels(XmlReader* reader) {
80 const int start_depth = reader->Depth(); 80 const int start_depth = reader->Depth();
81 do { 81 do {
82 if (reader->NodeName() == kSequenceNode) { 82 if (reader->NodeName() == kSequenceNode) {
83 if (AdvanceToTag(reader, kUuidNode)) { 83 if (AdvanceToTag(reader, kUuidNode)) {
84 std::string type; 84 std::string type;
85 if (reader->NodeAttribute(kValueAttribute, &type) && 85 if (reader->NodeAttribute(kValueAttribute, &type) &&
86 type == kRfcommUuid) { 86 type == kRfcommUuid) {
87 if (AdvanceToTag(reader, kUint8Node)) { 87 if (AdvanceToTag(reader, kUint8Node)) {
88 std::string channel_string; 88 std::string channel_string;
89 if (reader->NodeAttribute(kValueAttribute, &channel_string)) { 89 if (reader->NodeAttribute(kValueAttribute, &channel_string)) {
90 std::vector<uint8> channel_bytes; 90 std::vector<uint8> channel_bytes;
91 if (base::HexStringToBytes(channel_string.substr(2), 91 if (base::HexStringToBytes(channel_string.substr(2),
92 &channel_bytes)) { 92 &channel_bytes)) {
93 if (channel_bytes.size() == 1) { 93 if (channel_bytes.size() == 1) {
94 rfcomm_channel_ = channel_bytes[0]; 94 rfcomm_channel_ = channel_bytes[0];
95 supports_rfcomm_ = true; 95 supports_rfcomm_ = true;
96 } 96 }
97 } 97 }
98 } 98 }
99 } 99 }
100 } 100 }
101 } 101 }
102 } 102 }
103 } while (AdvanceToTag(reader, kSequenceNode) && 103 } while (AdvanceToTag(reader, kSequenceNode) &&
104 reader->Depth() != start_depth); 104 reader->Depth() != start_depth);
105 } 105 }
106 106
107 void BluetoothServiceRecord::ExtractUuid(XmlReader* reader) { 107 void BluetoothServiceRecordDBus::ExtractUuid(XmlReader* reader) {
108 const int start_depth = reader->Depth(); 108 const int start_depth = reader->Depth();
109 do { 109 do {
110 if (reader->NodeName() == kSequenceNode) { 110 if (reader->NodeName() == kSequenceNode) {
111 if (AdvanceToTag(reader, kUuidNode)) { 111 if (AdvanceToTag(reader, kUuidNode)) {
112 if (!reader->NodeAttribute(kValueAttribute, &uuid_)) 112 if (!reader->NodeAttribute(kValueAttribute, &uuid_))
113 uuid_.clear(); 113 uuid_.clear();
114 } 114 }
115 } 115 }
116 } while (AdvanceToTag(reader, kSequenceNode) && 116 } while (AdvanceToTag(reader, kSequenceNode) &&
117 reader->Depth() != start_depth); 117 reader->Depth() != start_depth);
118 118
119 uuid_ = bluetooth_utils::CanonicalUuid(uuid_); 119 uuid_ = bluetooth_utils::CanonicalUuid(uuid_);
120 } 120 }
121 121
122 } // namespace chromeos 122 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698