| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/installer/util/auto_launch_util.h" | 5 #include "chrome/installer/util/auto_launch_util.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 path = path.Append(profile_directory); | 45 path = path.Append(profile_directory); |
| 46 | 46 |
| 47 std::string input(path.AsUTF8Unsafe()); | 47 std::string input(path.AsUTF8Unsafe()); |
| 48 uint8 hash[16]; | 48 uint8 hash[16]; |
| 49 crypto::SHA256HashString(input, hash, sizeof(hash)); | 49 crypto::SHA256HashString(input, hash, sizeof(hash)); |
| 50 std::string hash_string = base::HexEncode(hash, sizeof(hash)); | 50 std::string hash_string = base::HexEncode(hash, sizeof(hash)); |
| 51 return string16(kAutolaunchKeyValue) + | 51 return string16(kAutolaunchKeyValue) + |
| 52 ASCIIToWide("_") + ASCIIToWide(hash_string); | 52 ASCIIToWide("_") + ASCIIToWide(hash_string); |
| 53 } | 53 } |
| 54 | 54 |
| 55 bool WillLaunchAtLogin(const FilePath& application_path, | 55 bool WillLaunchAtLoginWithSwitch(const FilePath& application_path, |
| 56 const string16& profile_directory) { | 56 const string16& profile_directory, |
| 57 const std::string& command_line_switch) { |
| 57 string16 key_name(ProfileToKeyName(profile_directory)); | 58 string16 key_name(ProfileToKeyName(profile_directory)); |
| 58 string16 autolaunch; | 59 string16 autolaunch; |
| 59 if (!base::win::ReadCommandFromAutoRun( | 60 if (!base::win::ReadCommandFromAutoRun( |
| 60 HKEY_CURRENT_USER, key_name, &autolaunch)) { | 61 HKEY_CURRENT_USER, key_name, &autolaunch)) { |
| 61 return false; | 62 return false; |
| 62 } | 63 } |
| 63 | 64 |
| 64 FilePath chrome_exe(application_path); | 65 FilePath chrome_exe(application_path); |
| 65 if (chrome_exe.empty()) { | 66 if (chrome_exe.empty()) { |
| 66 if (!PathService::Get(base::DIR_EXE, &chrome_exe)) { | 67 if (!PathService::Get(base::DIR_EXE, &chrome_exe)) { |
| 67 NOTREACHED(); | 68 NOTREACHED(); |
| 68 return false; | 69 return false; |
| 69 } | 70 } |
| 70 } | 71 } |
| 71 chrome_exe = chrome_exe.Append(installer::kChromeExe); | 72 chrome_exe = chrome_exe.Append(installer::kChromeExe); |
| 72 | 73 |
| 73 return autolaunch.find(chrome_exe.value()) != string16::npos; | 74 if (autolaunch.find(chrome_exe.value()) == string16::npos) |
| 75 return false; |
| 76 |
| 77 return command_line_switch.empty() || |
| 78 autolaunch.find(ASCIIToUTF16(command_line_switch)) != string16::npos; |
| 74 } | 79 } |
| 75 | 80 |
| 76 void SetWillLaunchAtLogin(bool auto_launch, | 81 void SetWillLaunchAtLogin(const FilePath& application_path, |
| 77 const FilePath& application_path, | 82 const string16& profile_directory, |
| 78 const string16& profile_directory) { | 83 FlagSetting auto_start_feature, |
| 84 FlagSetting background_mode) { |
| 79 string16 key_name(ProfileToKeyName(profile_directory)); | 85 string16 key_name(ProfileToKeyName(profile_directory)); |
| 80 | 86 |
| 87 // Check which feature should be enabled. |
| 88 bool auto_start = |
| 89 auto_start_feature == FLAG_ENABLE || |
| 90 (auto_start_feature == FLAG_PRESERVE && |
| 91 WillLaunchAtLoginWithSwitch(application_path, |
| 92 profile_directory, |
| 93 switches::kAutoLaunchAtStartup)); |
| 94 bool in_background = |
| 95 background_mode == FLAG_ENABLE || |
| 96 (background_mode == FLAG_PRESERVE && |
| 97 WillLaunchAtLoginWithSwitch(application_path, |
| 98 profile_directory, |
| 99 switches::kNoStartupWindow)); |
| 100 |
| 81 // TODO(finnur): Convert this into a shortcut, instead of using the Run key. | 101 // TODO(finnur): Convert this into a shortcut, instead of using the Run key. |
| 82 if (auto_launch) { | 102 if (auto_start || in_background) { |
| 83 FilePath path(application_path); | 103 FilePath path(application_path); |
| 84 if (path.empty()) { | 104 if (path.empty()) { |
| 85 if (!PathService::Get(base::DIR_EXE, &path)) { | 105 if (!PathService::Get(base::DIR_EXE, &path)) { |
| 86 NOTREACHED(); | 106 NOTREACHED(); |
| 87 return; | 107 return; |
| 88 } | 108 } |
| 89 } | 109 } |
| 90 string16 cmd_line = ASCIIToUTF16("\""); | 110 string16 cmd_line = ASCIIToUTF16("\""); |
| 91 cmd_line += path.value(); | 111 cmd_line += path.value(); |
| 92 cmd_line += ASCIIToUTF16("\\"); | 112 cmd_line += ASCIIToUTF16("\\"); |
| 93 cmd_line += installer::kChromeExe; | 113 cmd_line += installer::kChromeExe; |
| 94 cmd_line += ASCIIToUTF16("\" --"); | 114 cmd_line += ASCIIToUTF16("\""); |
| 95 cmd_line += ASCIIToUTF16(switches::kAutoLaunchAtStartup); | |
| 96 | 115 |
| 97 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 116 if (in_background) { |
| 98 if (command_line.HasSwitch(switches::kUserDataDir)) { | |
| 99 cmd_line += ASCIIToUTF16(" --"); | 117 cmd_line += ASCIIToUTF16(" --"); |
| 100 cmd_line += ASCIIToUTF16(switches::kUserDataDir); | 118 cmd_line += ASCIIToUTF16(switches::kNoStartupWindow); |
| 119 } |
| 120 if (auto_start) { |
| 121 cmd_line += ASCIIToUTF16(" --"); |
| 122 cmd_line += ASCIIToUTF16(switches::kAutoLaunchAtStartup); |
| 123 |
| 124 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 125 if (command_line.HasSwitch(switches::kUserDataDir)) { |
| 126 cmd_line += ASCIIToUTF16(" --"); |
| 127 cmd_line += ASCIIToUTF16(switches::kUserDataDir); |
| 128 cmd_line += ASCIIToUTF16("=\""); |
| 129 cmd_line += |
| 130 command_line.GetSwitchValuePath(switches::kUserDataDir).value(); |
| 131 cmd_line += ASCIIToUTF16("\""); |
| 132 } |
| 133 |
| 134 cmd_line += ASCIIToUTF16(" --"); |
| 135 cmd_line += ASCIIToUTF16(switches::kProfileDirectory); |
| 101 cmd_line += ASCIIToUTF16("=\""); | 136 cmd_line += ASCIIToUTF16("=\""); |
| 102 cmd_line += | 137 cmd_line += profile_directory; |
| 103 command_line.GetSwitchValuePath(switches::kUserDataDir).value(); | |
| 104 cmd_line += ASCIIToUTF16("\""); | 138 cmd_line += ASCIIToUTF16("\""); |
| 105 } | 139 } |
| 106 | 140 |
| 107 cmd_line += ASCIIToUTF16(" --"); | |
| 108 cmd_line += ASCIIToUTF16(switches::kProfileDirectory); | |
| 109 cmd_line += ASCIIToUTF16("=\""); | |
| 110 cmd_line += profile_directory; | |
| 111 cmd_line += ASCIIToUTF16("\""); | |
| 112 | |
| 113 base::win::AddCommandToAutoRun( | 141 base::win::AddCommandToAutoRun( |
| 114 HKEY_CURRENT_USER, key_name, cmd_line); | 142 HKEY_CURRENT_USER, key_name, cmd_line); |
| 115 } else { | 143 } else { |
| 116 base::win::RemoveCommandFromAutoRun(HKEY_CURRENT_USER, key_name); | 144 base::win::RemoveCommandFromAutoRun(HKEY_CURRENT_USER, key_name); |
| 117 } | 145 } |
| 118 } | 146 } |
| 119 | 147 |
| 120 } // namespace auto_launch_util | 148 } // namespace auto_launch_util |
| OLD | NEW |