| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 google_update::kRegRunAsUserField}, | 24 google_update::kRegRunAsUserField}, |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 AppCommand::AppCommand() | 27 AppCommand::AppCommand() |
| 28 : sends_pings_(false), | 28 : sends_pings_(false), |
| 29 is_web_accessible_(false), | 29 is_web_accessible_(false), |
| 30 is_auto_run_on_os_upgrade_(false), | 30 is_auto_run_on_os_upgrade_(false), |
| 31 is_run_as_user_(false) { | 31 is_run_as_user_(false) { |
| 32 } | 32 } |
| 33 | 33 |
| 34 AppCommand::AppCommand(const string16& command_line) | 34 AppCommand::AppCommand(const base::string16& command_line) |
| 35 : command_line_(command_line), | 35 : command_line_(command_line), |
| 36 sends_pings_(false), | 36 sends_pings_(false), |
| 37 is_web_accessible_(false), | 37 is_web_accessible_(false), |
| 38 is_auto_run_on_os_upgrade_(false), | 38 is_auto_run_on_os_upgrade_(false), |
| 39 is_run_as_user_(false) { | 39 is_run_as_user_(false) { |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool AppCommand::Initialize(const base::win::RegKey& key) { | 42 bool AppCommand::Initialize(const base::win::RegKey& key) { |
| 43 if (!key.Valid()) { | 43 if (!key.Valid()) { |
| 44 LOG(DFATAL) << "Cannot initialize an AppCommand from an invalid key."; | 44 LOG(DFATAL) << "Cannot initialize an AppCommand from an invalid key."; |
| 45 return false; | 45 return false; |
| 46 } | 46 } |
| 47 | 47 |
| 48 LONG result = ERROR_SUCCESS; | 48 LONG result = ERROR_SUCCESS; |
| 49 string16 cmd_line; | 49 base::string16 cmd_line; |
| 50 | 50 |
| 51 result = key.ReadValue(google_update::kRegCommandLineField, &cmd_line); | 51 result = key.ReadValue(google_update::kRegCommandLineField, &cmd_line); |
| 52 if (result != ERROR_SUCCESS) { | 52 if (result != ERROR_SUCCESS) { |
| 53 LOG(WARNING) << "Error reading " << google_update::kRegCommandLineField | 53 LOG(WARNING) << "Error reading " << google_update::kRegCommandLineField |
| 54 << " value from registry: " << result; | 54 << " value from registry: " << result; |
| 55 return false; | 55 return false; |
| 56 } | 56 } |
| 57 | 57 |
| 58 command_line_.swap(cmd_line); | 58 command_line_.swap(cmd_line); |
| 59 | 59 |
| 60 for (int i = 0; i < arraysize(kNameBoolVars); ++i) { | 60 for (int i = 0; i < arraysize(kNameBoolVars); ++i) { |
| 61 DWORD value = 0; // Set default to false. | 61 DWORD value = 0; // Set default to false. |
| 62 // Note: ReadValueDW only modifies out param on success. | 62 // Note: ReadValueDW only modifies out param on success. |
| 63 key.ReadValueDW(kNameBoolVars[i].name, &value); | 63 key.ReadValueDW(kNameBoolVars[i].name, &value); |
| 64 this->*(kNameBoolVars[i].data) = (value != 0); | 64 this->*(kNameBoolVars[i].data) = (value != 0); |
| 65 } | 65 } |
| 66 | 66 |
| 67 return true; | 67 return true; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void AppCommand::AddWorkItems(HKEY predefined_root, | 70 void AppCommand::AddWorkItems(HKEY predefined_root, |
| 71 const string16& command_path, | 71 const base::string16& command_path, |
| 72 WorkItemList* item_list) const { | 72 WorkItemList* item_list) const { |
| 73 item_list->AddCreateRegKeyWorkItem(predefined_root, command_path) | 73 item_list->AddCreateRegKeyWorkItem(predefined_root, command_path) |
| 74 ->set_log_message("creating AppCommand registry key"); | 74 ->set_log_message("creating AppCommand registry key"); |
| 75 item_list->AddSetRegValueWorkItem(predefined_root, command_path, | 75 item_list->AddSetRegValueWorkItem(predefined_root, command_path, |
| 76 google_update::kRegCommandLineField, | 76 google_update::kRegCommandLineField, |
| 77 command_line_, true) | 77 command_line_, true) |
| 78 ->set_log_message("setting AppCommand CommandLine registry value"); | 78 ->set_log_message("setting AppCommand CommandLine registry value"); |
| 79 | 79 |
| 80 for (int i = 0; i < arraysize(kNameBoolVars); ++i) { | 80 for (int i = 0; i < arraysize(kNameBoolVars); ++i) { |
| 81 const wchar_t* var_name = kNameBoolVars[i].name; | 81 const wchar_t* var_name = kNameBoolVars[i].name; |
| 82 bool var_data = this->*(kNameBoolVars[i].data); | 82 bool var_data = this->*(kNameBoolVars[i].data); |
| 83 | 83 |
| 84 // Adds a work item to set |var_name| to DWORD 1 if |var_data| is true; | 84 // Adds a work item to set |var_name| to DWORD 1 if |var_data| is true; |
| 85 // adds a work item to remove |var_name| otherwise. | 85 // adds a work item to remove |var_name| otherwise. |
| 86 if (var_data) { | 86 if (var_data) { |
| 87 item_list->AddSetRegValueWorkItem(predefined_root, | 87 item_list->AddSetRegValueWorkItem(predefined_root, |
| 88 command_path, | 88 command_path, |
| 89 var_name, | 89 var_name, |
| 90 static_cast<DWORD>(1), | 90 static_cast<DWORD>(1), |
| 91 true); | 91 true); |
| 92 } else { | 92 } else { |
| 93 item_list->AddDeleteRegValueWorkItem(predefined_root, | 93 item_list->AddDeleteRegValueWorkItem(predefined_root, |
| 94 command_path, | 94 command_path, |
| 95 var_name); | 95 var_name); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 } // namespace installer | 100 } // namespace installer |
| OLD | NEW |