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

Side by Side Diff: chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.cc

Issue 873103002: Removed unused native code related to wifi bootstrapping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sun 01/25/2015 21:44:58.31 Created 5 years, 11 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ui/webui/local_discovery/local_discovery_ui_handler.h" 5 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/local_discovery/cloud_device_list.h"
16 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h" 16 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h"
17 #include "chrome/browser/local_discovery/privet_constants.h" 17 #include "chrome/browser/local_discovery/privet_constants.h"
18 #include "chrome/browser/local_discovery/privet_device_lister_impl.h" 18 #include "chrome/browser/local_discovery/privet_device_lister_impl.h"
19 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" 19 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h"
20 #include "chrome/browser/local_discovery/privet_http_impl.h"
21 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" 20 #include "chrome/browser/local_discovery/service_discovery_shared_client.h"
22 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 21 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
23 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" 22 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h"
24 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
26 #include "chrome/browser/signin/signin_manager_factory.h" 25 #include "chrome/browser/signin/signin_manager_factory.h"
27 #include "chrome/browser/signin/signin_promo.h"
28 #include "chrome/browser/ui/browser_finder.h" 26 #include "chrome/browser/ui/browser_finder.h"
29 #include "chrome/browser/ui/browser_tabstrip.h" 27 #include "chrome/browser/ui/browser_tabstrip.h"
30 #include "chrome/browser/ui/chrome_pages.h" 28 #include "chrome/browser/ui/chrome_pages.h"
31 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
33 #include "chrome/grit/generated_resources.h" 31 #include "chrome/grit/generated_resources.h"
34 #include "components/cloud_devices/common/cloud_devices_switches.h"
35 #include "components/cloud_devices/common/cloud_devices_urls.h" 32 #include "components/cloud_devices/common/cloud_devices_urls.h"
36 #include "components/signin/core/browser/profile_oauth2_token_service.h" 33 #include "components/signin/core/browser/profile_oauth2_token_service.h"
37 #include "components/signin/core/browser/signin_manager_base.h"
38 #include "content/public/browser/user_metrics.h" 34 #include "content/public/browser/user_metrics.h"
39 #include "content/public/browser/web_ui.h" 35 #include "content/public/browser/web_ui.h"
40 #include "net/base/host_port_pair.h"
41 #include "net/base/net_util.h"
42 #include "net/base/url_util.h"
43 #include "net/http/http_status_code.h"
44 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
45 #include "ui/base/page_transition_types.h"
46 37
47 #if defined(ENABLE_PRINT_PREVIEW) && !defined(OS_CHROMEOS) 38 #if defined(ENABLE_PRINT_PREVIEW) && !defined(OS_CHROMEOS)
48 #define CLOUD_PRINT_CONNECTOR_UI_AVAILABLE 39 #define CLOUD_PRINT_CONNECTOR_UI_AVAILABLE
49 #endif 40 #endif
50 41
51 namespace local_discovery { 42 namespace local_discovery {
52 43
53 namespace { 44 namespace {
54 45
55 const char kDictionaryKeyServiceName[] = "service_name"; 46 const char kDictionaryKeyServiceName[] = "service_name";
56 const char kDictionaryKeyDisplayName[] = "display_name"; 47 const char kDictionaryKeyDisplayName[] = "display_name";
57 const char kDictionaryKeyDescription[] = "description"; 48 const char kDictionaryKeyDescription[] = "description";
58 const char kDictionaryKeyType[] = "type"; 49 const char kDictionaryKeyType[] = "type";
59 const char kDictionaryKeyIsWifi[] = "is_wifi"; 50 const char kDictionaryKeyIsWifi[] = "is_wifi";
60 const char kDictionaryKeyID[] = "id"; 51 const char kDictionaryKeyID[] = "id";
61 52
62 const char kKeyPrefixMDns[] = "MDns:"; 53 const char kKeyPrefixMDns[] = "MDns:";
63 54
64 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
65 const char kKeyPrefixWifi[] = "WiFi:";
66 #endif // ENABLE_WIFI_BOOTSTRAPPING
67
68 int g_num_visible = 0; 55 int g_num_visible = 0;
69 56
70 const int kCloudDevicesPrivetVersion = 3; 57 const int kCloudDevicesPrivetVersion = 3;
71 58
72 scoped_ptr<base::DictionaryValue> CreateDeviceInfo( 59 scoped_ptr<base::DictionaryValue> CreateDeviceInfo(
73 const CloudDeviceListDelegate::Device& description) { 60 const CloudDeviceListDelegate::Device& description) {
74 scoped_ptr<base::DictionaryValue> return_value(new base::DictionaryValue); 61 scoped_ptr<base::DictionaryValue> return_value(new base::DictionaryValue);
75 62
76 return_value->SetString(kDictionaryKeyID, description.id); 63 return_value->SetString(kDictionaryKeyID, description.id);
77 return_value->SetString(kDictionaryKeyDisplayName, description.display_name); 64 return_value->SetString(kDictionaryKeyDisplayName, description.display_name);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 void LocalDiscoveryUIHandler::RegisterMessages() { 125 void LocalDiscoveryUIHandler::RegisterMessages() {
139 web_ui()->RegisterMessageCallback("start", base::Bind( 126 web_ui()->RegisterMessageCallback("start", base::Bind(
140 &LocalDiscoveryUIHandler::HandleStart, 127 &LocalDiscoveryUIHandler::HandleStart,
141 base::Unretained(this))); 128 base::Unretained(this)));
142 web_ui()->RegisterMessageCallback("isVisible", base::Bind( 129 web_ui()->RegisterMessageCallback("isVisible", base::Bind(
143 &LocalDiscoveryUIHandler::HandleIsVisible, 130 &LocalDiscoveryUIHandler::HandleIsVisible,
144 base::Unretained(this))); 131 base::Unretained(this)));
145 web_ui()->RegisterMessageCallback("registerDevice", base::Bind( 132 web_ui()->RegisterMessageCallback("registerDevice", base::Bind(
146 &LocalDiscoveryUIHandler::HandleRegisterDevice, 133 &LocalDiscoveryUIHandler::HandleRegisterDevice,
147 base::Unretained(this))); 134 base::Unretained(this)));
148 web_ui()->RegisterMessageCallback(
149 "confirmCode",
150 base::Bind(&LocalDiscoveryUIHandler::HandleConfirmCode,
151 base::Unretained(this)));
152 web_ui()->RegisterMessageCallback("cancelRegistration", base::Bind( 135 web_ui()->RegisterMessageCallback("cancelRegistration", base::Bind(
153 &LocalDiscoveryUIHandler::HandleCancelRegistration, 136 &LocalDiscoveryUIHandler::HandleCancelRegistration,
154 base::Unretained(this))); 137 base::Unretained(this)));
155 web_ui()->RegisterMessageCallback( 138 web_ui()->RegisterMessageCallback(
156 "requestDeviceList", 139 "requestDeviceList",
157 base::Bind(&LocalDiscoveryUIHandler::HandleRequestDeviceList, 140 base::Bind(&LocalDiscoveryUIHandler::HandleRequestDeviceList,
158 base::Unretained(this))); 141 base::Unretained(this)));
159 web_ui()->RegisterMessageCallback("openCloudPrintURL", base::Bind( 142 web_ui()->RegisterMessageCallback("openCloudPrintURL", base::Bind(
160 &LocalDiscoveryUIHandler::HandleOpenCloudPrintURL, 143 &LocalDiscoveryUIHandler::HandleOpenCloudPrintURL,
161 base::Unretained(this))); 144 base::Unretained(this)));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 signin_manager->AddObserver(this); 179 signin_manager->AddObserver(this);
197 } 180 }
198 181
199 privet_lister_->Start(); 182 privet_lister_->Start();
200 privet_lister_->DiscoverNewDevices(false); 183 privet_lister_->DiscoverNewDevices(false);
201 184
202 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) 185 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
203 StartCloudPrintConnector(); 186 StartCloudPrintConnector();
204 #endif 187 #endif
205 188
206 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
207 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
208 switches::kEnableCloudDevices)) {
209 StartWifiBootstrapping();
210 }
211 #endif
212
213 CheckUserLoggedIn(); 189 CheckUserLoggedIn();
214 } 190 }
215 191
216 void LocalDiscoveryUIHandler::HandleIsVisible(const base::ListValue* args) { 192 void LocalDiscoveryUIHandler::HandleIsVisible(const base::ListValue* args) {
217 bool is_visible = false; 193 bool is_visible = false;
218 bool rv = args->GetBoolean(0, &is_visible); 194 bool rv = args->GetBoolean(0, &is_visible);
219 DCHECK(rv); 195 DCHECK(rv);
220 SetIsVisible(is_visible); 196 SetIsVisible(is_visible);
221 } 197 }
222 198
223 void LocalDiscoveryUIHandler::HandleRegisterDevice( 199 void LocalDiscoveryUIHandler::HandleRegisterDevice(
224 const base::ListValue* args) { 200 const base::ListValue* args) {
225 std::string device; 201 std::string device;
226 202
227 bool rv = args->GetString(0, &device); 203 bool rv = args->GetString(0, &device);
228 DCHECK(rv); 204 DCHECK(rv);
229 205
230 DeviceDescriptionMap::iterator found = device_descriptions_.find(device); 206 DeviceDescriptionMap::iterator found = device_descriptions_.find(device);
231 if (found == device_descriptions_.end()) { 207 if (found == device_descriptions_.end()) {
232 OnSetupError(); 208 OnSetupError();
233 return; 209 return;
234 } 210 }
235 211
236 if (found->second.version == kCloudDevicesPrivetVersion) { 212 if (found->second.version < kCloudDevicesPrivetVersion) {
237 current_setup_operation_.reset(new PrivetV3SetupFlow(this));
238 current_setup_operation_->Register(device);
239 } else if (found->second.version <= 2) {
240 privet_resolution_ = privet_http_factory_->CreatePrivetHTTP( 213 privet_resolution_ = privet_http_factory_->CreatePrivetHTTP(
241 device, 214 device,
242 found->second.address, 215 found->second.address,
243 base::Bind(&LocalDiscoveryUIHandler::StartRegisterHTTP, 216 base::Bind(&LocalDiscoveryUIHandler::StartRegisterHTTP,
244 base::Unretained(this))); 217 base::Unretained(this)));
245 privet_resolution_->Start(); 218 privet_resolution_->Start();
246 } else { 219 } else {
247 OnSetupError(); 220 OnSetupError();
248 } 221 }
249 } 222 }
250 223
251 void LocalDiscoveryUIHandler::HandleConfirmCode(const base::ListValue* args) {
252 device_code_callback_.Run(true);
253 }
254
255 void LocalDiscoveryUIHandler::HandleCancelRegistration( 224 void LocalDiscoveryUIHandler::HandleCancelRegistration(
256 const base::ListValue* args) { 225 const base::ListValue* args) {
257 ResetCurrentRegistration(); 226 ResetCurrentRegistration();
258 } 227 }
259 228
260 void LocalDiscoveryUIHandler::HandleRequestDeviceList( 229 void LocalDiscoveryUIHandler::HandleRequestDeviceList(
261 const base::ListValue* args) { 230 const base::ListValue* args) {
262 failed_list_count_ = 0; 231 failed_list_count_ = 0;
263 succeded_list_count_ = 0; 232 succeded_list_count_ = 0;
264 cloud_devices_.clear(); 233 cloud_devices_.clear();
265 234
266 cloud_print_printer_list_ = CreateApiFlow();
267 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
268 switches::kEnableCloudDevices)) {
269 cloud_device_list_ = CreateApiFlow();
270 }
271
272 if (cloud_print_printer_list_) { 235 if (cloud_print_printer_list_) {
273 cloud_print_printer_list_->Start( 236 cloud_print_printer_list_->Start(
274 make_scoped_ptr<GCDApiFlow::Request>(new CloudPrintPrinterList(this))); 237 make_scoped_ptr<GCDApiFlow::Request>(new CloudPrintPrinterList(this)));
275 } 238 }
276 if (cloud_device_list_) { 239
277 cloud_device_list_->Start(
278 make_scoped_ptr<GCDApiFlow::Request>(new CloudDeviceList(this)));
279 }
280 CheckListingDone(); 240 CheckListingDone();
281 } 241 }
282 242
283 void LocalDiscoveryUIHandler::HandleOpenCloudPrintURL( 243 void LocalDiscoveryUIHandler::HandleOpenCloudPrintURL(
284 const base::ListValue* args) { 244 const base::ListValue* args) {
285 std::string id; 245 std::string id;
286 bool rv = args->GetString(0, &id); 246 bool rv = args->GetString(0, &id);
287 DCHECK(rv); 247 DCHECK(rv);
288 248
289 Browser* browser = chrome::FindBrowserWithWebContents( 249 Browser* browser = chrome::FindBrowserWithWebContents(
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 323 }
364 } 324 }
365 325
366 SendRegisterError(); 326 SendRegisterError();
367 } 327 }
368 328
369 void LocalDiscoveryUIHandler::OnPrivetRegisterDone( 329 void LocalDiscoveryUIHandler::OnPrivetRegisterDone(
370 PrivetRegisterOperation* operation, 330 PrivetRegisterOperation* operation,
371 const std::string& device_id) { 331 const std::string& device_id) {
372 std::string name = operation->GetHTTPClient()->GetName(); 332 std::string name = operation->GetHTTPClient()->GetName();
373 current_setup_operation_.reset();
374 current_register_operation_.reset(); 333 current_register_operation_.reset();
375 current_http_client_.reset(); 334 current_http_client_.reset();
376 SendRegisterDone(name); 335 SendRegisterDone(name);
377 } 336 }
378 337
379 void LocalDiscoveryUIHandler::GetWiFiCredentials(
380 const CredentialsCallback& callback) {
381 callback.Run("", "");
382 }
383
384 void LocalDiscoveryUIHandler::SwitchToSetupWiFi(
385 const ResultCallback& callback) {
386 callback.Run(true);
387 }
388
389 void LocalDiscoveryUIHandler::ConfirmSecurityCode(
390 const ResultCallback& callback) {
391 device_code_callback_ = callback;
392 web_ui()->CallJavascriptFunction(
393 "local_discovery.onRegistrationConfirmDeviceCode",
394 base::StringValue("1234"));
395 }
396
397 void LocalDiscoveryUIHandler::RestoreWifi(const ResultCallback& callback) {
398 callback.Run(true);
399 }
400
401 void LocalDiscoveryUIHandler::OnSetupDone() {
402 std::string service_name = current_setup_operation_->service_name();
403 current_setup_operation_.reset();
404 current_register_operation_.reset();
405 current_http_client_.reset();
406 SendRegisterDone(service_name);
407 }
408
409 void LocalDiscoveryUIHandler::OnSetupError() { 338 void LocalDiscoveryUIHandler::OnSetupError() {
410 ResetCurrentRegistration(); 339 ResetCurrentRegistration();
411 SendRegisterError(); 340 SendRegisterError();
412 } 341 }
413 342
414 void LocalDiscoveryUIHandler::OnConfirmDone(GCDApiFlow::Status status) { 343 void LocalDiscoveryUIHandler::OnConfirmDone(GCDApiFlow::Status status) {
415 if (status == GCDApiFlow::SUCCESS) { 344 if (status == GCDApiFlow::SUCCESS) {
416 confirm_api_call_flow_.reset(); 345 confirm_api_call_flow_.reset();
417 current_register_operation_->CompleteRegistration(); 346 current_register_operation_->CompleteRegistration();
418 } else { 347 } else {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 return signin_manager->GetAuthenticatedUsername(); 466 return signin_manager->GetAuthenticatedUsername();
538 } 467 }
539 468
540 // TODO(noamsml): Create master object for registration flow. 469 // TODO(noamsml): Create master object for registration flow.
541 void LocalDiscoveryUIHandler::ResetCurrentRegistration() { 470 void LocalDiscoveryUIHandler::ResetCurrentRegistration() {
542 if (current_register_operation_) { 471 if (current_register_operation_) {
543 current_register_operation_->Cancel(); 472 current_register_operation_->Cancel();
544 current_register_operation_.reset(); 473 current_register_operation_.reset();
545 } 474 }
546 475
547 current_setup_operation_.reset();
548 confirm_api_call_flow_.reset(); 476 confirm_api_call_flow_.reset();
549 privet_resolution_.reset(); 477 privet_resolution_.reset();
550 current_http_client_.reset(); 478 current_http_client_.reset();
551 } 479 }
552 480
553 void LocalDiscoveryUIHandler::PrivetClientToV3(
554 const PrivetClientCallback& callback,
555 scoped_ptr<PrivetHTTPClient> client) {
556 callback.Run(client.Pass());
557 }
558
559 void LocalDiscoveryUIHandler::CheckUserLoggedIn() { 481 void LocalDiscoveryUIHandler::CheckUserLoggedIn() {
560 base::FundamentalValue logged_in_value(!GetSyncAccount().empty()); 482 base::FundamentalValue logged_in_value(!GetSyncAccount().empty());
561 base::FundamentalValue is_supervised_value(IsUserSupervisedOrOffTheRecord()); 483 base::FundamentalValue is_supervised_value(IsUserSupervisedOrOffTheRecord());
562 web_ui()->CallJavascriptFunction( 484 web_ui()->CallJavascriptFunction(
563 "local_discovery.setUserLoggedIn", logged_in_value, is_supervised_value); 485 "local_discovery.setUserLoggedIn", logged_in_value, is_supervised_value);
564 } 486 }
565 487
566 void LocalDiscoveryUIHandler::CheckListingDone() { 488 void LocalDiscoveryUIHandler::CheckListingDone() {
567 int started = 0; 489 int started = 0;
568 if (cloud_print_printer_list_) 490 if (cloud_print_printer_list_)
569 ++started; 491 ++started;
570 if (cloud_device_list_)
571 ++started;
572 492
573 if (started > failed_list_count_ + succeded_list_count_) 493 if (started > failed_list_count_ + succeded_list_count_)
574 return; 494 return;
575 495
576 if (succeded_list_count_ <= 0) { 496 if (succeded_list_count_ <= 0) {
577 web_ui()->CallJavascriptFunction( 497 web_ui()->CallJavascriptFunction(
578 "local_discovery.onCloudDeviceListUnavailable"); 498 "local_discovery.onCloudDeviceListUnavailable");
579 return; 499 return;
580 } 500 }
581 501
582 base::ListValue devices_list; 502 base::ListValue devices_list;
583 std::set<std::string> local_ids; 503 std::set<std::string> local_ids;
584 504
585 for (DeviceDescriptionMap::iterator i = device_descriptions_.begin(); 505 for (DeviceDescriptionMap::iterator i = device_descriptions_.begin();
586 i != device_descriptions_.end(); i++) { 506 i != device_descriptions_.end(); i++) {
587 local_ids.insert(i->second.id); 507 local_ids.insert(i->second.id);
588 } 508 }
589 509
590 ReadDevicesList(cloud_devices_, local_ids, &devices_list); 510 ReadDevicesList(cloud_devices_, local_ids, &devices_list);
591 511
592 web_ui()->CallJavascriptFunction( 512 web_ui()->CallJavascriptFunction(
593 "local_discovery.onCloudDeviceListAvailable", devices_list); 513 "local_discovery.onCloudDeviceListAvailable", devices_list);
594 cloud_print_printer_list_.reset(); 514 cloud_print_printer_list_.reset();
595 cloud_device_list_.reset();
596 } 515 }
597 516
598 scoped_ptr<GCDApiFlow> LocalDiscoveryUIHandler::CreateApiFlow() { 517 scoped_ptr<GCDApiFlow> LocalDiscoveryUIHandler::CreateApiFlow() {
599 Profile* profile = Profile::FromWebUI(web_ui()); 518 Profile* profile = Profile::FromWebUI(web_ui());
600 if (!profile) 519 if (!profile)
601 return scoped_ptr<GCDApiFlow>(); 520 return scoped_ptr<GCDApiFlow>();
602 ProfileOAuth2TokenService* token_service = 521 ProfileOAuth2TokenService* token_service =
603 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 522 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
604 if (!token_service) 523 if (!token_service)
605 return scoped_ptr<GCDApiFlow>(); 524 return scoped_ptr<GCDApiFlow>();
606 SigninManagerBase* signin_manager = 525 SigninManagerBase* signin_manager =
607 SigninManagerFactory::GetInstance()->GetForProfile(profile); 526 SigninManagerFactory::GetInstance()->GetForProfile(profile);
608 if (!signin_manager) 527 if (!signin_manager)
609 return scoped_ptr<GCDApiFlow>(); 528 return scoped_ptr<GCDApiFlow>();
610 return GCDApiFlow::Create(profile->GetRequestContext(), 529 return GCDApiFlow::Create(profile->GetRequestContext(),
611 token_service, 530 token_service,
612 signin_manager->GetAuthenticatedAccountId()); 531 signin_manager->GetAuthenticatedAccountId());
613 } 532 }
614 533
615 void LocalDiscoveryUIHandler::CreatePrivetV3Client(
616 const std::string& device,
617 const PrivetClientCallback& callback) {
618 DeviceDescriptionMap::iterator found = device_descriptions_.find(device);
619 if (found == device_descriptions_.end())
620 return callback.Run(scoped_ptr<PrivetHTTPClient>());
621 PrivetHTTPAsynchronousFactory::ResultCallback new_callback =
622 base::Bind(&LocalDiscoveryUIHandler::PrivetClientToV3,
623 base::Unretained(this),
624 callback);
625 privet_resolution_ =
626 privet_http_factory_->CreatePrivetHTTP(device,
627 found->second.address,
628 new_callback).Pass();
629 if (!privet_resolution_)
630 return callback.Run(scoped_ptr<PrivetHTTPClient>());
631 privet_resolution_->Start();
632 }
633
634 bool LocalDiscoveryUIHandler::IsUserSupervisedOrOffTheRecord() { 534 bool LocalDiscoveryUIHandler::IsUserSupervisedOrOffTheRecord() {
635 Profile* profile = Profile::FromWebUI(web_ui()); 535 Profile* profile = Profile::FromWebUI(web_ui());
636 536
637 return profile->IsSupervised() || profile->IsOffTheRecord(); 537 return profile->IsSupervised() || profile->IsOffTheRecord();
638 } 538 }
639 539
640 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) 540 #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
641 void LocalDiscoveryUIHandler::StartCloudPrintConnector() { 541 void LocalDiscoveryUIHandler::StartCloudPrintConnector() {
642 Profile* profile = Profile::FromWebUI(web_ui()); 542 Profile* profile = Profile::FromWebUI(web_ui());
643 543
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 } 638 }
739 639
740 void LocalDiscoveryUIHandler::RefreshCloudPrintStatusFromService() { 640 void LocalDiscoveryUIHandler::RefreshCloudPrintStatusFromService() {
741 if (cloud_print_connector_ui_enabled_) 641 if (cloud_print_connector_ui_enabled_)
742 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> 642 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))->
743 RefreshStatusFromService(); 643 RefreshStatusFromService();
744 } 644 }
745 645
746 #endif // cloud print connector option stuff 646 #endif // cloud print connector option stuff
747 647
748 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
749
750 void LocalDiscoveryUIHandler::StartWifiBootstrapping() {
751 // Since LocalDiscoveryUIHandler isn't destroyed every time the page is
752 // refreshed, reset bootstrapping_device_lister_ so it's destoryed before
753 // wifi_manager_ is.
754 bootstrapping_device_lister_.reset();
755
756 wifi_manager_ = wifi::WifiManager::Create();
757 bootstrapping_device_lister_.reset(new wifi::BootstrappingDeviceLister(
758 wifi_manager_.get(),
759 base::Bind(&LocalDiscoveryUIHandler::OnBootstrappingDeviceChanged,
760 base::Unretained(this))));
761
762 wifi_manager_->Start();
763 bootstrapping_device_lister_->Start();
764 wifi_manager_->RequestScan();
765 }
766
767 void LocalDiscoveryUIHandler::OnBootstrappingDeviceChanged(
768 bool available,
769 const wifi::BootstrappingDeviceDescription& description) {
770 base::DictionaryValue info;
771
772 base::StringValue service_key(kKeyPrefixWifi + description.device_ssid);
773
774 if (available) {
775 info.SetString(kDictionaryKeyServiceName, description.device_ssid);
776 info.SetString(kDictionaryKeyDisplayName, description.device_name);
777 info.SetString(kDictionaryKeyDescription, std::string());
778 info.SetString(kDictionaryKeyType, description.device_kind);
779 info.SetBoolean(kDictionaryKeyIsWifi, true);
780
781 web_ui()->CallJavascriptFunction(
782 "local_discovery.onUnregisteredDeviceUpdate", service_key, info);
783 } else {
784 scoped_ptr<base::Value> null_value(base::Value::CreateNullValue());
785
786 web_ui()->CallJavascriptFunction(
787 "local_discovery.onUnregisteredDeviceUpdate", service_key, *null_value);
788 }
789 }
790
791 #endif // ENABLE_WIFI_BOOTSTRAPPING
792
793 } // namespace local_discovery 648 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698