Chromium Code Reviews| Index: chrome/installer/util/auto_launch_util.cc |
| =================================================================== |
| --- chrome/installer/util/auto_launch_util.cc (revision 119922) |
| +++ chrome/installer/util/auto_launch_util.cc (working copy) |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -7,21 +7,40 @@ |
| #include "base/file_path.h" |
| #include "base/logging.h" |
| #include "base/path_service.h" |
| +#include "base/string_number_conversions.h" |
| #include "base/string16.h" |
| #include "base/utf_string_conversions.h" |
| #include "base/win/win_util.h" |
| #include "chrome/common/chrome_switches.h" |
| +#include "chrome/common/chrome_version_info.h" |
| #include "chrome/installer/util/util_constants.h" |
| +#include "crypto/sha2.h" |
| namespace auto_launch_util { |
| -// The name of the Chrome Auto-launch key under the Run key. |
| +// The prefix of the Chrome Auto-launch key under the Run key. |
| const wchar_t kAutolaunchKeyValue[] = L"GoogleChromeAutoLaunch"; |
| -bool WillLaunchAtLogin(const FilePath& application_path) { |
| +// A helper function that takes a |profile_path| and builds a registry key |
| +// name to use when deciding where to read/write the auto-launch value |
| +// to/from. It takes into account the name of the profile (so that different |
| +// installations of Chrome don't conflict, and so the in the future different |
| +// profiles can be auto-launched (or not) separately). |
| +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
|
| + std::string input = profile_path.AsUTF8Unsafe(); |
|
grt (UTC plus 2)
2012/02/01 18:45:15
nit: input(profile_path.AsUTF8Unsafe());
|
| + uint8 hash[16]; |
| + crypto::SHA256HashString(input, hash, sizeof(hash)); |
| + std::string hash_string = base::HexEncode(hash, sizeof(hash)); |
| + return string16(kAutolaunchKeyValue) + |
| + ASCIIToWide("_") + ASCIIToWide(hash_string); |
|
grt (UTC plus 2)
2012/02/01 18:45:15
nit: either indent 4 from the previous line, or pu
|
| +} |
| + |
| +bool WillLaunchAtLogin(const FilePath& application_path, |
| + const FilePath& profile_path) { |
| + string16 key_name = ProfileToKeyName(profile_path); |
|
grt (UTC plus 2)
2012/02/01 18:45:15
nit: key_name(ProfileToKeyName(profile_path));
|
| string16 autolaunch; |
| if (!base::win::ReadCommandFromAutoRun( |
| - HKEY_CURRENT_USER, kAutolaunchKeyValue, &autolaunch)) { |
| + HKEY_CURRENT_USER, key_name, &autolaunch)) { |
| return false; |
| } |
| @@ -37,7 +56,11 @@ |
| return autolaunch.find(chrome_exe.value()) != string16::npos; |
| } |
| -void SetWillLaunchAtLogin(bool auto_launch, const FilePath& application_path) { |
| +void SetWillLaunchAtLogin(bool auto_launch, |
| + const FilePath& application_path, |
| + const FilePath& profile_path) { |
| + string16 key_name = ProfileToKeyName(profile_path); |
|
grt (UTC plus 2)
2012/02/01 18:45:15
nit: key_name(...);
|
| + |
| // TODO(finnur): Convert this into a shortcut, instead of using the Run key. |
| if (auto_launch) { |
| FilePath path(application_path); |
| @@ -53,11 +76,16 @@ |
| cmd_line += installer::kChromeExe; |
| cmd_line += ASCIIToUTF16("\" --"); |
| cmd_line += ASCIIToUTF16(switches::kAutoLaunchAtStartup); |
| + cmd_line += ASCIIToUTF16(" --"); |
| + cmd_line += ASCIIToUTF16(switches::kProfileDirectory); |
| + cmd_line += ASCIIToUTF16("=\""); |
| + cmd_line += profile_path.BaseName().value(); |
| + cmd_line += ASCIIToUTF16("\""); |
| base::win::AddCommandToAutoRun( |
| - HKEY_CURRENT_USER, kAutolaunchKeyValue, cmd_line); |
| + HKEY_CURRENT_USER, key_name, cmd_line); |
| } else { |
| - base::win::RemoveCommandFromAutoRun(HKEY_CURRENT_USER, kAutolaunchKeyValue); |
| + base::win::RemoveCommandFromAutoRun(HKEY_CURRENT_USER, key_name); |
| } |
| } |