OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/app_command.h" | 5 #include "chrome/installer/util/app_command.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/win/registry.h" | 8 #include "base/win/registry.h" |
9 #include "chrome/installer/util/google_update_constants.h" | 9 #include "chrome/installer/util/google_update_constants.h" |
10 #include "chrome/installer/util/work_item_list.h" | 10 #include "chrome/installer/util/work_item_list.h" |
11 | 11 |
12 namespace installer { | 12 namespace installer { |
13 | 13 |
| 14 namespace { |
| 15 |
| 16 // Adds a work item to set |value_name| to DWORD 1 if |value_data| is true; |
| 17 // adds a work item to remove |value_name| otherwise. |
| 18 WorkItem* AddSetOptionalBoolRegValueWorkItem( |
| 19 HKEY predefined_root, |
| 20 const string16& key_path, |
| 21 const string16& value_name, |
| 22 bool value_data, |
| 23 WorkItemList* item_list) { |
| 24 if (value_data) { |
| 25 return item_list->AddSetRegValueWorkItem(predefined_root, |
| 26 key_path, |
| 27 value_name, |
| 28 static_cast<DWORD>(1), |
| 29 true); |
| 30 } else { |
| 31 return item_list->AddDeleteRegValueWorkItem(predefined_root, |
| 32 key_path, |
| 33 value_name); |
| 34 } |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
14 AppCommand::AppCommand() | 39 AppCommand::AppCommand() |
15 : sends_pings_(false), | 40 : sends_pings_(false), |
16 is_web_accessible_(false) { | 41 is_web_accessible_(false), |
| 42 is_auto_run_on_os_upgrade_(false) { |
17 } | 43 } |
18 | 44 |
19 AppCommand::AppCommand(const std::wstring& command_line, | 45 AppCommand::AppCommand(const string16& command_line) |
20 bool sends_pings, | |
21 bool is_web_accessible) | |
22 : command_line_(command_line), | 46 : command_line_(command_line), |
23 sends_pings_(sends_pings), | 47 sends_pings_(false), |
24 is_web_accessible_(is_web_accessible) { | 48 is_web_accessible_(false), |
| 49 is_auto_run_on_os_upgrade_(false) { |
25 } | 50 } |
26 | 51 |
27 bool AppCommand::Initialize(const base::win::RegKey& key) { | 52 bool AppCommand::Initialize(const base::win::RegKey& key) { |
28 if (!key.Valid()) { | 53 if (!key.Valid()) { |
29 LOG(DFATAL) << "Cannot initialize an AppCommand from an invalid key."; | 54 LOG(DFATAL) << "Cannot initialize an AppCommand from an invalid key."; |
30 return false; | 55 return false; |
31 } | 56 } |
32 | 57 |
33 LONG result = ERROR_SUCCESS; | 58 LONG result = ERROR_SUCCESS; |
34 std::wstring cmd_line; | 59 string16 cmd_line; |
35 DWORD sends_pings = 0; | 60 DWORD sends_pings = 0; |
36 DWORD is_web_acc = 0; | 61 DWORD is_web_acc = 0; |
| 62 DWORD is_auto_run_on_os_upgrade = 0; |
37 | 63 |
38 result = key.ReadValue(google_update::kRegCommandLineField, &cmd_line); | 64 result = key.ReadValue(google_update::kRegCommandLineField, &cmd_line); |
39 if (result != ERROR_SUCCESS) { | 65 if (result != ERROR_SUCCESS) { |
40 LOG(WARNING) << "Error reading " << google_update::kRegCommandLineField | 66 LOG(WARNING) << "Error reading " << google_update::kRegCommandLineField |
41 << " value from registry: " << result; | 67 << " value from registry: " << result; |
42 return false; | 68 return false; |
43 } | 69 } |
44 | 70 |
45 result = key.ReadValueDW(google_update::kRegSendsPingsField, &sends_pings); | 71 // Note: ReadValueDW only modifies its out param on success. |
46 if (result != ERROR_SUCCESS) { | 72 key.ReadValueDW(google_update::kRegSendsPingsField, &sends_pings); |
47 LOG(WARNING) << "Error reading " << google_update::kRegSendsPingsField | 73 key.ReadValueDW(google_update::kRegWebAccessibleField, &is_web_acc); |
48 << " value from registry: " << result; | 74 key.ReadValueDW(google_update::kRegAutoRunOnOSUpgradeField, |
49 return false; | 75 &is_auto_run_on_os_upgrade); |
50 } | |
51 | |
52 result = key.ReadValueDW(google_update::kRegWebAccessibleField, &is_web_acc); | |
53 if (result != ERROR_SUCCESS) { | |
54 LOG(WARNING) << "Error reading " << google_update::kRegWebAccessibleField | |
55 << " value from registry: " << result; | |
56 return false; | |
57 } | |
58 | 76 |
59 command_line_.swap(cmd_line); | 77 command_line_.swap(cmd_line); |
60 sends_pings_ = (sends_pings != 0); | 78 sends_pings_ = (sends_pings != 0); |
61 is_web_accessible_ = (is_web_acc != 0); | 79 is_web_accessible_ = (is_web_acc != 0); |
| 80 is_auto_run_on_os_upgrade_ = (is_auto_run_on_os_upgrade != 0); |
62 | 81 |
63 return true; | 82 return true; |
64 } | 83 } |
65 | 84 |
66 void AppCommand::AddWorkItems(HKEY predefined_root, | 85 void AppCommand::AddWorkItems(HKEY predefined_root, |
67 const std::wstring& command_path, | 86 const string16& command_path, |
68 WorkItemList* item_list) const { | 87 WorkItemList* item_list) const { |
69 const DWORD sends_pings = sends_pings_ ? 1U : 0U; | |
70 const DWORD is_web_accessible = is_web_accessible_ ? 1U : 0U; | |
71 | |
72 item_list->AddCreateRegKeyWorkItem(predefined_root, command_path) | 88 item_list->AddCreateRegKeyWorkItem(predefined_root, command_path) |
73 ->set_log_message("creating quick-enable-cf command registry key"); | 89 ->set_log_message("creating AppCommand registry key"); |
74 item_list->AddSetRegValueWorkItem(predefined_root, command_path, | 90 item_list->AddSetRegValueWorkItem(predefined_root, command_path, |
75 google_update::kRegCommandLineField, | 91 google_update::kRegCommandLineField, |
76 command_line_, true) | 92 command_line_, true) |
77 ->set_log_message("setting quick-enable-cf CommandLine registry value"); | 93 ->set_log_message("setting AppCommand CommandLine registry value"); |
78 item_list->AddSetRegValueWorkItem(predefined_root, command_path, | 94 AddSetOptionalBoolRegValueWorkItem(predefined_root, |
79 google_update::kRegSendsPingsField, | 95 command_path, |
80 sends_pings, true) | 96 google_update::kRegSendsPingsField, |
81 ->set_log_message("setting quick-enable-cf SendsPings registry value"); | 97 sends_pings_, |
82 item_list->AddSetRegValueWorkItem(predefined_root, command_path, | 98 item_list) |
83 google_update::kRegWebAccessibleField, | 99 ->set_log_message("setting AppCommand SendsPings registry value"); |
84 is_web_accessible, true) | 100 AddSetOptionalBoolRegValueWorkItem(predefined_root, |
85 ->set_log_message("setting quick-enable-cf WebAccessible registry value"); | 101 command_path, |
| 102 google_update::kRegWebAccessibleField, |
| 103 is_web_accessible_, |
| 104 item_list) |
| 105 ->set_log_message("setting AppCommand WebAccessible registry value"); |
| 106 AddSetOptionalBoolRegValueWorkItem(predefined_root, |
| 107 command_path, |
| 108 google_update::kRegAutoRunOnOSUpgradeField, |
| 109 is_auto_run_on_os_upgrade_, |
| 110 item_list) |
| 111 ->set_log_message("setting AppCommand AutoRunOnOSUpgrade registry value"); |
86 } | 112 } |
87 | 113 |
88 } // namespace installer | 114 } // namespace installer |
OLD | NEW |