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
3 // found in the LICENSE file.
5 #include "chrome/installer/util/app_commands.h"
7 #include "base/logging.h"
8 #include "base/win/registry.h"
9 #include "chrome/installer/util/google_update_constants.h"
10 #include "chrome/installer/util/work_item_list.h"
12 using base::win::RegKey
;
16 AppCommands::AppCommands() {
19 AppCommands::~AppCommands() {
22 bool AppCommands::Initialize(const base::win::RegKey
& key
, REGSAM wow64access
) {
24 LOG(DFATAL
) << "Cannot initialize AppCommands from an invalid key.";
28 if (wow64access
!= 0 && wow64access
!= KEY_WOW64_32KEY
&&
29 wow64access
!= KEY_WOW64_64KEY
) {
30 LOG(DFATAL
) << "Invalid wow64access supplied to AppCommands.";
34 using base::win::RegistryKeyIterator
;
35 static const wchar_t kEmptyString
[] = L
"";
42 for (RegistryKeyIterator
key_iterator(
43 key
.Handle(), kEmptyString
, wow64access
);
46 const wchar_t* name
= key_iterator
.Name();
47 result
= cmd_key
.Open(key
.Handle(), name
, KEY_QUERY_VALUE
);
48 if (result
!= ERROR_SUCCESS
) {
49 LOG(ERROR
) << "Failed to open key \"" << name
50 << "\" with last-error code " << result
;
51 } else if (command
.Initialize(cmd_key
)) {
52 commands_
[name
] = command
;
54 VLOG(1) << "Skipping over key \"" << name
55 << "\" as it does not appear to hold a product command.";
62 AppCommands
& AppCommands::CopyFrom(const AppCommands
& other
) {
63 commands_
= other
.commands_
;
68 void AppCommands::Clear() {
72 bool AppCommands::Get(const std::wstring
& command_id
,
73 AppCommand
* command
) const {
75 CommandMap::const_iterator
it(commands_
.find(command_id
));
76 if (it
== commands_
.end())
78 *command
= it
->second
;
82 bool AppCommands::Set(const std::wstring
& command_id
,
83 const AppCommand
& command
) {
84 std::pair
<CommandMap::iterator
, bool> result(
85 commands_
.insert(std::make_pair(command_id
, command
)));
87 result
.first
->second
= command
;
91 bool AppCommands::Remove(const std::wstring
& command_id
) {
92 return commands_
.erase(command_id
) != 0;
95 AppCommands::CommandMapRange
AppCommands::GetIterators() const {
96 return std::make_pair(commands_
.begin(), commands_
.end());
99 } // namespace installer