Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/string_number_conversions.h" | |
| 10 #include "base/string16.h" | 11 #include "base/string16.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "base/win/win_util.h" | 13 #include "base/win/win_util.h" |
| 13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/chrome_version_info.h" | |
| 14 #include "chrome/installer/util/util_constants.h" | 16 #include "chrome/installer/util/util_constants.h" |
| 17 #include "crypto/sha2.h" | |
| 15 | 18 |
| 16 namespace auto_launch_util { | 19 namespace auto_launch_util { |
| 17 | 20 |
| 18 // The name of the Chrome Auto-launch key under the Run key. | 21 // The prefix of the Chrome Auto-launch key under the Run key. |
| 19 const wchar_t kAutolaunchKeyValue[] = L"GoogleChromeAutoLaunch"; | 22 const wchar_t kAutolaunchKeyValue[] = L"GoogleChromeAutoLaunch"; |
| 20 | 23 |
| 21 bool WillLaunchAtLogin(const FilePath& application_path) { | 24 // A helper function that takes a |profile_path| and builds a registry key |
| 25 // name to use when deciding where to read/write the auto-launch value | |
| 26 // to/from. It takes into account the name of the profile (so that different | |
| 27 // installations of Chrome don't conflict, and so the in the future different | |
| 28 // profiles can be auto-launched (or not) separately). | |
| 29 string16 ProfileToKeyName(const FilePath& profile_path) { | |
|
grt (UTC plus 2)
2012/02/01 18:45:15
i'm concerned that profile_path may be equivalent
Finnur
2012/02/06 16:30:36
I'm hesitant to make it Chrome only, as that makes
| |
| 30 std::string input = profile_path.AsUTF8Unsafe(); | |
|
grt (UTC plus 2)
2012/02/01 18:45:15
nit: input(profile_path.AsUTF8Unsafe());
| |
| 31 uint8 hash[16]; | |
| 32 crypto::SHA256HashString(input, hash, sizeof(hash)); | |
| 33 std::string hash_string = base::HexEncode(hash, sizeof(hash)); | |
| 34 return string16(kAutolaunchKeyValue) + | |
| 35 ASCIIToWide("_") + ASCIIToWide(hash_string); | |
|
grt (UTC plus 2)
2012/02/01 18:45:15
nit: either indent 4 from the previous line, or pu
| |
| 36 } | |
| 37 | |
| 38 bool WillLaunchAtLogin(const FilePath& application_path, | |
| 39 const FilePath& profile_path) { | |
| 40 string16 key_name = ProfileToKeyName(profile_path); | |
|
grt (UTC plus 2)
2012/02/01 18:45:15
nit: key_name(ProfileToKeyName(profile_path));
| |
| 22 string16 autolaunch; | 41 string16 autolaunch; |
| 23 if (!base::win::ReadCommandFromAutoRun( | 42 if (!base::win::ReadCommandFromAutoRun( |
| 24 HKEY_CURRENT_USER, kAutolaunchKeyValue, &autolaunch)) { | 43 HKEY_CURRENT_USER, key_name, &autolaunch)) { |
| 25 return false; | 44 return false; |
| 26 } | 45 } |
| 27 | 46 |
| 28 FilePath chrome_exe(application_path); | 47 FilePath chrome_exe(application_path); |
| 29 if (chrome_exe.empty()) { | 48 if (chrome_exe.empty()) { |
| 30 if (!PathService::Get(base::DIR_EXE, &chrome_exe)) { | 49 if (!PathService::Get(base::DIR_EXE, &chrome_exe)) { |
| 31 NOTREACHED(); | 50 NOTREACHED(); |
| 32 return false; | 51 return false; |
| 33 } | 52 } |
| 34 } | 53 } |
| 35 chrome_exe = chrome_exe.Append(installer::kChromeExe); | 54 chrome_exe = chrome_exe.Append(installer::kChromeExe); |
| 36 | 55 |
| 37 return autolaunch.find(chrome_exe.value()) != string16::npos; | 56 return autolaunch.find(chrome_exe.value()) != string16::npos; |
| 38 } | 57 } |
| 39 | 58 |
| 40 void SetWillLaunchAtLogin(bool auto_launch, const FilePath& application_path) { | 59 void SetWillLaunchAtLogin(bool auto_launch, |
| 60 const FilePath& application_path, | |
| 61 const FilePath& profile_path) { | |
| 62 string16 key_name = ProfileToKeyName(profile_path); | |
|
grt (UTC plus 2)
2012/02/01 18:45:15
nit: key_name(...);
| |
| 63 | |
| 41 // TODO(finnur): Convert this into a shortcut, instead of using the Run key. | 64 // TODO(finnur): Convert this into a shortcut, instead of using the Run key. |
| 42 if (auto_launch) { | 65 if (auto_launch) { |
| 43 FilePath path(application_path); | 66 FilePath path(application_path); |
| 44 if (path.empty()) { | 67 if (path.empty()) { |
| 45 if (!PathService::Get(base::DIR_EXE, &path)) { | 68 if (!PathService::Get(base::DIR_EXE, &path)) { |
| 46 NOTREACHED(); | 69 NOTREACHED(); |
| 47 return; | 70 return; |
| 48 } | 71 } |
| 49 } | 72 } |
| 50 string16 cmd_line = ASCIIToUTF16("\""); | 73 string16 cmd_line = ASCIIToUTF16("\""); |
| 51 cmd_line += path.value(); | 74 cmd_line += path.value(); |
| 52 cmd_line += ASCIIToUTF16("\\"); | 75 cmd_line += ASCIIToUTF16("\\"); |
| 53 cmd_line += installer::kChromeExe; | 76 cmd_line += installer::kChromeExe; |
| 54 cmd_line += ASCIIToUTF16("\" --"); | 77 cmd_line += ASCIIToUTF16("\" --"); |
| 55 cmd_line += ASCIIToUTF16(switches::kAutoLaunchAtStartup); | 78 cmd_line += ASCIIToUTF16(switches::kAutoLaunchAtStartup); |
| 79 cmd_line += ASCIIToUTF16(" --"); | |
| 80 cmd_line += ASCIIToUTF16(switches::kProfileDirectory); | |
| 81 cmd_line += ASCIIToUTF16("=\""); | |
| 82 cmd_line += profile_path.BaseName().value(); | |
| 83 cmd_line += ASCIIToUTF16("\""); | |
| 56 | 84 |
| 57 base::win::AddCommandToAutoRun( | 85 base::win::AddCommandToAutoRun( |
| 58 HKEY_CURRENT_USER, kAutolaunchKeyValue, cmd_line); | 86 HKEY_CURRENT_USER, key_name, cmd_line); |
| 59 } else { | 87 } else { |
| 60 base::win::RemoveCommandFromAutoRun(HKEY_CURRENT_USER, kAutolaunchKeyValue); | 88 base::win::RemoveCommandFromAutoRun(HKEY_CURRENT_USER, key_name); |
| 61 } | 89 } |
| 62 } | 90 } |
| 63 | 91 |
| 64 } // namespace auto_launch_util | 92 } // namespace auto_launch_util |
| OLD | NEW |