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
) {
24 LOG(DFATAL
) << "Cannot initialize AppCommands from an invalid key.";
28 using base::win::RegistryKeyIterator
;
29 static const wchar_t kEmptyString
[] = L
"";
36 for (RegistryKeyIterator
key_iterator(key
.Handle(), kEmptyString
);
37 key_iterator
.Valid(); ++key_iterator
) {
38 const wchar_t* name
= key_iterator
.Name();
39 result
= cmd_key
.Open(key
.Handle(), name
, KEY_QUERY_VALUE
);
40 if (result
!= ERROR_SUCCESS
) {
41 LOG(ERROR
) << "Failed to open key \"" << name
42 << "\" with last-error code " << result
;
43 } else if (command
.Initialize(cmd_key
)) {
44 commands_
[name
] = command
;
46 VLOG(1) << "Skipping over key \"" << name
47 << "\" as it does not appear to hold a product command.";
54 AppCommands
& AppCommands::CopyFrom(const AppCommands
& other
) {
55 commands_
= other
.commands_
;
60 void AppCommands::Clear() {
64 bool AppCommands::Get(const std::wstring
& command_id
,
65 AppCommand
* command
) const {
67 CommandMap::const_iterator
it(commands_
.find(command_id
));
68 if (it
== commands_
.end())
70 *command
= it
->second
;
74 bool AppCommands::Set(const std::wstring
& command_id
,
75 const AppCommand
& command
) {
76 std::pair
<CommandMap::iterator
, bool> result(
77 commands_
.insert(std::make_pair(command_id
, command
)));
79 result
.first
->second
= command
;
83 bool AppCommands::Remove(const std::wstring
& command_id
) {
84 return commands_
.erase(command_id
) != 0;
87 AppCommands::CommandMapRange
AppCommands::GetIterators() const {
88 return std::make_pair(commands_
.begin(), commands_
.end());
91 } // namespace installer