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 <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" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 #endif // defined(ENABLE_FULL_PRINTING) | 158 #endif // defined(ENABLE_FULL_PRINTING) |
159 } | 159 } |
160 | 160 |
161 void LocalDiscoveryUIHandler::HandleStart(const base::ListValue* args) { | 161 void LocalDiscoveryUIHandler::HandleStart(const base::ListValue* args) { |
162 Profile* profile = Profile::FromWebUI(web_ui()); | 162 Profile* profile = Profile::FromWebUI(web_ui()); |
163 | 163 |
164 // If privet_lister_ is already set, it is a mock used for tests or the result | 164 // If privet_lister_ is already set, it is a mock used for tests or the result |
165 // of a reload. | 165 // of a reload. |
166 if (!privet_lister_) { | 166 if (!privet_lister_) { |
167 service_discovery_client_ = ServiceDiscoverySharedClient::GetInstance(); | 167 service_discovery_client_ = ServiceDiscoverySharedClient::GetInstance(); |
168 privet_lister_.reset(new PrivetDeviceListerImpl( | 168 privet_lister_.reset( |
169 service_discovery_client_.get(), this)); | 169 new PrivetDeviceListerImpl(service_discovery_client_.get(), this)); |
170 privet_http_factory_ = | 170 privet_http_factory_ = |
171 PrivetHTTPAsynchronousFactory::CreateInstance( | 171 PrivetHTTPAsynchronousFactory::CreateInstance( |
172 service_discovery_client_.get(), profile->GetRequestContext()); | 172 service_discovery_client_.get(), profile->GetRequestContext()); |
173 | 173 |
174 SigninManagerBase* signin_manager = | 174 SigninManagerBase* signin_manager = |
175 SigninManagerFactory::GetInstance()->GetForProfile(profile); | 175 SigninManagerFactory::GetInstance()->GetForProfile(profile); |
176 if (signin_manager) | 176 if (signin_manager) |
177 signin_manager->AddObserver(this); | 177 signin_manager->AddObserver(this); |
178 } | 178 } |
179 | 179 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 PrivetRegisterOperation* operation, | 294 PrivetRegisterOperation* operation, |
295 const std::string& token, | 295 const std::string& token, |
296 const GURL& url) { | 296 const GURL& url) { |
297 web_ui()->CallJavascriptFunction( | 297 web_ui()->CallJavascriptFunction( |
298 "local_discovery.onRegistrationConfirmedOnPrinter"); | 298 "local_discovery.onRegistrationConfirmedOnPrinter"); |
299 if (device_descriptions_.count(current_http_client_->GetName()) == 0) { | 299 if (device_descriptions_.count(current_http_client_->GetName()) == 0) { |
300 SendRegisterError(); | 300 SendRegisterError(); |
301 return; | 301 return; |
302 } | 302 } |
303 | 303 |
304 bool is_cloud_print = | |
305 device_descriptions_[current_http_client_->GetName()].type == | |
306 kDeviceTypePrinter; | |
307 | |
308 Profile* profile = Profile::FromWebUI(web_ui()); | 304 Profile* profile = Profile::FromWebUI(web_ui()); |
309 | 305 |
310 ProfileOAuth2TokenService* token_service = | 306 ProfileOAuth2TokenService* token_service = |
311 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 307 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
312 | 308 |
313 if (!token_service) { | 309 if (!token_service) { |
314 SendRegisterError(); | 310 SendRegisterError(); |
315 return; | 311 return; |
316 } | 312 } |
317 | 313 |
318 SigninManagerBase* signin_manager = | 314 SigninManagerBase* signin_manager = |
319 SigninManagerFactory::GetInstance()->GetForProfile(profile); | 315 SigninManagerFactory::GetInstance()->GetForProfile(profile); |
320 if (!signin_manager) { | 316 if (!signin_manager) { |
321 SendRegisterError(); | 317 SendRegisterError(); |
322 return; | 318 return; |
323 } | 319 } |
324 | 320 |
325 confirm_api_call_flow_.reset(new PrivetConfirmApiCallFlow( | 321 confirm_api_call_flow_.reset(new PrivetConfirmApiCallFlow( |
326 profile->GetRequestContext(), | 322 profile->GetRequestContext(), |
327 token_service, | 323 token_service, |
328 signin_manager->GetAuthenticatedAccountId(), | 324 signin_manager->GetAuthenticatedAccountId(), |
329 is_cloud_print, | |
330 token, | 325 token, |
331 base::Bind(&LocalDiscoveryUIHandler::OnConfirmDone, | 326 base::Bind(&LocalDiscoveryUIHandler::OnConfirmDone, |
332 base::Unretained(this)))); | 327 base::Unretained(this)))); |
333 confirm_api_call_flow_->Start(); | 328 confirm_api_call_flow_->Start(); |
334 } | 329 } |
335 | 330 |
336 void LocalDiscoveryUIHandler::OnPrivetRegisterError( | 331 void LocalDiscoveryUIHandler::OnPrivetRegisterError( |
337 PrivetRegisterOperation* operation, | 332 PrivetRegisterOperation* operation, |
338 const std::string& action, | 333 const std::string& action, |
339 PrivetRegisterOperation::FailureReason reason, | 334 PrivetRegisterOperation::FailureReason reason, |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 } | 640 } |
646 | 641 |
647 void LocalDiscoveryUIHandler::RefreshCloudPrintStatusFromService() { | 642 void LocalDiscoveryUIHandler::RefreshCloudPrintStatusFromService() { |
648 if (cloud_print_connector_ui_enabled_) | 643 if (cloud_print_connector_ui_enabled_) |
649 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> | 644 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> |
650 RefreshStatusFromService(); | 645 RefreshStatusFromService(); |
651 } | 646 } |
652 #endif // cloud print connector option stuff | 647 #endif // cloud print connector option stuff |
653 | 648 |
654 } // namespace local_discovery | 649 } // namespace local_discovery |
OLD | NEW |