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 // This file defines functions that integrate Chrome in Windows shell. These | 5 // This file defines functions that integrate Chrome in Windows shell. These |
6 // functions can be used by Chrome as well as Chrome installer. All of the | 6 // functions can be used by Chrome as well as Chrome installer. All of the |
7 // work is done by the local functions defined in anonymous namespace in | 7 // work is done by the local functions defined in anonymous namespace in |
8 // this class. | 8 // this class. |
9 | 9 |
10 #include "chrome/installer/util/shell_util.h" | 10 #include "chrome/installer/util/shell_util.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 | 147 |
148 bool UserSpecificRegistrySuffix::GetSuffix(base::string16* suffix) { | 148 bool UserSpecificRegistrySuffix::GetSuffix(base::string16* suffix) { |
149 if (suffix_.empty()) { | 149 if (suffix_.empty()) { |
150 NOTREACHED(); | 150 NOTREACHED(); |
151 return false; | 151 return false; |
152 } | 152 } |
153 suffix->assign(suffix_); | 153 suffix->assign(suffix_); |
154 return true; | 154 return true; |
155 } | 155 } |
156 | 156 |
157 // This class represents a single registry entry. The objective is to | 157 // This class represents a single registry entry (a key and its value). A |
158 // encapsulate all the registry entries required for registering Chrome at one | 158 // collection of registry entries should be collected into a list and written |
159 // place. This class can not be instantiated outside the class and the objects | 159 // atomically using a WorkItemList. This is preferred to writing to the registry |
160 // of this class type can be obtained only by calling a static method of this | 160 // directly, because if anything goes wrong, they can be rolled back atomically. |
gab
2015/11/30 13:04:00
I'd say remove the two "atomically" words in this
Matt Giuca
2015/12/01 00:46:35
I think we want to highlight the transactional nat
| |
161 // class. | |
162 class RegistryEntry { | 161 class RegistryEntry { |
163 public: | 162 public: |
164 // A bit-field enum of places to look for this key in the Windows registry. | 163 // A bit-field enum of places to look for this key in the Windows registry. |
165 enum LookForIn { | 164 enum LookForIn { |
166 LOOK_IN_HKCU = 1 << 0, | 165 LOOK_IN_HKCU = 1 << 0, |
167 LOOK_IN_HKLM = 1 << 1, | 166 LOOK_IN_HKLM = 1 << 1, |
168 LOOK_IN_HKCU_THEN_HKLM = LOOK_IN_HKCU | LOOK_IN_HKLM, | 167 LOOK_IN_HKCU_THEN_HKLM = LOOK_IN_HKCU | LOOK_IN_HKLM, |
169 }; | 168 }; |
170 | 169 |
171 // Identifies the type of removal this RegistryEntry is flagged for, if any. | 170 // Identifies the type of removal this RegistryEntry is flagged for, if any. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 base::string16 application_name; | 205 base::string16 application_name; |
207 base::FilePath application_icon_path; | 206 base::FilePath application_icon_path; |
208 int application_icon_index; | 207 int application_icon_index; |
209 base::string16 application_description; | 208 base::string16 application_description; |
210 base::string16 publisher_name; | 209 base::string16 publisher_name; |
211 | 210 |
212 // The CLSID for the application's DelegateExecute handler. May be empty. | 211 // The CLSID for the application's DelegateExecute handler. May be empty. |
213 base::string16 delegate_clsid; | 212 base::string16 delegate_clsid; |
214 }; | 213 }; |
215 | 214 |
215 // Create a object that represent default value of a key | |
216 RegistryEntry(const base::string16& key_path, const base::string16& value); | |
217 | |
218 // Create a object that represent a key of type REG_SZ | |
219 RegistryEntry(const base::string16& key_path, | |
220 const base::string16& name, | |
221 const base::string16& value); | |
222 | |
223 // Create a object that represent a key of integer type | |
gab
2015/11/30 13:04:00
End comments with '.', here and above.
gab
2015/11/30 13:04:00
s/a object/an object/
here and above.
Matt Giuca
2015/12/01 00:46:35
Done (next CL).
Note: I wouldn't want to do this
| |
224 RegistryEntry(const base::string16& key_path, | |
225 const base::string16& name, | |
226 DWORD value); | |
227 | |
216 // Returns the Windows browser client registration key for Chrome. For | 228 // Returns the Windows browser client registration key for Chrome. For |
217 // example: "Software\Clients\StartMenuInternet\Chromium[.user]". Strictly | 229 // example: "Software\Clients\StartMenuInternet\Chromium[.user]". Strictly |
218 // speaking, we should use the name of the executable (e.g., "chrome.exe"), | 230 // speaking, we should use the name of the executable (e.g., "chrome.exe"), |
219 // but that ship has sailed. The cost of switching now is re-prompting users | 231 // but that ship has sailed. The cost of switching now is re-prompting users |
220 // to make Chrome their default browser, which isn't polite. |suffix| is the | 232 // to make Chrome their default browser, which isn't polite. |suffix| is the |
221 // user-specific registration suffix; see GetUserSpecificDefaultBrowserSuffix | 233 // user-specific registration suffix; see GetUserSpecificDefaultBrowserSuffix |
222 // in shell_util.h for details. | 234 // in shell_util.h for details. |
223 static base::string16 GetBrowserClientKey(BrowserDistribution* dist, | 235 static base::string16 GetBrowserClientKey(BrowserDistribution* dist, |
224 const base::string16& suffix); | 236 const base::string16& suffix); |
225 | 237 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 // States this RegistryKey can be in compared to the registry. | 380 // States this RegistryKey can be in compared to the registry. |
369 enum RegistryStatus { | 381 enum RegistryStatus { |
370 // |name_| does not exist in the registry | 382 // |name_| does not exist in the registry |
371 DOES_NOT_EXIST, | 383 DOES_NOT_EXIST, |
372 // |name_| exists, but its value != |value_| | 384 // |name_| exists, but its value != |value_| |
373 DIFFERENT_VALUE, | 385 DIFFERENT_VALUE, |
374 // |name_| exists and its value is |value_| | 386 // |name_| exists and its value is |value_| |
375 SAME_VALUE, | 387 SAME_VALUE, |
376 }; | 388 }; |
377 | 389 |
378 // Create a object that represent default value of a key | |
379 RegistryEntry(const base::string16& key_path, const base::string16& value); | |
380 | |
381 // Create a object that represent a key of type REG_SZ | |
382 RegistryEntry(const base::string16& key_path, | |
383 const base::string16& name, | |
384 const base::string16& value); | |
385 | |
386 // Create a object that represent a key of integer type | |
387 RegistryEntry(const base::string16& key_path, | |
388 const base::string16& name, | |
389 DWORD value); | |
390 | |
391 base::string16 key_path_; // key path for the registry entry | 390 base::string16 key_path_; // key path for the registry entry |
392 base::string16 name_; // name of the registry entry | 391 base::string16 name_; // name of the registry entry |
393 bool is_string_; // true if current registry entry is of type REG_SZ | 392 bool is_string_; // true if current registry entry is of type REG_SZ |
394 base::string16 value_; // string value (useful if is_string_ = true) | 393 base::string16 value_; // string value (useful if is_string_ = true) |
395 DWORD int_value_; // integer value (useful if is_string_ = false) | 394 DWORD int_value_; // integer value (useful if is_string_ = false) |
396 | 395 |
397 // Identifies whether this RegistryEntry is flagged for removal (i.e. no | 396 // Identifies whether this RegistryEntry is flagged for removal (i.e. no |
398 // longer relevant on the configuration it was created under). | 397 // longer relevant on the configuration it was created under). |
399 RemovalFlag removal_flag_; | 398 RemovalFlag removal_flag_; |
400 | 399 |
401 // Helper function for ExistsInRegistry(). | 400 // Helper function for ExistsInRegistry(). |
402 // Returns the RegistryStatus of the current registry entry in | 401 // Returns the RegistryStatus of the current registry entry in |
403 // |root|\|key_path_|\|name_|. | 402 // |root|\|key_path_|\|name_|. |
404 RegistryStatus StatusInRegistryUnderRoot(HKEY root) const; | 403 RegistryStatus StatusInRegistryUnderRoot(HKEY root) const; |
405 | 404 |
406 DISALLOW_COPY_AND_ASSIGN(RegistryEntry); | 405 DISALLOW_COPY_AND_ASSIGN(RegistryEntry); |
407 }; // class RegistryEntry | 406 }; // class RegistryEntry |
408 | 407 |
408 RegistryEntry::RegistryEntry(const base::string16& key_path, | |
409 const base::string16& value) | |
410 : key_path_(key_path), | |
411 name_(), | |
412 is_string_(true), | |
413 value_(value), | |
414 int_value_(0), | |
415 removal_flag_(RemovalFlag::NONE) {} | |
416 | |
417 RegistryEntry::RegistryEntry(const base::string16& key_path, | |
418 const base::string16& name, | |
419 const base::string16& value) | |
420 : key_path_(key_path), | |
421 name_(name), | |
422 is_string_(true), | |
423 value_(value), | |
424 int_value_(0), | |
425 removal_flag_(RemovalFlag::NONE) {} | |
426 | |
427 RegistryEntry::RegistryEntry(const base::string16& key_path, | |
428 const base::string16& name, | |
429 DWORD value) | |
430 : key_path_(key_path), | |
431 name_(name), | |
432 is_string_(false), | |
433 value_(), | |
434 int_value_(value), | |
435 removal_flag_(RemovalFlag::NONE) {} | |
436 | |
409 // static | 437 // static |
410 base::string16 RegistryEntry::GetBrowserClientKey( | 438 base::string16 RegistryEntry::GetBrowserClientKey( |
411 BrowserDistribution* dist, | 439 BrowserDistribution* dist, |
412 const base::string16& suffix) { | 440 const base::string16& suffix) { |
413 DCHECK(suffix.empty() || suffix[0] == L'.'); | 441 DCHECK(suffix.empty() || suffix[0] == L'.'); |
414 return base::string16(ShellUtil::kRegStartMenuInternet) | 442 return base::string16(ShellUtil::kRegStartMenuInternet) |
415 .append(1, L'\\') | 443 .append(1, L'\\') |
416 .append(dist->GetBaseAppName()) | 444 .append(dist->GetBaseAppName()) |
417 .append(suffix); | 445 .append(suffix); |
418 } | 446 } |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
834 DCHECK(look_for_in); | 862 DCHECK(look_for_in); |
835 | 863 |
836 RegistryStatus status = DOES_NOT_EXIST; | 864 RegistryStatus status = DOES_NOT_EXIST; |
837 if (look_for_in & LOOK_IN_HKCU) | 865 if (look_for_in & LOOK_IN_HKCU) |
838 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER); | 866 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER); |
839 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM)) | 867 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM)) |
840 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE); | 868 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE); |
841 return status != DOES_NOT_EXIST; | 869 return status != DOES_NOT_EXIST; |
842 } | 870 } |
843 | 871 |
844 RegistryEntry::RegistryEntry(const base::string16& key_path, | |
845 const base::string16& value) | |
846 : key_path_(key_path), | |
847 name_(), | |
848 is_string_(true), | |
849 value_(value), | |
850 int_value_(0), | |
851 removal_flag_(RemovalFlag::NONE) {} | |
852 | |
853 RegistryEntry::RegistryEntry(const base::string16& key_path, | |
854 const base::string16& name, | |
855 const base::string16& value) | |
856 : key_path_(key_path), | |
857 name_(name), | |
858 is_string_(true), | |
859 value_(value), | |
860 int_value_(0), | |
861 removal_flag_(RemovalFlag::NONE) {} | |
862 | |
863 RegistryEntry::RegistryEntry(const base::string16& key_path, | |
864 const base::string16& name, | |
865 DWORD value) | |
866 : key_path_(key_path), | |
867 name_(name), | |
868 is_string_(false), | |
869 value_(), | |
870 int_value_(value), | |
871 removal_flag_(RemovalFlag::NONE) {} | |
872 | |
873 RegistryEntry::RegistryStatus RegistryEntry::StatusInRegistryUnderRoot( | 872 RegistryEntry::RegistryStatus RegistryEntry::StatusInRegistryUnderRoot( |
874 HKEY root) const { | 873 HKEY root) const { |
875 RegKey key(root, key_path_.c_str(), KEY_QUERY_VALUE); | 874 RegKey key(root, key_path_.c_str(), KEY_QUERY_VALUE); |
876 bool found = false; | 875 bool found = false; |
877 bool correct_value = false; | 876 bool correct_value = false; |
878 if (is_string_) { | 877 if (is_string_) { |
879 base::string16 read_value; | 878 base::string16 read_value; |
880 found = key.ReadValue(name_.c_str(), &read_value) == ERROR_SUCCESS; | 879 found = key.ReadValue(name_.c_str(), &read_value) == ERROR_SUCCESS; |
881 if (found) { | 880 if (found) { |
882 correct_value = | 881 correct_value = |
(...skipping 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2600 base::string16 key_path(ShellUtil::kRegClasses); | 2599 base::string16 key_path(ShellUtil::kRegClasses); |
2601 key_path.push_back(base::FilePath::kSeparators[0]); | 2600 key_path.push_back(base::FilePath::kSeparators[0]); |
2602 key_path.append(prog_id); | 2601 key_path.append(prog_id); |
2603 return InstallUtil::DeleteRegistryKey( | 2602 return InstallUtil::DeleteRegistryKey( |
2604 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default); | 2603 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default); |
2605 | 2604 |
2606 // TODO(mgiuca): Remove the extension association entries. This requires that | 2605 // TODO(mgiuca): Remove the extension association entries. This requires that |
2607 // the extensions associated with a particular prog_id are stored in that | 2606 // the extensions associated with a particular prog_id are stored in that |
2608 // prog_id's key. | 2607 // prog_id's key. |
2609 } | 2608 } |
OLD | NEW |