diff options
author | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-24 18:28:50 +0000 |
---|---|---|
committer | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-24 18:28:50 +0000 |
commit | c13e69a6641c879d9b2cf5cec8689e31243c1bd5 (patch) | |
tree | 165dce47d99e1af0fba930de74fd26a47f103325 /remoting | |
parent | d45c59d747638e5cf5329c8bbb75b96d47856d77 (diff) | |
download | chromium_src-c13e69a6641c879d9b2cf5cec8689e31243c1bd5.zip chromium_src-c13e69a6641c879d9b2cf5cec8689e31243c1bd5.tar.gz chromium_src-c13e69a6641c879d9b2cf5cec8689e31243c1bd5.tar.bz2 |
Restart Mac pref-pane if version mismatch detected
BUG=129226
TEST=manual
Review URL: https://chromiumcodereview.appspot.com/10413065
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138844 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rwxr-xr-x | remoting/host/installer/mac/PrivilegedHelperTools/org.chromium.chromoting.me2me.sh | 6 | ||||
-rw-r--r-- | remoting/host/me2me_preference_pane.h | 5 | ||||
-rw-r--r-- | remoting/host/me2me_preference_pane.mm | 43 |
3 files changed, 54 insertions, 0 deletions
diff --git a/remoting/host/installer/mac/PrivilegedHelperTools/org.chromium.chromoting.me2me.sh b/remoting/host/installer/mac/PrivilegedHelperTools/org.chromium.chromoting.me2me.sh index 4f949d2..810e498 100755 --- a/remoting/host/installer/mac/PrivilegedHelperTools/org.chromium.chromoting.me2me.sh +++ b/remoting/host/installer/mac/PrivilegedHelperTools/org.chromium.chromoting.me2me.sh @@ -12,6 +12,7 @@ HOST_EXE=$CONFIG_DIR/$NAME.me2me_host.app/Contents/MacOS/remoting_me2me_host PLIST_FILE=$CONFIG_DIR/$NAME.me2me_host.app/Contents/Info.plist ENABLED_FILE=$CONFIG_DIR/$NAME.me2me_enabled CONFIG_FILE=$CONFIG_DIR/$NAME.json +PREF_PANE_BUNDLE=/Library/PreferencePanes/$NAME.prefPane # The exit code returned by 'wait' when a process is terminated by SIGTERM. SIGTERM_EXIT_CODE=143 @@ -87,6 +88,11 @@ elif [[ "$1" = "--save-config" ]]; then cat > "$CONFIG_FILE" elif [[ "$1" = "--host-version" ]]; then PlistBuddy -c "Print CFBundleVersion" "$PLIST_FILE" +elif [[ "$1" = "--relaunch-prefpane" ]]; then + # Wait for the parent (System Preferences applet) to die, by reading from + # stdin until the pipe is broken. + cat 2>/dev/null || true + open "$PREF_PANE_BUNDLE" elif [[ "$1" = "--run-from-launchd" ]]; then run_host else diff --git a/remoting/host/me2me_preference_pane.h b/remoting/host/me2me_preference_pane.h index 7b93d8d..52e6ad5 100644 --- a/remoting/host/me2me_preference_pane.h +++ b/remoting/host/me2me_preference_pane.h @@ -107,4 +107,9 @@ class JsonHostConfig { inputData:(const std::string&)input_data; - (BOOL)sendJobControlMessage:(const char*)launch_key; +// Compare the version of the running pref-pane against the installed version. +// If the versions are mismatched, return YES and restart the System +// Preferences application, so the correct version of this pref-pane is loaded. +- (BOOL)restartPanelIfDifferentVersionInstalled; + @end diff --git a/remoting/host/me2me_preference_pane.mm b/remoting/host/me2me_preference_pane.mm index da116af..0412f6d 100644 --- a/remoting/host/me2me_preference_pane.mm +++ b/remoting/host/me2me_preference_pane.mm @@ -276,6 +276,12 @@ std::string JsonHostConfig::GetSerializedData() const { } - (void)readNewConfig { + if ([self restartPanelIfDifferentVersionInstalled]) { + // Don't read any new config if the version is mismatched. Return control + // to the main run-loop instead, so the application can be terminated. + return; + } + std::string file; if (!GetTemporaryConfigFilePath(&file)) { LOG(ERROR) << "Failed to get path of configuration data."; @@ -518,4 +524,41 @@ std::string JsonHostConfig::GetSerializedData() const { userInfo:nil]; } +- (BOOL)restartPanelIfDifferentVersionInstalled { + NSBundle* this_bundle = [NSBundle bundleForClass:[self class]]; + NSDictionary* this_plist = [this_bundle infoDictionary]; + NSString* this_version = [this_plist objectForKey:@"CFBundleVersion"]; + + NSString* bundle_path = [this_bundle bundlePath]; + NSString* plist_path = + [bundle_path stringByAppendingString:@"/Contents/Info.plist"]; + NSDictionary* disk_plist = + [NSDictionary dictionaryWithContentsOfFile:plist_path]; + NSString* disk_version = [disk_plist objectForKey:@"CFBundleVersion"]; + + if (disk_version == nil) { + LOG(ERROR) << "Failed to get installed version information"; + [self showError]; + return NO; + } + + if ([this_version isEqualToString:disk_version]) { + return NO; + } else { + // Terminate and relaunch System Preferences. + + // TODO(lambroslambrou): Improve this when System Preferences supports + // dynamic reloading of pref-panes. + NSTask* task = [[NSTask alloc] init]; + NSArray* arguments = [NSArray arrayWithObjects:@"--relaunch-prefpane", nil]; + [task setLaunchPath:[NSString stringWithUTF8String:kHelperTool]]; + [task setArguments:arguments]; + [task setStandardInput:[NSPipe pipe]]; + [task launch]; + [task release]; + [NSApp terminate:nil]; + return YES; + } +} + @end |