Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/common/platform_util.h" | 5 #include "chrome/common/platform_util.h" |
| 6 | 6 |
| 7 #include <commdlg.h> | 7 #include <commdlg.h> |
| 8 #include <dwmapi.h> | 8 #include <dwmapi.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| 11 | 11 |
| 12 #include "app/gfx/native_widget_types.h" | 12 #include "app/gfx/native_widget_types.h" |
| 13 #include "app/win_util.h" | 13 #include "app/win_util.h" |
| 14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/registry.h" | 17 #include "base/registry.h" |
| 18 #include "base/scoped_comptr_win.h" | 18 #include "base/scoped_comptr_win.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "chrome/installer/util/google_update_constants.h" | |
| 20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 21 | 22 |
| 22 namespace platform_util { | 23 namespace platform_util { |
| 23 | 24 |
| 24 void ShowItemInFolder(const FilePath& full_path) { | 25 void ShowItemInFolder(const FilePath& full_path) { |
| 25 FilePath dir = full_path.DirName(); | 26 FilePath dir = full_path.DirName(); |
| 26 // ParseDisplayName will fail if the directory is "C:", it must be "C:\\". | 27 // ParseDisplayName will fail if the directory is "C:", it must be "C:\\". |
| 27 if (dir.value() == L"" || !file_util::EnsureEndsWithSeparator(&dir)) | 28 if (dir.value() == L"" || !file_util::EnsureEndsWithSeparator(&dir)) |
| 28 return; | 29 return; |
| 29 | 30 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 } | 153 } |
| 153 | 154 |
| 154 void SimpleErrorBox(gfx::NativeWindow parent, | 155 void SimpleErrorBox(gfx::NativeWindow parent, |
| 155 const string16& title, | 156 const string16& title, |
| 156 const string16& message) { | 157 const string16& message) { |
| 157 win_util::MessageBox(parent, message, title, MB_OK | MB_SETFOREGROUND); | 158 win_util::MessageBox(parent, message, title, MB_OK | MB_SETFOREGROUND); |
| 158 } | 159 } |
| 159 | 160 |
| 160 | 161 |
| 161 namespace { | 162 namespace { |
| 162 // Constants copied from src/tools/channel_changer/channel_changer.cc. | |
| 163 | 163 |
| 164 // The Google Update key to read to find out which branch you are on. | |
| 165 const wchar_t* const kChromeClientStateKey = | |
| 166 L"Software\\Google\\Update\\ClientState\\" | |
| 167 L"{8A69D345-D564-463C-AFF1-A69D9E530F96}"; | |
| 168 | |
| 169 // The Google Client key to read to find out which branch you are on. | |
| 170 const wchar_t* const kChromeClientsKey = | |
| 171 L"Software\\Google\\Update\\Clients\\" | |
| 172 L"{8A69D345-D564-463C-AFF1-A69D9E530F96}"; | |
| 173 | |
| 174 // The Google Update value that defines which branch you are on. | |
| 175 const wchar_t* const kBranchKey = L"ap"; | |
| 176 | |
| 177 // The suffix Google Update sometimes adds to the channel name (channel names | |
| 178 // are defined in kBranchStrings), indicating that a full install is needed. We | |
| 179 // strip this out (if present) for the purpose of determining which channel you | |
| 180 // are on. | |
| 181 const wchar_t* const kChannelSuffix = L"-full"; | |
| 182 | |
| 183 // See DetectBranch() in src/tools/channel_changer/channel_changer.cc. | |
| 184 std::wstring CurrentChromeChannel() { | 164 std::wstring CurrentChromeChannel() { |
| 185 std::wstring update_branch = L"stable"; // default if we get confused. | 165 std::wstring update_branch = L"stable"; // The default if we get confused. |
|
Erik does not do reviews
2010/01/07 23:50:51
per mark's comment, this shouldn't be the default
| |
| 186 | 166 |
| 187 // See if we can find the Clients key on the HKLM branch. | 167 // See if we can find the Clients key on the HKLM branch. |
| 188 HKEY registry_hive = HKEY_LOCAL_MACHINE; | 168 HKEY registry_hive = HKEY_LOCAL_MACHINE; |
| 189 RegKey google_update_hklm(registry_hive, kChromeClientsKey, KEY_READ); | 169 std::wstring key = google_update::kRegPathClients + std::wstring(L"\\") + |
| 170 google_update::kChromeUpgradeCode; | |
| 171 RegKey google_update_hklm(registry_hive, key.c_str(), KEY_READ); | |
| 190 if (!google_update_hklm.Valid()) { | 172 if (!google_update_hklm.Valid()) { |
| 191 // HKLM failed us, try the same for the HKCU branch. | 173 // HKLM failed us, try the same for the HKCU branch. |
| 192 registry_hive = HKEY_CURRENT_USER; | 174 registry_hive = HKEY_CURRENT_USER; |
| 193 RegKey google_update_hkcu(registry_hive, kChromeClientsKey, KEY_READ); | 175 RegKey google_update_hkcu(registry_hive, key.c_str(), KEY_READ); |
| 194 if (!google_update_hkcu.Valid()) { | 176 if (!google_update_hkcu.Valid()) { |
| 195 // Unknown. | 177 // Unknown. |
| 196 registry_hive = 0; | 178 registry_hive = 0; |
| 197 } | 179 } |
| 198 } | 180 } |
| 199 | 181 |
| 200 if (registry_hive != 0) { | 182 if (registry_hive != 0) { |
| 201 // Now that we know which hive to use, read the 'ap' key from it. | 183 // Now that we know which hive to use, read the 'ap' key from it. |
| 202 RegKey client_state(registry_hive, kChromeClientStateKey, KEY_READ); | 184 std::wstring key = google_update::kRegPathClientState + |
| 203 client_state.ReadValue(kBranchKey, &update_branch); | 185 std::wstring(L"\\") + google_update::kChromeUpgradeCode; |
| 204 | 186 RegKey client_state(registry_hive, key.c_str(), KEY_READ); |
| 205 // We look for '1.1-beta' or '1.1-dev', but Google Update might have added | 187 client_state.ReadValue(google_update::kRegApField, &update_branch); |
| 206 // '-full' to the channel name, which we need to strip out to determine what | |
| 207 // channel you are on. | |
| 208 std::wstring suffix = kChannelSuffix; | |
| 209 if (update_branch.length() > suffix.length()) { | |
| 210 size_t index = update_branch.rfind(suffix); | |
| 211 if (index != std::wstring::npos && | |
| 212 index == update_branch.length() - suffix.length()) { | |
| 213 update_branch = update_branch.substr(0, index); | |
| 214 } | |
| 215 } | |
| 216 } | 188 } |
| 217 | 189 |
| 218 // Map to something pithy for human consumption. | 190 // Map to something pithy for human consumption. There are no rules as to |
| 219 if ((update_branch == L"2.0-dev") ||(update_branch == L"1.1-dev")) | 191 // what the ap string can contain, but generally it will contain a number |
| 192 // followed by a dash followed by the branch name (and then some random | |
| 193 // suffix). | |
| 194 if (update_branch.find(L"-beta") != std::wstring::npos) | |
| 195 update_branch = L"beta"; | |
| 196 else if (update_branch.find(L"-dev") != std::wstring::npos) | |
| 220 update_branch = L"dev"; | 197 update_branch = L"dev"; |
| 221 else if (update_branch == L"1.1-beta") | 198 else |
| 222 update_branch = L"beta"; | 199 update_branch = L""; |
|
Erik does not do reviews
2010/01/07 23:50:51
Add a comment here about why we don't return "stab
| |
| 223 | 200 |
| 224 return update_branch; | 201 return update_branch; |
| 225 } | 202 } |
| 226 | 203 |
| 227 } // namespace | 204 } // namespace |
| 228 | 205 |
| 229 string16 GetVersionStringModifier() { | 206 string16 GetVersionStringModifier() { |
| 230 #if defined(GOOGLE_CHROME_BUILD) | 207 #if defined(GOOGLE_CHROME_BUILD) |
| 231 return CurrentChromeChannel(); | 208 return CurrentChromeChannel(); |
| 232 #else | 209 #else |
| 233 return EmptyString16(); | 210 return EmptyString16(); |
| 234 #endif | 211 #endif |
| 235 } | 212 } |
| 236 | 213 |
| 237 } // namespace platform_util | 214 } // namespace platform_util |
| OLD | NEW |