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/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.h
" | 5 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.h
" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 NOTREACHED(); | 84 NOTREACHED(); |
85 break; | 85 break; |
86 default: | 86 default: |
87 return kErrorOperationFailed; | 87 return kErrorOperationFailed; |
88 } | 88 } |
89 return ""; | 89 return ""; |
90 } | 90 } |
91 | 91 |
92 extensions::BluetoothLowEnergyEventRouter* GetEventRouter( | 92 extensions::BluetoothLowEnergyEventRouter* GetEventRouter( |
93 BrowserContext* context) { | 93 BrowserContext* context) { |
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 94 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
95 return extensions::BluetoothLowEnergyAPI::Get(context)->event_router(); | 95 return extensions::BluetoothLowEnergyAPI::Get(context)->event_router(); |
96 } | 96 } |
97 | 97 |
98 void DoWorkCallback(const base::Callback<bool()>& callback) { | 98 void DoWorkCallback(const base::Callback<bool()>& callback) { |
99 DCHECK(!callback.is_null()); | 99 DCHECK(!callback.is_null()); |
100 callback.Run(); | 100 callback.Run(); |
101 } | 101 } |
102 | 102 |
103 } // namespace | 103 } // namespace |
104 | 104 |
105 | 105 |
106 static base::LazyInstance<BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI> > | 106 static base::LazyInstance<BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI> > |
107 g_factory = LAZY_INSTANCE_INITIALIZER; | 107 g_factory = LAZY_INSTANCE_INITIALIZER; |
108 | 108 |
109 // static | 109 // static |
110 BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>* | 110 BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>* |
111 BluetoothLowEnergyAPI::GetFactoryInstance() { | 111 BluetoothLowEnergyAPI::GetFactoryInstance() { |
112 return g_factory.Pointer(); | 112 return g_factory.Pointer(); |
113 } | 113 } |
114 | 114 |
115 // static | 115 // static |
116 BluetoothLowEnergyAPI* BluetoothLowEnergyAPI::Get(BrowserContext* context) { | 116 BluetoothLowEnergyAPI* BluetoothLowEnergyAPI::Get(BrowserContext* context) { |
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 117 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
118 return GetFactoryInstance()->Get(context); | 118 return GetFactoryInstance()->Get(context); |
119 } | 119 } |
120 | 120 |
121 BluetoothLowEnergyAPI::BluetoothLowEnergyAPI(BrowserContext* context) | 121 BluetoothLowEnergyAPI::BluetoothLowEnergyAPI(BrowserContext* context) |
122 : event_router_(new BluetoothLowEnergyEventRouter(context)) { | 122 : event_router_(new BluetoothLowEnergyEventRouter(context)) { |
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
124 } | 124 } |
125 | 125 |
126 BluetoothLowEnergyAPI::~BluetoothLowEnergyAPI() { | 126 BluetoothLowEnergyAPI::~BluetoothLowEnergyAPI() { |
127 } | 127 } |
128 | 128 |
129 void BluetoothLowEnergyAPI::Shutdown() { | 129 void BluetoothLowEnergyAPI::Shutdown() { |
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 130 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
131 } | 131 } |
132 | 132 |
133 namespace core_api { | 133 namespace core_api { |
134 | 134 |
135 BluetoothLowEnergyExtensionFunction::BluetoothLowEnergyExtensionFunction() { | 135 BluetoothLowEnergyExtensionFunction::BluetoothLowEnergyExtensionFunction() { |
136 } | 136 } |
137 | 137 |
138 BluetoothLowEnergyExtensionFunction::~BluetoothLowEnergyExtensionFunction() { | 138 BluetoothLowEnergyExtensionFunction::~BluetoothLowEnergyExtensionFunction() { |
139 } | 139 } |
140 | 140 |
141 bool BluetoothLowEnergyExtensionFunction::RunAsync() { | 141 bool BluetoothLowEnergyExtensionFunction::RunAsync() { |
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 142 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
143 | 143 |
144 if (!BluetoothManifestData::CheckLowEnergyPermitted(extension())) { | 144 if (!BluetoothManifestData::CheckLowEnergyPermitted(extension())) { |
145 error_ = kErrorPermissionDenied; | 145 error_ = kErrorPermissionDenied; |
146 return false; | 146 return false; |
147 } | 147 } |
148 | 148 |
149 BluetoothLowEnergyEventRouter* event_router = | 149 BluetoothLowEnergyEventRouter* event_router = |
150 GetEventRouter(browser_context()); | 150 GetEventRouter(browser_context()); |
151 if (!event_router->IsBluetoothSupported()) { | 151 if (!event_router->IsBluetoothSupported()) { |
152 SetError(kErrorPlatformNotSupported); | 152 SetError(kErrorPlatformNotSupported); |
153 return false; | 153 return false; |
154 } | 154 } |
155 | 155 |
156 // It is safe to pass |this| here as ExtensionFunction is refcounted. | 156 // It is safe to pass |this| here as ExtensionFunction is refcounted. |
157 if (!event_router->InitializeAdapterAndInvokeCallback(base::Bind( | 157 if (!event_router->InitializeAdapterAndInvokeCallback(base::Bind( |
158 &DoWorkCallback, | 158 &DoWorkCallback, |
159 base::Bind(&BluetoothLowEnergyExtensionFunction::DoWork, this)))) { | 159 base::Bind(&BluetoothLowEnergyExtensionFunction::DoWork, this)))) { |
160 SetError(kErrorAdapterNotInitialized); | 160 SetError(kErrorAdapterNotInitialized); |
161 return false; | 161 return false; |
162 } | 162 } |
163 | 163 |
164 return true; | 164 return true; |
165 } | 165 } |
166 | 166 |
167 bool BluetoothLowEnergyConnectFunction::DoWork() { | 167 bool BluetoothLowEnergyConnectFunction::DoWork() { |
168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 168 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
169 | 169 |
170 BluetoothLowEnergyEventRouter* event_router = | 170 BluetoothLowEnergyEventRouter* event_router = |
171 GetEventRouter(browser_context()); | 171 GetEventRouter(browser_context()); |
172 | 172 |
173 // The adapter must be initialized at this point, but return an error instead | 173 // The adapter must be initialized at this point, but return an error instead |
174 // of asserting. | 174 // of asserting. |
175 if (!event_router->HasAdapter()) { | 175 if (!event_router->HasAdapter()) { |
176 SetError(kErrorAdapterNotInitialized); | 176 SetError(kErrorAdapterNotInitialized); |
177 SendResponse(false); | 177 SendResponse(false); |
178 return false; | 178 return false; |
(...skipping 22 matching lines...) Expand all Loading... |
201 SendResponse(true); | 201 SendResponse(true); |
202 } | 202 } |
203 | 203 |
204 void BluetoothLowEnergyConnectFunction::ErrorCallback( | 204 void BluetoothLowEnergyConnectFunction::ErrorCallback( |
205 BluetoothLowEnergyEventRouter::Status status) { | 205 BluetoothLowEnergyEventRouter::Status status) { |
206 SetError(StatusToString(status)); | 206 SetError(StatusToString(status)); |
207 SendResponse(false); | 207 SendResponse(false); |
208 } | 208 } |
209 | 209 |
210 bool BluetoothLowEnergyDisconnectFunction::DoWork() { | 210 bool BluetoothLowEnergyDisconnectFunction::DoWork() { |
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 211 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
212 | 212 |
213 BluetoothLowEnergyEventRouter* event_router = | 213 BluetoothLowEnergyEventRouter* event_router = |
214 GetEventRouter(browser_context()); | 214 GetEventRouter(browser_context()); |
215 | 215 |
216 // The adapter must be initialized at this point, but return an error instead | 216 // The adapter must be initialized at this point, but return an error instead |
217 // of asserting. | 217 // of asserting. |
218 if (!event_router->HasAdapter()) { | 218 if (!event_router->HasAdapter()) { |
219 SetError(kErrorAdapterNotInitialized); | 219 SetError(kErrorAdapterNotInitialized); |
220 SendResponse(false); | 220 SendResponse(false); |
221 return false; | 221 return false; |
(...skipping 16 matching lines...) Expand all Loading... |
238 SendResponse(true); | 238 SendResponse(true); |
239 } | 239 } |
240 | 240 |
241 void BluetoothLowEnergyDisconnectFunction::ErrorCallback( | 241 void BluetoothLowEnergyDisconnectFunction::ErrorCallback( |
242 BluetoothLowEnergyEventRouter::Status status) { | 242 BluetoothLowEnergyEventRouter::Status status) { |
243 SetError(StatusToString(status)); | 243 SetError(StatusToString(status)); |
244 SendResponse(false); | 244 SendResponse(false); |
245 } | 245 } |
246 | 246 |
247 bool BluetoothLowEnergyGetServiceFunction::DoWork() { | 247 bool BluetoothLowEnergyGetServiceFunction::DoWork() { |
248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 248 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
249 | 249 |
250 BluetoothLowEnergyEventRouter* event_router = | 250 BluetoothLowEnergyEventRouter* event_router = |
251 GetEventRouter(browser_context()); | 251 GetEventRouter(browser_context()); |
252 | 252 |
253 // The adapter must be initialized at this point, but return an error instead | 253 // The adapter must be initialized at this point, but return an error instead |
254 // of asserting. | 254 // of asserting. |
255 if (!event_router->HasAdapter()) { | 255 if (!event_router->HasAdapter()) { |
256 SetError(kErrorAdapterNotInitialized); | 256 SetError(kErrorAdapterNotInitialized); |
257 SendResponse(false); | 257 SendResponse(false); |
258 return false; | 258 return false; |
(...skipping 12 matching lines...) Expand all Loading... |
271 return false; | 271 return false; |
272 } | 272 } |
273 | 273 |
274 results_ = apibtle::GetService::Results::Create(service); | 274 results_ = apibtle::GetService::Results::Create(service); |
275 SendResponse(true); | 275 SendResponse(true); |
276 | 276 |
277 return true; | 277 return true; |
278 } | 278 } |
279 | 279 |
280 bool BluetoothLowEnergyGetServicesFunction::DoWork() { | 280 bool BluetoothLowEnergyGetServicesFunction::DoWork() { |
281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 281 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
282 | 282 |
283 BluetoothLowEnergyEventRouter* event_router = | 283 BluetoothLowEnergyEventRouter* event_router = |
284 GetEventRouter(browser_context()); | 284 GetEventRouter(browser_context()); |
285 | 285 |
286 // The adapter must be initialized at this point, but return an error instead | 286 // The adapter must be initialized at this point, but return an error instead |
287 // of asserting. | 287 // of asserting. |
288 if (!event_router->HasAdapter()) { | 288 if (!event_router->HasAdapter()) { |
289 SetError(kErrorAdapterNotInitialized); | 289 SetError(kErrorAdapterNotInitialized); |
290 SendResponse(false); | 290 SendResponse(false); |
291 return false; | 291 return false; |
(...skipping 10 matching lines...) Expand all Loading... |
302 return false; | 302 return false; |
303 } | 303 } |
304 | 304 |
305 results_ = apibtle::GetServices::Results::Create(service_list); | 305 results_ = apibtle::GetServices::Results::Create(service_list); |
306 SendResponse(true); | 306 SendResponse(true); |
307 | 307 |
308 return true; | 308 return true; |
309 } | 309 } |
310 | 310 |
311 bool BluetoothLowEnergyGetCharacteristicFunction::DoWork() { | 311 bool BluetoothLowEnergyGetCharacteristicFunction::DoWork() { |
312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 312 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
313 | 313 |
314 BluetoothLowEnergyEventRouter* event_router = | 314 BluetoothLowEnergyEventRouter* event_router = |
315 GetEventRouter(browser_context()); | 315 GetEventRouter(browser_context()); |
316 | 316 |
317 // The adapter must be initialized at this point, but return an error instead | 317 // The adapter must be initialized at this point, but return an error instead |
318 // of asserting. | 318 // of asserting. |
319 if (!event_router->HasAdapter()) { | 319 if (!event_router->HasAdapter()) { |
320 SetError(kErrorAdapterNotInitialized); | 320 SetError(kErrorAdapterNotInitialized); |
321 SendResponse(false); | 321 SendResponse(false); |
322 return false; | 322 return false; |
(...skipping 16 matching lines...) Expand all Loading... |
339 // Manually construct the result instead of using | 339 // Manually construct the result instead of using |
340 // apibtle::GetCharacteristic::Result::Create as it doesn't convert lists of | 340 // apibtle::GetCharacteristic::Result::Create as it doesn't convert lists of |
341 // enums correctly. | 341 // enums correctly. |
342 SetResult(apibtle::CharacteristicToValue(&characteristic).release()); | 342 SetResult(apibtle::CharacteristicToValue(&characteristic).release()); |
343 SendResponse(true); | 343 SendResponse(true); |
344 | 344 |
345 return true; | 345 return true; |
346 } | 346 } |
347 | 347 |
348 bool BluetoothLowEnergyGetCharacteristicsFunction::DoWork() { | 348 bool BluetoothLowEnergyGetCharacteristicsFunction::DoWork() { |
349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 349 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
350 | 350 |
351 BluetoothLowEnergyEventRouter* event_router = | 351 BluetoothLowEnergyEventRouter* event_router = |
352 GetEventRouter(browser_context()); | 352 GetEventRouter(browser_context()); |
353 | 353 |
354 // The adapter must be initialized at this point, but return an error instead | 354 // The adapter must be initialized at this point, but return an error instead |
355 // of asserting. | 355 // of asserting. |
356 if (!event_router->HasAdapter()) { | 356 if (!event_router->HasAdapter()) { |
357 SetError(kErrorAdapterNotInitialized); | 357 SetError(kErrorAdapterNotInitialized); |
358 SendResponse(false); | 358 SendResponse(false); |
359 return false; | 359 return false; |
(...skipping 23 matching lines...) Expand all Loading... |
383 ++iter) | 383 ++iter) |
384 result->Append(apibtle::CharacteristicToValue(iter->get()).release()); | 384 result->Append(apibtle::CharacteristicToValue(iter->get()).release()); |
385 | 385 |
386 SetResult(result.release()); | 386 SetResult(result.release()); |
387 SendResponse(true); | 387 SendResponse(true); |
388 | 388 |
389 return true; | 389 return true; |
390 } | 390 } |
391 | 391 |
392 bool BluetoothLowEnergyGetIncludedServicesFunction::DoWork() { | 392 bool BluetoothLowEnergyGetIncludedServicesFunction::DoWork() { |
393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 393 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
394 | 394 |
395 BluetoothLowEnergyEventRouter* event_router = | 395 BluetoothLowEnergyEventRouter* event_router = |
396 GetEventRouter(browser_context()); | 396 GetEventRouter(browser_context()); |
397 | 397 |
398 // The adapter must be initialized at this point, but return an error instead | 398 // The adapter must be initialized at this point, but return an error instead |
399 // of asserting. | 399 // of asserting. |
400 if (!event_router->HasAdapter()) { | 400 if (!event_router->HasAdapter()) { |
401 SetError(kErrorAdapterNotInitialized); | 401 SetError(kErrorAdapterNotInitialized); |
402 SendResponse(false); | 402 SendResponse(false); |
403 return false; | 403 return false; |
(...skipping 12 matching lines...) Expand all Loading... |
416 return false; | 416 return false; |
417 } | 417 } |
418 | 418 |
419 results_ = apibtle::GetIncludedServices::Results::Create(service_list); | 419 results_ = apibtle::GetIncludedServices::Results::Create(service_list); |
420 SendResponse(true); | 420 SendResponse(true); |
421 | 421 |
422 return true; | 422 return true; |
423 } | 423 } |
424 | 424 |
425 bool BluetoothLowEnergyGetDescriptorFunction::DoWork() { | 425 bool BluetoothLowEnergyGetDescriptorFunction::DoWork() { |
426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 426 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
427 | 427 |
428 BluetoothLowEnergyEventRouter* event_router = | 428 BluetoothLowEnergyEventRouter* event_router = |
429 GetEventRouter(browser_context()); | 429 GetEventRouter(browser_context()); |
430 | 430 |
431 // The adapter must be initialized at this point, but return an error instead | 431 // The adapter must be initialized at this point, but return an error instead |
432 // of asserting. | 432 // of asserting. |
433 if (!event_router->HasAdapter()) { | 433 if (!event_router->HasAdapter()) { |
434 SetError(kErrorAdapterNotInitialized); | 434 SetError(kErrorAdapterNotInitialized); |
435 SendResponse(false); | 435 SendResponse(false); |
436 return false; | 436 return false; |
(...skipping 15 matching lines...) Expand all Loading... |
452 // Manually construct the result instead of using | 452 // Manually construct the result instead of using |
453 // apibtle::GetDescriptor::Result::Create as it doesn't convert lists of enums | 453 // apibtle::GetDescriptor::Result::Create as it doesn't convert lists of enums |
454 // correctly. | 454 // correctly. |
455 SetResult(apibtle::DescriptorToValue(&descriptor).release()); | 455 SetResult(apibtle::DescriptorToValue(&descriptor).release()); |
456 SendResponse(true); | 456 SendResponse(true); |
457 | 457 |
458 return true; | 458 return true; |
459 } | 459 } |
460 | 460 |
461 bool BluetoothLowEnergyGetDescriptorsFunction::DoWork() { | 461 bool BluetoothLowEnergyGetDescriptorsFunction::DoWork() { |
462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 462 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
463 | 463 |
464 BluetoothLowEnergyEventRouter* event_router = | 464 BluetoothLowEnergyEventRouter* event_router = |
465 GetEventRouter(browser_context()); | 465 GetEventRouter(browser_context()); |
466 | 466 |
467 // The adapter must be initialized at this point, but return an error instead | 467 // The adapter must be initialized at this point, but return an error instead |
468 // of asserting. | 468 // of asserting. |
469 if (!event_router->HasAdapter()) { | 469 if (!event_router->HasAdapter()) { |
470 SetError(kErrorAdapterNotInitialized); | 470 SetError(kErrorAdapterNotInitialized); |
471 SendResponse(false); | 471 SendResponse(false); |
472 return false; | 472 return false; |
(...skipping 22 matching lines...) Expand all Loading... |
495 ++iter) | 495 ++iter) |
496 result->Append(apibtle::DescriptorToValue(iter->get()).release()); | 496 result->Append(apibtle::DescriptorToValue(iter->get()).release()); |
497 | 497 |
498 SetResult(result.release()); | 498 SetResult(result.release()); |
499 SendResponse(true); | 499 SendResponse(true); |
500 | 500 |
501 return true; | 501 return true; |
502 } | 502 } |
503 | 503 |
504 bool BluetoothLowEnergyReadCharacteristicValueFunction::DoWork() { | 504 bool BluetoothLowEnergyReadCharacteristicValueFunction::DoWork() { |
505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 505 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
506 | 506 |
507 BluetoothLowEnergyEventRouter* event_router = | 507 BluetoothLowEnergyEventRouter* event_router = |
508 GetEventRouter(browser_context()); | 508 GetEventRouter(browser_context()); |
509 | 509 |
510 // The adapter must be initialized at this point, but return an error instead | 510 // The adapter must be initialized at this point, but return an error instead |
511 // of asserting. | 511 // of asserting. |
512 if (!event_router->HasAdapter()) { | 512 if (!event_router->HasAdapter()) { |
513 SetError(kErrorAdapterNotInitialized); | 513 SetError(kErrorAdapterNotInitialized); |
514 SendResponse(false); | 514 SendResponse(false); |
515 return false; | 515 return false; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 SendResponse(true); | 553 SendResponse(true); |
554 } | 554 } |
555 | 555 |
556 void BluetoothLowEnergyReadCharacteristicValueFunction::ErrorCallback( | 556 void BluetoothLowEnergyReadCharacteristicValueFunction::ErrorCallback( |
557 BluetoothLowEnergyEventRouter::Status status) { | 557 BluetoothLowEnergyEventRouter::Status status) { |
558 SetError(StatusToString(status)); | 558 SetError(StatusToString(status)); |
559 SendResponse(false); | 559 SendResponse(false); |
560 } | 560 } |
561 | 561 |
562 bool BluetoothLowEnergyWriteCharacteristicValueFunction::DoWork() { | 562 bool BluetoothLowEnergyWriteCharacteristicValueFunction::DoWork() { |
563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 563 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
564 | 564 |
565 BluetoothLowEnergyEventRouter* event_router = | 565 BluetoothLowEnergyEventRouter* event_router = |
566 GetEventRouter(browser_context()); | 566 GetEventRouter(browser_context()); |
567 | 567 |
568 // The adapter must be initialized at this point, but return an error instead | 568 // The adapter must be initialized at this point, but return an error instead |
569 // of asserting. | 569 // of asserting. |
570 if (!event_router->HasAdapter()) { | 570 if (!event_router->HasAdapter()) { |
571 SetError(kErrorAdapterNotInitialized); | 571 SetError(kErrorAdapterNotInitialized); |
572 SendResponse(false); | 572 SendResponse(false); |
573 return false; | 573 return false; |
(...skipping 23 matching lines...) Expand all Loading... |
597 SendResponse(true); | 597 SendResponse(true); |
598 } | 598 } |
599 | 599 |
600 void BluetoothLowEnergyWriteCharacteristicValueFunction::ErrorCallback( | 600 void BluetoothLowEnergyWriteCharacteristicValueFunction::ErrorCallback( |
601 BluetoothLowEnergyEventRouter::Status status) { | 601 BluetoothLowEnergyEventRouter::Status status) { |
602 SetError(StatusToString(status)); | 602 SetError(StatusToString(status)); |
603 SendResponse(false); | 603 SendResponse(false); |
604 } | 604 } |
605 | 605 |
606 bool BluetoothLowEnergyStartCharacteristicNotificationsFunction::DoWork() { | 606 bool BluetoothLowEnergyStartCharacteristicNotificationsFunction::DoWork() { |
607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 607 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
608 | 608 |
609 BluetoothLowEnergyEventRouter* event_router = | 609 BluetoothLowEnergyEventRouter* event_router = |
610 GetEventRouter(browser_context()); | 610 GetEventRouter(browser_context()); |
611 | 611 |
612 // The adapter must be initialized at this point, but return an error instead | 612 // The adapter must be initialized at this point, but return an error instead |
613 // of asserting. | 613 // of asserting. |
614 if (!event_router->HasAdapter()) { | 614 if (!event_router->HasAdapter()) { |
615 SetError(kErrorAdapterNotInitialized); | 615 SetError(kErrorAdapterNotInitialized); |
616 SendResponse(false); | 616 SendResponse(false); |
617 return false; | 617 return false; |
(...skipping 27 matching lines...) Expand all Loading... |
645 SendResponse(true); | 645 SendResponse(true); |
646 } | 646 } |
647 | 647 |
648 void BluetoothLowEnergyStartCharacteristicNotificationsFunction::ErrorCallback( | 648 void BluetoothLowEnergyStartCharacteristicNotificationsFunction::ErrorCallback( |
649 BluetoothLowEnergyEventRouter::Status status) { | 649 BluetoothLowEnergyEventRouter::Status status) { |
650 SetError(StatusToString(status)); | 650 SetError(StatusToString(status)); |
651 SendResponse(false); | 651 SendResponse(false); |
652 } | 652 } |
653 | 653 |
654 bool BluetoothLowEnergyStopCharacteristicNotificationsFunction::DoWork() { | 654 bool BluetoothLowEnergyStopCharacteristicNotificationsFunction::DoWork() { |
655 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 655 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
656 | 656 |
657 BluetoothLowEnergyEventRouter* event_router = | 657 BluetoothLowEnergyEventRouter* event_router = |
658 GetEventRouter(browser_context()); | 658 GetEventRouter(browser_context()); |
659 | 659 |
660 // The adapter must be initialized at this point, but return an error instead | 660 // The adapter must be initialized at this point, but return an error instead |
661 // of asserting. | 661 // of asserting. |
662 if (!event_router->HasAdapter()) { | 662 if (!event_router->HasAdapter()) { |
663 SetError(kErrorAdapterNotInitialized); | 663 SetError(kErrorAdapterNotInitialized); |
664 SendResponse(false); | 664 SendResponse(false); |
665 return false; | 665 return false; |
(...skipping 21 matching lines...) Expand all Loading... |
687 SendResponse(true); | 687 SendResponse(true); |
688 } | 688 } |
689 | 689 |
690 void BluetoothLowEnergyStopCharacteristicNotificationsFunction::ErrorCallback( | 690 void BluetoothLowEnergyStopCharacteristicNotificationsFunction::ErrorCallback( |
691 BluetoothLowEnergyEventRouter::Status status) { | 691 BluetoothLowEnergyEventRouter::Status status) { |
692 SetError(StatusToString(status)); | 692 SetError(StatusToString(status)); |
693 SendResponse(false); | 693 SendResponse(false); |
694 } | 694 } |
695 | 695 |
696 bool BluetoothLowEnergyReadDescriptorValueFunction::DoWork() { | 696 bool BluetoothLowEnergyReadDescriptorValueFunction::DoWork() { |
697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 697 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
698 | 698 |
699 BluetoothLowEnergyEventRouter* event_router = | 699 BluetoothLowEnergyEventRouter* event_router = |
700 GetEventRouter(browser_context()); | 700 GetEventRouter(browser_context()); |
701 | 701 |
702 // The adapter must be initialized at this point, but return an error instead | 702 // The adapter must be initialized at this point, but return an error instead |
703 // of asserting. | 703 // of asserting. |
704 if (!event_router->HasAdapter()) { | 704 if (!event_router->HasAdapter()) { |
705 SetError(kErrorAdapterNotInitialized); | 705 SetError(kErrorAdapterNotInitialized); |
706 SendResponse(false); | 706 SendResponse(false); |
707 return false; | 707 return false; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 SendResponse(true); | 744 SendResponse(true); |
745 } | 745 } |
746 | 746 |
747 void BluetoothLowEnergyReadDescriptorValueFunction::ErrorCallback( | 747 void BluetoothLowEnergyReadDescriptorValueFunction::ErrorCallback( |
748 BluetoothLowEnergyEventRouter::Status status) { | 748 BluetoothLowEnergyEventRouter::Status status) { |
749 SetError(StatusToString(status)); | 749 SetError(StatusToString(status)); |
750 SendResponse(false); | 750 SendResponse(false); |
751 } | 751 } |
752 | 752 |
753 bool BluetoothLowEnergyWriteDescriptorValueFunction::DoWork() { | 753 bool BluetoothLowEnergyWriteDescriptorValueFunction::DoWork() { |
754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 754 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
755 | 755 |
756 BluetoothLowEnergyEventRouter* event_router = | 756 BluetoothLowEnergyEventRouter* event_router = |
757 GetEventRouter(browser_context()); | 757 GetEventRouter(browser_context()); |
758 | 758 |
759 // The adapter must be initialized at this point, but return an error instead | 759 // The adapter must be initialized at this point, but return an error instead |
760 // of asserting. | 760 // of asserting. |
761 if (!event_router->HasAdapter()) { | 761 if (!event_router->HasAdapter()) { |
762 SetError(kErrorAdapterNotInitialized); | 762 SetError(kErrorAdapterNotInitialized); |
763 SendResponse(false); | 763 SendResponse(false); |
764 return false; | 764 return false; |
(...skipping 23 matching lines...) Expand all Loading... |
788 } | 788 } |
789 | 789 |
790 void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback( | 790 void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback( |
791 BluetoothLowEnergyEventRouter::Status status) { | 791 BluetoothLowEnergyEventRouter::Status status) { |
792 SetError(StatusToString(status)); | 792 SetError(StatusToString(status)); |
793 SendResponse(false); | 793 SendResponse(false); |
794 } | 794 } |
795 | 795 |
796 } // namespace core_api | 796 } // namespace core_api |
797 } // namespace extensions | 797 } // namespace extensions |
OLD | NEW |