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_register_step.h" 6 7 #include "chrome/browser/prefs/pref_service.h" 8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/remoting/setup_flow_login_step.h" 10 #include "chrome/browser/remoting/setup_flow_start_host_step.h" 11 #include "chrome/common/pref_names.h" 12 #include "grit/generated_resources.h" 13 #include "ui/base/l10n/l10n_util.h" 14 15 namespace remoting { 16 17 SetupFlowRegisterStep::SetupFlowRegisterStep() { } 18 SetupFlowRegisterStep::~SetupFlowRegisterStep() { } 19 20 void SetupFlowRegisterStep::HandleMessage(const std::string& message, 21 const Value* arg) { 22 } 23 24 void SetupFlowRegisterStep::Cancel() { 25 // Don't need to do anything here. The request will be canceled when 26 // |request_| is destroyed. 27 } 28 29 void SetupFlowRegisterStep::DoStart() { 30 flow()->web_ui()->CallJavascriptFunction("showSettingUp"); 31 32 request_.reset(new DirectoryAddRequest( 33 flow()->profile()->GetRequestContext())); 34 request_->AddHost(flow()->context()->host_info, 35 flow()->context()->remoting_token, 36 NewCallback(this, &SetupFlowRegisterStep::OnRequestDone)); 37 } 38 39 void SetupFlowRegisterStep::SetRemotingEnabled() { 40 flow()->profile()->GetPrefs()->SetBoolean( 41 prefs::kRemotingHasSetupCompleted, true); 42 } 43 44 void SetupFlowRegisterStep::OnRequestDone(DirectoryAddRequest::Result result, 45 const std::string& error_message) { 46 switch (result) { 47 case DirectoryAddRequest::SUCCESS: 48 SetRemotingEnabled(); 49 FinishStep(new SetupFlowStartHostStep()); 50 break; 51 case DirectoryAddRequest::ERROR_EXISTS: 52 SetRemotingEnabled(); 53 LOG(INFO) << "Chromoting host is already registered."; 54 FinishStep(new SetupFlowStartHostStep()); 55 break; 56 case DirectoryAddRequest::ERROR_AUTH: 57 LOG(ERROR) << "Access denied by Chromoting Directory."; 58 FinishStep(new SetupFlowLoginStep(l10n_util::GetStringUTF16( 59 IDS_REMOTING_REGISTRATION_ACCESS_DENIED))); 60 break; 61 default: 62 LOG(ERROR) << "Chromoting Host registration failed: " 63 << error_message << " (" << result << ")"; 64 FinishStep(new SetupFlowRegisterErrorStep()); 65 break; 66 } 67 } 68 69 SetupFlowRegisterErrorStep::SetupFlowRegisterErrorStep() { } 70 SetupFlowRegisterErrorStep::~SetupFlowRegisterErrorStep() { } 71 72 string16 SetupFlowRegisterErrorStep::GetErrorMessage() { 73 return l10n_util::GetStringUTF16(IDS_REMOTING_REGISTRATION_FAILED_MESSAGE); 74 } 75 76 void SetupFlowRegisterErrorStep::Retry() { 77 // When retrying we retry from the GetStatus step because it may be 78 // necessary to start service process. 79 FinishStep(new SetupFlowRegisterStep()); 80 } 81 82 } // namespace remoting 83