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/remoting_options_handler.h" 6 7 #include "base/utf_string_conversions.h" 8 #include "base/values.h" 9 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/service/service_process_control_manager.h" 12 #include "chrome/common/pref_names.h" 13 #include "chrome/common/remoting/chromoting_host_info.h" 14 #include "content/browser/webui/web_ui.h" 15 #include "grit/generated_resources.h" 16 #include "ui/base/l10n/l10n_util.h" 17 18 namespace remoting { 19 RemotingOptionsHandler()20RemotingOptionsHandler::RemotingOptionsHandler() 21 : web_ui_(NULL), 22 process_control_(NULL) { 23 } 24 ~RemotingOptionsHandler()25RemotingOptionsHandler::~RemotingOptionsHandler() { 26 if (process_control_) 27 process_control_->RemoveMessageHandler(this); 28 } 29 Init(WebUI * web_ui)30void RemotingOptionsHandler::Init(WebUI* web_ui) { 31 web_ui_ = web_ui; 32 33 process_control_ = 34 ServiceProcessControlManager::GetInstance()->GetProcessControl( 35 web_ui_->GetProfile()); 36 process_control_->AddMessageHandler(this); 37 38 if (!process_control_->RequestRemotingHostStatus()) { 39 // Assume that host is not started if we can't request status. 40 SetStatus(false, ""); 41 } 42 web_ui_->GetProfile()->GetPrefs()->SetBoolean( 43 prefs::kRemotingHasSetupCompleted, false); 44 } 45 46 // ServiceProcessControl::MessageHandler interface OnRemotingHostInfo(const remoting::ChromotingHostInfo & host_info)47void RemotingOptionsHandler::OnRemotingHostInfo( 48 const remoting::ChromotingHostInfo& host_info) { 49 SetStatus(host_info.enabled, host_info.login); 50 } 51 SetStatus(bool enabled,const std::string & login)52void RemotingOptionsHandler::SetStatus( 53 bool enabled, const std::string& login) { 54 string16 status; 55 if (enabled) { 56 status = l10n_util::GetStringFUTF16(IDS_REMOTING_STATUS_ENABLED_TEXT, 57 UTF8ToUTF16(login)); 58 } else { 59 status = l10n_util::GetStringUTF16(IDS_REMOTING_STATUS_DISABLED_TEXT); 60 } 61 62 FundamentalValue enabled_value(enabled); 63 StringValue status_value(status); 64 web_ui_->CallJavascriptFunction("options.AdvancedOptions.SetRemotingStatus", 65 enabled_value, status_value); 66 } 67 68 } // namespace remoting 69