| OLD | NEW |
| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/local_discovery/privet_device_lister_impl.h" | 10 #include "chrome/browser/local_discovery/privet_device_lister_impl.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 LocalDiscoveryUIHandler::LocalDiscoveryUIHandler() : is_visible_(false) { | 35 LocalDiscoveryUIHandler::LocalDiscoveryUIHandler() : is_visible_(false) { |
| 36 } | 36 } |
| 37 | 37 |
| 38 LocalDiscoveryUIHandler::LocalDiscoveryUIHandler( | 38 LocalDiscoveryUIHandler::LocalDiscoveryUIHandler( |
| 39 scoped_ptr<PrivetDeviceLister> privet_lister) { | 39 scoped_ptr<PrivetDeviceLister> privet_lister) { |
| 40 privet_lister.swap(privet_lister_); | 40 privet_lister.swap(privet_lister_); |
| 41 } | 41 } |
| 42 | 42 |
| 43 LocalDiscoveryUIHandler::~LocalDiscoveryUIHandler() { | 43 LocalDiscoveryUIHandler::~LocalDiscoveryUIHandler() { |
| 44 ResetCurrentRegistration(); |
| 44 SetIsVisible(false); | 45 SetIsVisible(false); |
| 45 if (service_discovery_client_.get()) { | 46 if (service_discovery_client_.get()) { |
| 46 service_discovery_client_ = NULL; | 47 service_discovery_client_ = NULL; |
| 47 ServiceDiscoveryHostClientFactory::ReleaseClient(); | 48 ServiceDiscoveryHostClientFactory::ReleaseClient(); |
| 48 } | 49 } |
| 49 } | 50 } |
| 50 | 51 |
| 51 // static | 52 // static |
| 52 LocalDiscoveryUIHandler* LocalDiscoveryUIHandler::Create() { | 53 LocalDiscoveryUIHandler* LocalDiscoveryUIHandler::Create() { |
| 53 if (g_factory) return g_factory->CreateLocalDiscoveryUIHandler(); | 54 if (g_factory) return g_factory->CreateLocalDiscoveryUIHandler(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 70 base::Unretained(this))); | 71 base::Unretained(this))); |
| 71 web_ui()->RegisterMessageCallback("isVisible", base::Bind( | 72 web_ui()->RegisterMessageCallback("isVisible", base::Bind( |
| 72 &LocalDiscoveryUIHandler::HandleIsVisible, | 73 &LocalDiscoveryUIHandler::HandleIsVisible, |
| 73 base::Unretained(this))); | 74 base::Unretained(this))); |
| 74 web_ui()->RegisterMessageCallback("registerDevice", base::Bind( | 75 web_ui()->RegisterMessageCallback("registerDevice", base::Bind( |
| 75 &LocalDiscoveryUIHandler::HandleRegisterDevice, | 76 &LocalDiscoveryUIHandler::HandleRegisterDevice, |
| 76 base::Unretained(this))); | 77 base::Unretained(this))); |
| 77 web_ui()->RegisterMessageCallback("chooseUser", base::Bind( | 78 web_ui()->RegisterMessageCallback("chooseUser", base::Bind( |
| 78 &LocalDiscoveryUIHandler::HandleChooseUser, | 79 &LocalDiscoveryUIHandler::HandleChooseUser, |
| 79 base::Unretained(this))); | 80 base::Unretained(this))); |
| 81 web_ui()->RegisterMessageCallback("cancelRegistration", base::Bind( |
| 82 &LocalDiscoveryUIHandler::HandleCancelRegistration, |
| 83 base::Unretained(this))); |
| 80 } | 84 } |
| 81 | 85 |
| 82 void LocalDiscoveryUIHandler::HandleStart(const base::ListValue* args) { | 86 void LocalDiscoveryUIHandler::HandleStart(const base::ListValue* args) { |
| 83 // If privet_lister_ is already set, it is a mock used for tests or the result | 87 // If privet_lister_ is already set, it is a mock used for tests or the result |
| 84 // of a reload. | 88 // of a reload. |
| 85 if (!privet_lister_) { | 89 if (!privet_lister_) { |
| 86 service_discovery_client_ = ServiceDiscoveryHostClientFactory::GetClient(); | 90 service_discovery_client_ = ServiceDiscoveryHostClientFactory::GetClient(); |
| 87 privet_lister_.reset(new PrivetDeviceListerImpl( | 91 privet_lister_.reset(new PrivetDeviceListerImpl( |
| 88 service_discovery_client_.get(), this)); | 92 service_discovery_client_.get(), this)); |
| 89 privet_http_factory_.reset(new PrivetHTTPAsynchronousFactoryImpl( | 93 privet_http_factory_.reset(new PrivetHTTPAsynchronousFactoryImpl( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 DCHECK(rv); | 134 DCHECK(rv); |
| 131 | 135 |
| 132 privet_resolution_ = privet_http_factory_->CreatePrivetHTTP( | 136 privet_resolution_ = privet_http_factory_->CreatePrivetHTTP( |
| 133 current_register_device_, | 137 current_register_device_, |
| 134 device_descriptions_[current_register_device_].address, | 138 device_descriptions_[current_register_device_].address, |
| 135 base::Bind(&LocalDiscoveryUIHandler::StartRegisterHTTP, | 139 base::Bind(&LocalDiscoveryUIHandler::StartRegisterHTTP, |
| 136 base::Unretained(this), user)); | 140 base::Unretained(this), user)); |
| 137 privet_resolution_->Start(); | 141 privet_resolution_->Start(); |
| 138 } | 142 } |
| 139 | 143 |
| 144 void LocalDiscoveryUIHandler::HandleCancelRegistration( |
| 145 const base::ListValue* args) { |
| 146 ResetCurrentRegistration(); |
| 147 } |
| 148 |
| 140 void LocalDiscoveryUIHandler::StartRegisterHTTP( | 149 void LocalDiscoveryUIHandler::StartRegisterHTTP( |
| 141 const std::string& user, | 150 const std::string& user, |
| 142 scoped_ptr<PrivetHTTPClient> http_client) { | 151 scoped_ptr<PrivetHTTPClient> http_client) { |
| 143 current_http_client_.swap(http_client); | 152 current_http_client_.swap(http_client); |
| 144 | 153 |
| 145 if (!current_http_client_) { | 154 if (!current_http_client_) { |
| 146 SendRegisterError(); | 155 SendRegisterError(); |
| 147 return; | 156 return; |
| 148 } | 157 } |
| 149 | 158 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 Profile::FromWebUI(web_ui())->GetRequestContext(), | 355 Profile::FromWebUI(web_ui())->GetRequestContext(), |
| 347 user_index, | 356 user_index, |
| 348 xsrf_token, | 357 xsrf_token, |
| 349 automated_claim_url, | 358 automated_claim_url, |
| 350 base::Bind(&LocalDiscoveryUIHandler::OnConfirmDone, | 359 base::Bind(&LocalDiscoveryUIHandler::OnConfirmDone, |
| 351 base::Unretained(this)))); | 360 base::Unretained(this)))); |
| 352 | 361 |
| 353 confirm_api_call_flow_->Start(); | 362 confirm_api_call_flow_->Start(); |
| 354 } | 363 } |
| 355 | 364 |
| 365 // TODO(noamsml): Create master object for registration flow. |
| 366 void LocalDiscoveryUIHandler::ResetCurrentRegistration() { |
| 367 current_register_device_.clear(); |
| 368 if (current_register_operation_.get()) { |
| 369 current_register_operation_->Cancel(); |
| 370 current_register_operation_.reset(); |
| 371 } |
| 372 |
| 373 confirm_api_call_flow_.reset(); |
| 374 privet_resolution_.reset(); |
| 375 cloud_print_account_manager_.reset(); |
| 376 xsrf_token_for_primary_user_.clear(); |
| 377 current_register_user_index_ = 0; |
| 378 current_http_client_.reset(); |
| 379 } |
| 380 |
| 356 } // namespace local_discovery | 381 } // namespace local_discovery |
| OLD | NEW |