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

Side by Side Diff: components/proximity_auth/ble/proximity_auth_ble_system.cc

Issue 1251843002: Using WireMessage instead of FakeWireMessage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing notification issue Created 5 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/proximity_auth/ble/proximity_auth_ble_system.h" 5 #include "components/proximity_auth/ble/proximity_auth_ble_system.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "base/time/default_tick_clock.h" 14 #include "base/time/default_tick_clock.h"
15 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" 15 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h"
16 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h " 16 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h "
17 #include "components/proximity_auth/ble/bluetooth_low_energy_device_whitelist.h" 17 #include "components/proximity_auth/ble/bluetooth_low_energy_device_whitelist.h"
18 #include "components/proximity_auth/ble/fake_wire_message.h" 18 #include "components/proximity_auth/ble/fake_wire_message.h"
19 #include "components/proximity_auth/bluetooth_throttler_impl.h" 19 #include "components/proximity_auth/bluetooth_throttler_impl.h"
20 #include "components/proximity_auth/connection.h" 20 #include "components/proximity_auth/connection.h"
21 #include "components/proximity_auth/cryptauth/base64url.h" 21 #include "components/proximity_auth/cryptauth/base64url.h"
22 #include "components/proximity_auth/cryptauth/cryptauth_client.h" 22 #include "components/proximity_auth/cryptauth/cryptauth_client.h"
23 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" 23 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h"
24 #include "components/proximity_auth/logging/logging.h" 24 #include "components/proximity_auth/logging/logging.h"
25 #include "components/proximity_auth/proximity_auth_client.h" 25 #include "components/proximity_auth/proximity_auth_client.h"
26 #include "components/proximity_auth/remote_device.h" 26 #include "components/proximity_auth/remote_device.h"
27 #include "components/proximity_auth/wire_message.h"
27 #include "device/bluetooth/bluetooth_device.h" 28 #include "device/bluetooth/bluetooth_device.h"
28 #include "device/bluetooth/bluetooth_gatt_connection.h" 29 #include "device/bluetooth/bluetooth_gatt_connection.h"
29 30
30 namespace proximity_auth { 31 namespace proximity_auth {
31 32
32 namespace { 33 namespace {
33 34
34 // The UUID of the Bluetooth Low Energy service. 35 // The UUID of the Bluetooth Low Energy service.
35 const char kSmartLockServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; 36 const char kSmartLockServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11";
36 37
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 connection_.reset(); 236 connection_.reset();
236 connection_finder_.reset(); 237 connection_finder_.reset();
237 } 238 }
238 239
239 void ProximityAuthBleSystem::OnFocusedUserChanged(const std::string& user_id) { 240 void ProximityAuthBleSystem::OnFocusedUserChanged(const std::string& user_id) {
240 PA_LOG(INFO) << "OnFocusedUserChanged: " << user_id; 241 PA_LOG(INFO) << "OnFocusedUserChanged: " << user_id;
241 } 242 }
242 243
243 void ProximityAuthBleSystem::OnMessageReceived(const Connection& connection, 244 void ProximityAuthBleSystem::OnMessageReceived(const Connection& connection,
244 const WireMessage& message) { 245 const WireMessage& message) {
245 // TODO(sacomoto): change this when WireMessage is fully implemented. 246 PA_LOG(INFO) << "Message with " << message.payload().size()
246 PA_LOG(INFO) << "Message received: " << message.payload(); 247 << " bytes received.";
247 248
248 // The first message should contain a public key registered in |unlock_keys_| 249 // The first message should contain a public key registered in |unlock_keys_|
249 // to authenticate the device. 250 // to authenticate the device.
250 if (!device_authenticated_) { 251 if (!device_authenticated_) {
251 std::string out_public_key; 252 std::string out_public_key;
252 if (HasUnlockKey(message.payload(), &out_public_key)) { 253 if (HasUnlockKey(message.payload(), &out_public_key)) {
253 PA_LOG(INFO) << "Device authenticated. Adding " 254 PA_LOG(INFO) << "Device authenticated. Adding "
254 << connection_->remote_device().bluetooth_address << ", " 255 << connection_->remote_device().bluetooth_address << ", "
255 << out_public_key << " to whitelist."; 256 << out_public_key << " to whitelist.";
256 device_whitelist_->AddOrUpdateDevice( 257 device_whitelist_->AddOrUpdateDevice(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 void ProximityAuthBleSystem::StartPollingScreenState() { 337 void ProximityAuthBleSystem::StartPollingScreenState() {
337 PA_LOG(INFO) << "Polling screen state."; 338 PA_LOG(INFO) << "Polling screen state.";
338 if (is_polling_screen_state_) { 339 if (is_polling_screen_state_) {
339 if (!connection_ || !connection_->IsConnected()) { 340 if (!connection_ || !connection_->IsConnected()) {
340 PA_LOG(INFO) << "Polling stopped."; 341 PA_LOG(INFO) << "Polling stopped.";
341 is_polling_screen_state_ = false; 342 is_polling_screen_state_ = false;
342 return; 343 return;
343 } 344 }
344 // Sends message requesting screen state. 345 // Sends message requesting screen state.
345 connection_->SendMessage( 346 connection_->SendMessage(
346 make_scoped_ptr(new FakeWireMessage(kPollScreenState))); 347 make_scoped_ptr(new WireMessage(kPollScreenState)));
347 348
348 // Schedules the next message in |kPollingIntervalSeconds| s. 349 // Schedules the next message in |kPollingIntervalSeconds| s.
349 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 350 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
350 FROM_HERE, base::Bind(&ProximityAuthBleSystem::StartPollingScreenState, 351 FROM_HERE, base::Bind(&ProximityAuthBleSystem::StartPollingScreenState,
351 weak_ptr_factory_.GetWeakPtr()), 352 weak_ptr_factory_.GetWeakPtr()),
352 base::TimeDelta::FromSeconds(kPollingIntervalSeconds)); 353 base::TimeDelta::FromSeconds(kPollingIntervalSeconds));
353 354
354 PA_LOG(INFO) << "Next poll iteration posted."; 355 PA_LOG(INFO) << "Next poll iteration posted.";
355 } 356 }
356 } 357 }
357 358
358 void ProximityAuthBleSystem::StopPollingScreenState() { 359 void ProximityAuthBleSystem::StopPollingScreenState() {
359 is_polling_screen_state_ = false; 360 is_polling_screen_state_ = false;
360 } 361 }
361 362
362 bool ProximityAuthBleSystem::HasUnlockKey(const std::string& message, 363 bool ProximityAuthBleSystem::HasUnlockKey(const std::string& message,
363 std::string* out_public_key) { 364 std::string* out_public_key) {
364 std::string message_prefix(kPublicKeyMessagePrefix); 365 std::string message_prefix(kPublicKeyMessagePrefix);
365 if (message.substr(0, message_prefix.size()) != message_prefix) 366 if (message.substr(0, message_prefix.size()) != message_prefix)
366 return false; 367 return false;
367 std::string public_key = message.substr(message_prefix.size()); 368 std::string public_key = message.substr(message_prefix.size());
368 if (out_public_key) 369 if (out_public_key)
369 (*out_public_key) = public_key; 370 (*out_public_key) = public_key;
370 return unlock_keys_.find(public_key) != unlock_keys_.end() || 371 return unlock_keys_.find(public_key) != unlock_keys_.end() ||
371 device_whitelist_->HasDeviceWithPublicKey(public_key); 372 device_whitelist_->HasDeviceWithPublicKey(public_key);
372 } 373 }
373 374
374 } // namespace proximity_auth 375 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc ('k') | components/proximity_auth/connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698