diff options
author | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 00:44:11 +0000 |
---|---|---|
committer | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 00:44:11 +0000 |
commit | 7bb8abfae13ca4aebb24ca379f60041f31e7da44 (patch) | |
tree | c1df67c3f85ce477fb6570a58665041b18832b18 /remoting | |
parent | 4f98272099b17305262c69be4461da976feef328 (diff) | |
download | chromium_src-7bb8abfae13ca4aebb24ca379f60041f31e7da44.zip chromium_src-7bb8abfae13ca4aebb24ca379f60041f31e7da44.tar.gz chromium_src-7bb8abfae13ca4aebb24ca379f60041f31e7da44.tar.bz2 |
Implemented getVersion framework.
BUG=125998
TEST=Manual
Review URL: https://chromiumcodereview.appspot.com/10356118
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136465 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/plugin/daemon_controller.h | 7 | ||||
-rw-r--r-- | remoting/host/plugin/daemon_controller_linux.cc | 7 | ||||
-rw-r--r-- | remoting/host/plugin/daemon_controller_mac.cc | 6 | ||||
-rw-r--r-- | remoting/host/plugin/daemon_controller_win.cc | 6 | ||||
-rw-r--r-- | remoting/host/plugin/host_script_object.cc | 43 | ||||
-rw-r--r-- | remoting/host/plugin/host_script_object.h | 11 | ||||
-rw-r--r-- | remoting/webapp/host_controller.js | 9 | ||||
-rw-r--r-- | remoting/webapp/host_plugin_proto.js | 9 |
8 files changed, 96 insertions, 2 deletions
diff --git a/remoting/host/plugin/daemon_controller.h b/remoting/host/plugin/daemon_controller.h index 281d258..04fde56b 100644 --- a/remoting/host/plugin/daemon_controller.h +++ b/remoting/host/plugin/daemon_controller.h @@ -76,6 +76,9 @@ class DaemonController { // starting/stopping the service. typedef base::Callback<void (AsyncResult result)> CompletionCallback; + // Callback type for GetVersion(). + typedef base::Callback<void (const std::string&)> GetVersionCallback; + virtual ~DaemonController() {} // Return the "installed/running" state of the daemon process. @@ -122,6 +125,10 @@ class DaemonController { // elevation prompts properly. virtual void SetWindow(void* window_handle) = 0; + // Get the version of the daemon as a dotted decimal string of the form + // major.minor.build.patch, if it is installed, or "" otherwise. + virtual void GetVersion(const GetVersionCallback& done_callback) = 0; + static scoped_ptr<DaemonController> Create(); }; diff --git a/remoting/host/plugin/daemon_controller_linux.cc b/remoting/host/plugin/daemon_controller_linux.cc index 52afb0c..7ed9440 100644 --- a/remoting/host/plugin/daemon_controller_linux.cc +++ b/remoting/host/plugin/daemon_controller_linux.cc @@ -64,6 +64,7 @@ class DaemonControllerLinux : public remoting::DaemonController { const CompletionCallback& done_callback) OVERRIDE; virtual void Stop(const CompletionCallback& done_callback) OVERRIDE; virtual void SetWindow(void* window_handle) OVERRIDE; + virtual void GetVersion(const GetVersionCallback& done_callback) OVERRIDE; private: FilePath GetConfigPath(); @@ -185,6 +186,12 @@ void DaemonControllerLinux::SetWindow(void* window_handle) { // noop } +void DaemonControllerLinux::GetVersion( + const GetVersionCallback& done_callback) { + NOTIMPLEMENTED(); + done_callback.Run(""); +} + FilePath DaemonControllerLinux::GetConfigPath() { std::string filename = "host#" + GetMd5(net::GetHostName()) + ".json"; return file_util::GetHomeDir(). diff --git a/remoting/host/plugin/daemon_controller_mac.cc b/remoting/host/plugin/daemon_controller_mac.cc index 136eef0..ad28eca 100644 --- a/remoting/host/plugin/daemon_controller_mac.cc +++ b/remoting/host/plugin/daemon_controller_mac.cc @@ -66,6 +66,7 @@ class DaemonControllerMac : public remoting::DaemonController { const CompletionCallback& done_callback) OVERRIDE; virtual void Stop(const CompletionCallback& done_callback) OVERRIDE; virtual void SetWindow(void* window_handle) OVERRIDE; + virtual void GetVersion(const GetVersionCallback& done_callback) OVERRIDE; private: void DoGetConfig(const GetConfigCallback& callback); @@ -142,6 +143,11 @@ void DaemonControllerMac::SetWindow(void* window_handle) { // noop } +void DaemonControllerMac::GetVersion(const GetVersionCallback& done_callback) { + NOTIMPLEMENTED(); + done_callback.Run(""); +} + void DaemonControllerMac::DoGetConfig(const GetConfigCallback& callback) { FilePath config_path(kHostConfigFile); JsonHostConfig host_config(config_path); diff --git a/remoting/host/plugin/daemon_controller_win.cc b/remoting/host/plugin/daemon_controller_win.cc index c7b484d..937728f 100644 --- a/remoting/host/plugin/daemon_controller_win.cc +++ b/remoting/host/plugin/daemon_controller_win.cc @@ -81,6 +81,7 @@ class DaemonControllerWin : public remoting::DaemonController { const CompletionCallback& done_callback) OVERRIDE; virtual void Stop(const CompletionCallback& done_callback) OVERRIDE; virtual void SetWindow(void* window_handle) OVERRIDE; + virtual void GetVersion(const GetVersionCallback& done_callback) OVERRIDE; private: // Activates an unprivileged instance of the daemon controller and caches it. @@ -246,6 +247,11 @@ void DaemonControllerWin::SetWindow(void* window_handle) { window_handle)); } +void DaemonControllerWin::GetVersion(const GetVersionCallback& done_callback) { + NOTIMPLEMENTED(); + done_callback.Run(""); +} + HRESULT DaemonControllerWin::ActivateController() { DCHECK(worker_thread_.message_loop_proxy()->BelongsToCurrentThread()); diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc index 760d916..83f201f 100644 --- a/remoting/host/plugin/host_script_object.cc +++ b/remoting/host/plugin/host_script_object.cc @@ -51,6 +51,7 @@ const char* kFuncNameGetPinHash = "getPinHash"; const char* kFuncNameGenerateKeyPair = "generateKeyPair"; const char* kFuncNameUpdateDaemonConfig = "updateDaemonConfig"; const char* kFuncNameGetDaemonConfig = "getDaemonConfig"; +const char* kFuncNameGetDaemonVersion = "getDaemonVersion"; const char* kFuncNameStartDaemon = "startDaemon"; const char* kFuncNameStopDaemon = "stopDaemon"; @@ -158,6 +159,7 @@ bool HostNPScriptObject::HasMethod(const std::string& method_name) { method_name == kFuncNameGenerateKeyPair || method_name == kFuncNameUpdateDaemonConfig || method_name == kFuncNameGetDaemonConfig || + method_name == kFuncNameGetDaemonVersion || method_name == kFuncNameStartDaemon || method_name == kFuncNameStopDaemon); } @@ -193,6 +195,8 @@ bool HostNPScriptObject::Invoke(const std::string& method_name, return UpdateDaemonConfig(args, arg_count, result); } else if (method_name == kFuncNameGetDaemonConfig) { return GetDaemonConfig(args, arg_count, result); + } else if (method_name == kFuncNameGetDaemonVersion) { + return GetDaemonVersion(args, arg_count, result); } else if (method_name == kFuncNameStartDaemon) { return StartDaemon(args, arg_count, result); } else if (method_name == kFuncNameStopDaemon) { @@ -365,6 +369,7 @@ bool HostNPScriptObject::Enumerate(std::vector<std::string>* values) { kFuncNameGenerateKeyPair, kFuncNameUpdateDaemonConfig, kFuncNameGetDaemonConfig, + kFuncNameGetDaemonVersion, kFuncNameStartDaemon, kFuncNameStopDaemon }; @@ -724,6 +729,29 @@ bool HostNPScriptObject::GetDaemonConfig(const NPVariant* args, return true; } +bool HostNPScriptObject::GetDaemonVersion(const NPVariant* args, + uint32_t arg_count, + NPVariant* result) { + if (arg_count != 1) { + SetException("getDaemonVersion: bad number of arguments"); + return false; + } + + ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0])); + if (!callback_obj.get()) { + SetException("getDaemonVersion: invalid callback parameter"); + return false; + } + + // We control lifetime of the |daemon_controller_| so it's safe to + // use base::Unretained() here. + daemon_controller_->GetVersion( + base::Bind(&HostNPScriptObject::InvokeGetDaemonVersionCallback, + base::Unretained(this), callback_obj)); + + return true; +} + bool HostNPScriptObject::StartDaemon(const NPVariant* args, uint32_t arg_count, NPVariant* result) { @@ -1089,6 +1117,21 @@ void HostNPScriptObject::InvokeGetDaemonConfigCallback( g_npnetscape_funcs->releasevariantvalue(&config_val); } +void HostNPScriptObject::InvokeGetDaemonVersionCallback( + const ScopedRefNPObject& callback, const std::string& version) { + if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { + plugin_message_loop_proxy_->PostTask( + FROM_HERE, base::Bind( + &HostNPScriptObject::InvokeGetDaemonVersionCallback, + base::Unretained(this), callback, version)); + return; + } + + NPVariant version_val = NPVariantFromString(version); + InvokeAndIgnoreResult(callback.get(), &version_val, 1); + g_npnetscape_funcs->releasevariantvalue(&version_val); +} + void HostNPScriptObject::LogDebugInfo(const std::string& message) { DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); if (log_debug_info_func_.get()) { diff --git a/remoting/host/plugin/host_script_object.h b/remoting/host/plugin/host_script_object.h index adfd075..d121266 100644 --- a/remoting/host/plugin/host_script_object.h +++ b/remoting/host/plugin/host_script_object.h @@ -153,6 +153,13 @@ class HostNPScriptObject : public HostStatusObserver { uint32_t arg_count, NPVariant* result); + // Loads daemon config version. The first argument specifies the + // callback to be called with the config is loaded. The version is + // returned as a dotted version string, described in daemon_controller.h. + bool GetDaemonVersion(const NPVariant* args, + uint32_t arg_count, + NPVariant* result); + // Start the daemon process with the specified config. Args are: // string config // function(number) done_callback @@ -229,6 +236,10 @@ class HostNPScriptObject : public HostStatusObserver { void InvokeGetDaemonConfigCallback(const ScopedRefNPObject& callback, scoped_ptr<base::DictionaryValue> config); + // Callback handler for DaemonController::GetVersion(). + void InvokeGetDaemonVersionCallback(const ScopedRefNPObject& callback, + const std::string& version); + ////////////////////////////////////////////////////////// // Basic helper methods used for both It2Me and Me2me. diff --git a/remoting/webapp/host_controller.js b/remoting/webapp/host_controller.js index 6284a1e..c78079c 100644 --- a/remoting/webapp/host_controller.js +++ b/remoting/webapp/host_controller.js @@ -16,6 +16,15 @@ remoting.HostController = function() { this.container_.appendChild(this.plugin_); /** @type {remoting.Host?} */ this.localHost = null; + /** @param {string} version */ + var printVersion = function(version) { + if (version == '') { + console.log('Host not installed.'); + } else { + console.log('Host version:', version); + } + }; + this.plugin_.getDaemonVersion(printVersion); }; // Note that the values in the enums below are copied from diff --git a/remoting/webapp/host_plugin_proto.js b/remoting/webapp/host_plugin_proto.js index a0ada57..da1697f 100644 --- a/remoting/webapp/host_plugin_proto.js +++ b/remoting/webapp/host_plugin_proto.js @@ -53,11 +53,16 @@ remoting.HostPlugin.prototype.generateKeyPair = function(callback) {}; remoting.HostPlugin.prototype.updateDaemonConfig = function(config, callback) {}; -/** @param {function(string):void} callback Callback to be called for - * the config. +/** @param {function(string):void} callback Callback to be called with + * the config. * @return {void} Nothing. */ remoting.HostPlugin.prototype.getDaemonConfig = function(callback) {}; +/** @param {function(string):void} callback Callback to be called with + * the version, as a dotted string. + * @return {void} Nothing. */ +remoting.HostPlugin.prototype.getDaemonVersion = function(callback) {}; + /** @param {string} config Host configuration. * @param {function(remoting.HostController.AsyncResult):void} callback * Callback to be called when finished. |