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

Side by Side Diff: extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc

Issue 1201063002: Set up the infrastructure for Extension event metrics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaaaaase Created 5 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
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_low_energy/bluetooth_low_energy_event _router.h" 5 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event _router.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 DCHECK(device->GetAddress() == 859 DCHECK(device->GetAddress() ==
860 service_id_to_device_address_[service->GetIdentifier()]); 860 service_id_to_device_address_[service->GetIdentifier()]);
861 service_id_to_device_address_.erase(service->GetIdentifier()); 861 service_id_to_device_address_.erase(service->GetIdentifier());
862 862
863 // Signal API event. 863 // Signal API event.
864 apibtle::Service api_service; 864 apibtle::Service api_service;
865 PopulateService(service, &api_service); 865 PopulateService(service, &api_service);
866 866
867 scoped_ptr<base::ListValue> args = 867 scoped_ptr<base::ListValue> args =
868 apibtle::OnServiceRemoved::Create(api_service); 868 apibtle::OnServiceRemoved::Create(api_service);
869 scoped_ptr<Event> event( 869 scoped_ptr<Event> event(new Event(
870 new Event(apibtle::OnServiceRemoved::kEventName, args.Pass())); 870 events::UNKNOWN, apibtle::OnServiceRemoved::kEventName, args.Pass()));
871 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); 871 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass());
872 } 872 }
873 873
874 void BluetoothLowEnergyEventRouter::GattDiscoveryCompleteForService( 874 void BluetoothLowEnergyEventRouter::GattDiscoveryCompleteForService(
875 BluetoothAdapter* adapter, 875 BluetoothAdapter* adapter,
876 BluetoothGattService* service) { 876 BluetoothGattService* service) {
877 DCHECK_CURRENTLY_ON(BrowserThread::UI); 877 DCHECK_CURRENTLY_ON(BrowserThread::UI);
878 DCHECK_EQ(adapter, adapter_.get()); 878 DCHECK_EQ(adapter, adapter_.get());
879 VLOG(2) << "GATT service discovery complete: " << service->GetIdentifier(); 879 VLOG(2) << "GATT service discovery complete: " << service->GetIdentifier();
880 880
881 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != 881 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) !=
882 service_id_to_device_address_.end()); 882 service_id_to_device_address_.end());
883 883
884 // Signal the service added event here. 884 // Signal the service added event here.
885 apibtle::Service api_service; 885 apibtle::Service api_service;
886 PopulateService(service, &api_service); 886 PopulateService(service, &api_service);
887 887
888 scoped_ptr<base::ListValue> args = 888 scoped_ptr<base::ListValue> args =
889 apibtle::OnServiceAdded::Create(api_service); 889 apibtle::OnServiceAdded::Create(api_service);
890 scoped_ptr<Event> event( 890 scoped_ptr<Event> event(new Event(
891 new Event(apibtle::OnServiceAdded::kEventName, args.Pass())); 891 events::UNKNOWN, apibtle::OnServiceAdded::kEventName, args.Pass()));
892 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); 892 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass());
893 } 893 }
894 894
895 void BluetoothLowEnergyEventRouter::GattServiceChanged( 895 void BluetoothLowEnergyEventRouter::GattServiceChanged(
896 BluetoothAdapter* adapter, 896 BluetoothAdapter* adapter,
897 BluetoothGattService* service) { 897 BluetoothGattService* service) {
898 DCHECK_CURRENTLY_ON(BrowserThread::UI); 898 DCHECK_CURRENTLY_ON(BrowserThread::UI);
899 DCHECK_EQ(adapter, adapter_.get()); 899 DCHECK_EQ(adapter, adapter_.get());
900 VLOG(2) << "GATT service changed: " << service->GetIdentifier(); 900 VLOG(2) << "GATT service changed: " << service->GetIdentifier();
901 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != 901 DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) !=
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 // If |event_name| is "onCharacteristicValueChanged", then send the 1153 // If |event_name| is "onCharacteristicValueChanged", then send the
1154 // event only if the extension has requested notifications from the 1154 // event only if the extension has requested notifications from the
1155 // related characteristic. 1155 // related characteristic.
1156 if (event_name == apibtle::OnCharacteristicValueChanged::kEventName && 1156 if (event_name == apibtle::OnCharacteristicValueChanged::kEventName &&
1157 !characteristic_id.empty() && 1157 !characteristic_id.empty() &&
1158 !FindNotifySession(extension_id, characteristic_id)) 1158 !FindNotifySession(extension_id, characteristic_id))
1159 continue; 1159 continue;
1160 1160
1161 // Send the event. 1161 // Send the event.
1162 scoped_ptr<base::ListValue> args_copy(args->DeepCopy()); 1162 scoped_ptr<base::ListValue> args_copy(args->DeepCopy());
1163 scoped_ptr<Event> event(new Event(event_name, args_copy.Pass())); 1163 scoped_ptr<Event> event(
1164 new Event(events::UNKNOWN, event_name, args_copy.Pass()));
1164 EventRouter::Get(browser_context_)->DispatchEventToExtension( 1165 EventRouter::Get(browser_context_)->DispatchEventToExtension(
1165 extension_id, event.Pass()); 1166 extension_id, event.Pass());
1166 } 1167 }
1167 } 1168 }
1168 1169
1169 BluetoothGattService* BluetoothLowEnergyEventRouter::FindServiceById( 1170 BluetoothGattService* BluetoothLowEnergyEventRouter::FindServiceById(
1170 const std::string& instance_id) const { 1171 const std::string& instance_id) const {
1171 InstanceIdMap::const_iterator iter = 1172 InstanceIdMap::const_iterator iter =
1172 service_id_to_device_address_.find(instance_id); 1173 service_id_to_device_address_.find(instance_id);
1173 if (iter == service_id_to_device_address_.end()) { 1174 if (iter == service_id_to_device_address_.end()) {
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 continue; 1489 continue;
1489 1490
1490 manager->Remove(extension_id, *iter); 1491 manager->Remove(extension_id, *iter);
1491 return true; 1492 return true;
1492 } 1493 }
1493 1494
1494 return false; 1495 return false;
1495 } 1496 }
1496 1497
1497 } // namespace extensions 1498 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698