1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/remoting/setup_flow_start_host_step.h" 6 7 #include "chrome/browser/remoting/setup_flow_get_status_step.h" 8 #include "chrome/browser/service/service_process_control.h" 9 #include "chrome/browser/service/service_process_control_manager.h" 10 #include "grit/generated_resources.h" 11 #include "ui/base/l10n/l10n_util.h" 12 13 namespace remoting { 14 SetupFlowStartHostStep()15SetupFlowStartHostStep::SetupFlowStartHostStep() 16 : ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), 17 status_requested_(false) { 18 } 19 ~SetupFlowStartHostStep()20SetupFlowStartHostStep::~SetupFlowStartHostStep() { 21 if (process_control_) 22 process_control_->RemoveMessageHandler(this); 23 } 24 HandleMessage(const std::string & message,const Value * arg)25void SetupFlowStartHostStep::HandleMessage(const std::string& message, 26 const Value* arg) { 27 } 28 Cancel()29void SetupFlowStartHostStep::Cancel() { 30 if (process_control_) 31 process_control_->RemoveMessageHandler(this); 32 } 33 OnRemotingHostInfo(const remoting::ChromotingHostInfo & host_info)34void SetupFlowStartHostStep::OnRemotingHostInfo( 35 const remoting::ChromotingHostInfo& host_info) { 36 if (status_requested_) { 37 status_requested_ = false; 38 if (host_info.enabled) { 39 FinishStep(new SetupFlowDoneStep()); 40 } else { 41 FinishStep(new SetupFlowStartHostErrorStep()); 42 } 43 } 44 } 45 DoStart()46void SetupFlowStartHostStep::DoStart() { 47 flow()->web_ui()->CallJavascriptFunction("showSettingUp"); 48 49 process_control_ = 50 ServiceProcessControlManager::GetInstance()->GetProcessControl( 51 flow()->profile()); 52 if (!process_control_ || !process_control_->is_connected()) { 53 FinishStep(new SetupFlowStartHostErrorStep()); 54 } 55 56 process_control_->SetRemotingHostCredentials(flow()->context()->login, 57 flow()->context()->talk_token); 58 process_control_->EnableRemotingHost(); 59 RequestStatus(); 60 } 61 RequestStatus()62void SetupFlowStartHostStep::RequestStatus() { 63 DCHECK(!status_requested_); 64 65 if (!process_control_->RequestRemotingHostStatus()) { 66 FinishStep(new SetupFlowStartHostErrorStep()); 67 return; 68 } 69 70 status_requested_ = true; 71 process_control_->AddMessageHandler(this); 72 } 73 SetupFlowStartHostErrorStep()74SetupFlowStartHostErrorStep::SetupFlowStartHostErrorStep() { } ~SetupFlowStartHostErrorStep()75SetupFlowStartHostErrorStep::~SetupFlowStartHostErrorStep() { } 76 GetErrorMessage()77string16 SetupFlowStartHostErrorStep::GetErrorMessage() { 78 return l10n_util::GetStringUTF16(IDS_REMOTING_SERVICE_PROCESS_FAILED_MESSAGE); 79 } 80 Retry()81void SetupFlowStartHostErrorStep::Retry() { 82 // When retrying we retry from the GetStatus step because it may be 83 // necessary to start service process. 84 FinishStep(new SetupFlowGetStatusStep()); 85 } 86 87 } // namespace remoting 88