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

Side by Side Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc

Issue 325893002: Bluetooth: add socket & low_energy manifest check (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add permission denied tests Created 6 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.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 "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h" 5 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_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 "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h" 10 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h"
11 #include "chrome/browser/extensions/api/bluetooth_low_energy/utils.h" 11 #include "chrome/browser/extensions/api/bluetooth_low_energy/utils.h"
12 #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h"
12 #include "chrome/common/extensions/api/bluetooth_low_energy.h" 13 #include "chrome/common/extensions/api/bluetooth_low_energy.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "extensions/browser/event_router.h" 15 #include "extensions/browser/event_router.h"
16 #include "extensions/common/permissions/permissions_data.h"
15 17
16 using content::BrowserContext; 18 using content::BrowserContext;
17 using content::BrowserThread; 19 using content::BrowserThread;
18 20
19 namespace apibtle = extensions::api::bluetooth_low_energy; 21 namespace apibtle = extensions::api::bluetooth_low_energy;
20 22
21 namespace { 23 namespace {
22 24
23 const char kErrorAdapterNotInitialized[] = 25 const char kErrorAdapterNotInitialized[] =
24 "Could not initialize Bluetooth adapter."; 26 "Could not initialize Bluetooth adapter.";
25 const char kErrorCharacteristicNotFoundFormat[] = 27 const char kErrorCharacteristicNotFoundFormat[] =
26 "Characteristic with ID \"%s\" not found."; 28 "Characteristic with ID \"%s\" not found.";
27 const char kErrorDescriptorNotFoundFormat[] = 29 const char kErrorDescriptorNotFoundFormat[] =
28 "Descriptor with ID \"%s\" not found."; 30 "Descriptor with ID \"%s\" not found.";
29 const char kErrorDeviceNotFoundFormat[] = 31 const char kErrorDeviceNotFoundFormat[] =
30 "Device with address \"%s\" not found."; 32 "Device with address \"%s\" not found.";
31 const char kErrorReadCharacteristicValueFailedFormat[] = 33 const char kErrorReadCharacteristicValueFailedFormat[] =
32 "Failed to read value of characteristic with ID \"%s\"."; 34 "Failed to read value of characteristic with ID \"%s\".";
33 const char kErrorReadDescriptorValueFailedFormat[] = 35 const char kErrorReadDescriptorValueFailedFormat[] =
34 "Failed to read value of descriptor with ID \"%s\"."; 36 "Failed to read value of descriptor with ID \"%s\".";
35 const char kErrorServiceNotFoundFormat[] = "Service with ID \"%s\" not found."; 37 const char kErrorServiceNotFoundFormat[] = "Service with ID \"%s\" not found.";
36 const char kErrorPlatformNotSupported[] = 38 const char kErrorPlatformNotSupported[] =
37 "This operation is not supported on the current platform"; 39 "This operation is not supported on the current platform";
38 const char kErrorWriteCharacteristicValueFailedFormat[] = 40 const char kErrorWriteCharacteristicValueFailedFormat[] =
39 "Failed to write value of characteristic with ID \"%s\"."; 41 "Failed to write value of characteristic with ID \"%s\".";
40 const char kErrorWriteDescriptorValueFailedFormat[] = 42 const char kErrorWriteDescriptorValueFailedFormat[] =
41 "Failed to write value of descriptor with ID \"%s\"."; 43 "Failed to write value of descriptor with ID \"%s\".";
44 const char kErrorPermissionDenied[] = "Permission denied";
42 45
43 extensions::BluetoothLowEnergyEventRouter* GetEventRouter( 46 extensions::BluetoothLowEnergyEventRouter* GetEventRouter(
44 BrowserContext* context) { 47 BrowserContext* context) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
46 return extensions::BluetoothLowEnergyAPI::Get(context)->event_router(); 49 return extensions::BluetoothLowEnergyAPI::Get(context)->event_router();
47 } 50 }
48 51
49 void DoWorkCallback(const base::Callback<bool()>& callback) { 52 void DoWorkCallback(const base::Callback<bool()>& callback) {
50 DCHECK(!callback.is_null()); 53 DCHECK(!callback.is_null());
51 callback.Run(); 54 callback.Run();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 90
88 BluetoothLowEnergyExtensionFunction::BluetoothLowEnergyExtensionFunction() { 91 BluetoothLowEnergyExtensionFunction::BluetoothLowEnergyExtensionFunction() {
89 } 92 }
90 93
91 BluetoothLowEnergyExtensionFunction::~BluetoothLowEnergyExtensionFunction() { 94 BluetoothLowEnergyExtensionFunction::~BluetoothLowEnergyExtensionFunction() {
92 } 95 }
93 96
94 bool BluetoothLowEnergyExtensionFunction::RunAsync() { 97 bool BluetoothLowEnergyExtensionFunction::RunAsync() {
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
96 99
100 if (!BluetoothManifestData::CheckLowEnergyPermitted(GetExtension())) {
101 error_ = kErrorPermissionDenied;
102 return false;
103 }
104
97 BluetoothLowEnergyEventRouter* event_router = 105 BluetoothLowEnergyEventRouter* event_router =
98 GetEventRouter(browser_context()); 106 GetEventRouter(browser_context());
99 if (!event_router->IsBluetoothSupported()) { 107 if (!event_router->IsBluetoothSupported()) {
100 SetError(kErrorPlatformNotSupported); 108 SetError(kErrorPlatformNotSupported);
101 return false; 109 return false;
102 } 110 }
103 111
104 // It is safe to pass |this| here as ExtensionFunction is refcounted. 112 // It is safe to pass |this| here as ExtensionFunction is refcounted.
105 if (!event_router->InitializeAdapterAndInvokeCallback(base::Bind( 113 if (!event_router->InitializeAdapterAndInvokeCallback(base::Bind(
106 &DoWorkCallback, 114 &DoWorkCallback,
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 } 604 }
597 605
598 void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback() { 606 void BluetoothLowEnergyWriteDescriptorValueFunction::ErrorCallback() {
599 SetError(base::StringPrintf(kErrorWriteDescriptorValueFailedFormat, 607 SetError(base::StringPrintf(kErrorWriteDescriptorValueFailedFormat,
600 instance_id_.c_str())); 608 instance_id_.c_str()));
601 SendResponse(false); 609 SendResponse(false);
602 } 610 }
603 611
604 } // namespace api 612 } // namespace api
605 } // namespace extensions 613 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698