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

Side by Side Diff: components/pairing/bluetooth_host_pairing_controller.cc

Issue 1519883003: 1) Add basic configuration (network connection, language, keyboard layout, timezone) setup page. 2)… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the i18n-content HTML format in the html files Created 5 years 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 "components/pairing/bluetooth_host_pairing_controller.h" 5 #include "components/pairing/bluetooth_host_pairing_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/hash.h" 8 #include "base/hash.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "components/pairing/bluetooth_pairing_constants.h" 11 #include "components/pairing/bluetooth_pairing_constants.h"
12 #include "components/pairing/pairing_api.pb.h" 12 #include "components/pairing/pairing_api.pb.h"
13 #include "components/pairing/proto_decoder.h" 13 #include "components/pairing/proto_decoder.h"
14 #include "device/bluetooth/bluetooth_adapter_factory.h" 14 #include "device/bluetooth/bluetooth_adapter_factory.h"
15 #include "net/base/io_buffer.h" 15 #include "net/base/io_buffer.h"
16 16
17 namespace pairing_chromeos { 17 namespace pairing_chromeos {
18 18
19 namespace { 19 namespace {
20 const int kReceiveSize = 16384; 20 const int kReceiveSize = 16384;
21 21
22 pairing_api::HostStatusParameters::Connectivity PairingApiConnectivityStatus(
23 HostPairingController::Connectivity connectivity_status) {
24 switch (connectivity_status) {
25 case HostPairingController::CONNECTIVITY_UNTESTED:
26 return pairing_api::HostStatusParameters::CONNECTIVITY_UNTESTED;
27 case HostPairingController::CONNECTIVITY_NONE:
28 return pairing_api::HostStatusParameters::CONNECTIVITY_NONE;
29 case HostPairingController::CONNECTIVITY_LIMITED:
30 return pairing_api::HostStatusParameters::CONNECTIVITY_LIMITED;
31 case HostPairingController::CONNECTIVITY_CONNECTING:
32 return pairing_api::HostStatusParameters::CONNECTIVITY_CONNECTING;
33 case HostPairingController::CONNECTIVITY_CONNECTED:
34 return pairing_api::HostStatusParameters::CONNECTIVITY_CONNECTED;
35 default:
36 NOTREACHED();
37 return pairing_api::HostStatusParameters::CONNECTIVITY_UNTESTED;
38 }
39 }
40
22 pairing_api::HostStatusParameters::UpdateStatus PairingApiUpdateStatus( 41 pairing_api::HostStatusParameters::UpdateStatus PairingApiUpdateStatus(
23 HostPairingController::UpdateStatus update_status) { 42 HostPairingController::UpdateStatus update_status) {
24 switch(update_status) { 43 switch(update_status) {
25 case HostPairingController::UPDATE_STATUS_UNKNOWN: 44 case HostPairingController::UPDATE_STATUS_UNKNOWN:
26 return pairing_api::HostStatusParameters::UPDATE_STATUS_UNKNOWN; 45 return pairing_api::HostStatusParameters::UPDATE_STATUS_UNKNOWN;
27 case HostPairingController::UPDATE_STATUS_UPDATING: 46 case HostPairingController::UPDATE_STATUS_UPDATING:
28 return pairing_api::HostStatusParameters::UPDATE_STATUS_UPDATING; 47 return pairing_api::HostStatusParameters::UPDATE_STATUS_UPDATING;
29 case HostPairingController::UPDATE_STATUS_REBOOTING: 48 case HostPairingController::UPDATE_STATUS_REBOOTING:
30 return pairing_api::HostStatusParameters::UPDATE_STATUS_REBOOTING; 49 return pairing_api::HostStatusParameters::UPDATE_STATUS_REBOOTING;
31 case HostPairingController::UPDATE_STATUS_UPDATED: 50 case HostPairingController::UPDATE_STATUS_UPDATED:
(...skipping 18 matching lines...) Expand all
50 default: 69 default:
51 NOTREACHED(); 70 NOTREACHED();
52 return pairing_api::HostStatusParameters::ENROLLMENT_STATUS_UNKNOWN; 71 return pairing_api::HostStatusParameters::ENROLLMENT_STATUS_UNKNOWN;
53 } 72 }
54 } 73 }
55 74
56 } // namespace 75 } // namespace
57 76
58 BluetoothHostPairingController::BluetoothHostPairingController() 77 BluetoothHostPairingController::BluetoothHostPairingController()
59 : current_stage_(STAGE_NONE), 78 : current_stage_(STAGE_NONE),
79 connectivity_status_(CONNECTIVITY_UNTESTED),
60 update_status_(UPDATE_STATUS_UNKNOWN), 80 update_status_(UPDATE_STATUS_UNKNOWN),
61 enrollment_status_(ENROLLMENT_STATUS_UNKNOWN), 81 enrollment_status_(ENROLLMENT_STATUS_UNKNOWN),
62 proto_decoder_(new ProtoDecoder(this)), 82 proto_decoder_(new ProtoDecoder(this)),
63 ptr_factory_(this) { 83 ptr_factory_(this) {}
64 }
65 84
66 BluetoothHostPairingController::~BluetoothHostPairingController() { 85 BluetoothHostPairingController::~BluetoothHostPairingController() {
67 Reset(); 86 Reset();
68 if (adapter_.get()) { 87 if (adapter_.get()) {
69 if (adapter_->IsDiscoverable()) { 88 if (adapter_->IsDiscoverable()) {
70 adapter_->SetDiscoverable(false, base::Closure(), base::Closure()); 89 adapter_->SetDiscoverable(false, base::Closure(), base::Closure());
71 } 90 }
72 adapter_->RemoveObserver(this); 91 adapter_->RemoveObserver(this);
73 adapter_ = NULL; 92 adapter_ = NULL;
74 } 93 }
(...skipping 11 matching lines...) Expand all
86 pairing_api::HostStatus host_status; 105 pairing_api::HostStatus host_status;
87 106
88 host_status.set_api_version(kPairingAPIVersion); 107 host_status.set_api_version(kPairingAPIVersion);
89 if (!enrollment_domain_.empty()) 108 if (!enrollment_domain_.empty())
90 host_status.mutable_parameters()->set_domain(enrollment_domain_); 109 host_status.mutable_parameters()->set_domain(enrollment_domain_);
91 if (!permanent_id_.empty()) 110 if (!permanent_id_.empty())
92 host_status.mutable_parameters()->set_permanent_id(permanent_id_); 111 host_status.mutable_parameters()->set_permanent_id(permanent_id_);
93 112
94 // TODO(zork): Get these values from the UI. (http://crbug.com/405744) 113 // TODO(zork): Get these values from the UI. (http://crbug.com/405744)
95 host_status.mutable_parameters()->set_connectivity( 114 host_status.mutable_parameters()->set_connectivity(
96 pairing_api::HostStatusParameters::CONNECTIVITY_CONNECTED); 115 PairingApiConnectivityStatus(connectivity_status_));
97 host_status.mutable_parameters()->set_update_status( 116 host_status.mutable_parameters()->set_update_status(
98 PairingApiUpdateStatus(update_status_)); 117 PairingApiUpdateStatus(update_status_));
99 host_status.mutable_parameters()->set_enrollment_status( 118 host_status.mutable_parameters()->set_enrollment_status(
100 PairingApiEnrollmentStatus(enrollment_status_)); 119 PairingApiEnrollmentStatus(enrollment_status_));
101 120
102 // TODO(zork): Get a list of other paired controllers. 121 // TODO(zork): Get a list of other paired controllers.
103 // (http://crbug.com/405757) 122 // (http://crbug.com/405757)
104 123
105 int size = 0; 124 int size = 0;
106 scoped_refptr<net::IOBuffer> io_buffer( 125 scoped_refptr<net::IOBuffer> io_buffer(
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 LOG(ERROR) << reason << ", " << error_message; 321 LOG(ERROR) << reason << ", " << error_message;
303 } 322 }
304 323
305 void BluetoothHostPairingController::OnHostStatusMessage( 324 void BluetoothHostPairingController::OnHostStatusMessage(
306 const pairing_api::HostStatus& message) { 325 const pairing_api::HostStatus& message) {
307 NOTREACHED(); 326 NOTREACHED();
308 } 327 }
309 328
310 void BluetoothHostPairingController::OnConfigureHostMessage( 329 void BluetoothHostPairingController::OnConfigureHostMessage(
311 const pairing_api::ConfigureHost& message) { 330 const pairing_api::ConfigureHost& message) {
331 ChangeStage(STAGE_SETUP_BASIC_CONFIGURATION);
312 FOR_EACH_OBSERVER(Observer, observers_, 332 FOR_EACH_OBSERVER(Observer, observers_,
313 ConfigureHostRequested( 333 ConfigureHostRequested(
314 message.parameters().accepted_eula(), 334 message.parameters().accepted_eula(),
315 message.parameters().lang(), 335 message.parameters().lang(),
316 message.parameters().timezone(), 336 message.parameters().timezone(),
317 message.parameters().send_reports(), 337 message.parameters().send_reports(),
318 message.parameters().keyboard_layout())); 338 message.parameters().keyboard_layout()));
319 } 339 }
320 340
321 void BluetoothHostPairingController::OnPairDevicesMessage( 341 void BluetoothHostPairingController::OnPairDevicesMessage(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 414
395 std::string BluetoothHostPairingController::GetConfirmationCode() { 415 std::string BluetoothHostPairingController::GetConfirmationCode() {
396 DCHECK_EQ(current_stage_, STAGE_WAITING_FOR_CODE_CONFIRMATION); 416 DCHECK_EQ(current_stage_, STAGE_WAITING_FOR_CODE_CONFIRMATION);
397 return confirmation_code_; 417 return confirmation_code_;
398 } 418 }
399 419
400 std::string BluetoothHostPairingController::GetEnrollmentDomain() { 420 std::string BluetoothHostPairingController::GetEnrollmentDomain() {
401 return enrollment_domain_; 421 return enrollment_domain_;
402 } 422 }
403 423
424 void BluetoothHostPairingController::OnNetworkConnectivityChanged(
425 Connectivity connectivity_status) {
426 connectivity_status_ = connectivity_status;
427 if (connectivity_status == CONNECTIVITY_NONE)
428 ChangeStage(STAGE_SETUP_NETWORK_ERROR);
429 SendHostStatus();
430 }
431
404 void BluetoothHostPairingController::OnUpdateStatusChanged( 432 void BluetoothHostPairingController::OnUpdateStatusChanged(
405 UpdateStatus update_status) { 433 UpdateStatus update_status) {
406 update_status_ = update_status; 434 update_status_ = update_status;
407 if (update_status == UPDATE_STATUS_UPDATED) 435 if (update_status == UPDATE_STATUS_UPDATED)
408 ChangeStage(STAGE_WAITING_FOR_CREDENTIALS); 436 ChangeStage(STAGE_WAITING_FOR_CREDENTIALS);
409 SendHostStatus(); 437 SendHostStatus();
410 } 438 }
411 439
412 void BluetoothHostPairingController::OnEnrollmentStatusChanged( 440 void BluetoothHostPairingController::OnEnrollmentStatusChanged(
413 EnrollmentStatus enrollment_status) { 441 EnrollmentStatus enrollment_status) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); 504 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION);
477 } 505 }
478 506
479 void BluetoothHostPairingController::AuthorizePairing( 507 void BluetoothHostPairingController::AuthorizePairing(
480 device::BluetoothDevice* device) { 508 device::BluetoothDevice* device) {
481 // Disallow unknown device. 509 // Disallow unknown device.
482 device->RejectPairing(); 510 device->RejectPairing();
483 } 511 }
484 512
485 } // namespace pairing_chromeos 513 } // namespace pairing_chromeos
OLDNEW
« no previous file with comments | « components/pairing/bluetooth_host_pairing_controller.h ('k') | components/pairing/fake_host_pairing_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698