Jae Hoon Kim | 823ead3 | 2019-12-13 09:30:09 -0800 | [diff] [blame] | 1 | // Copyright 2019 The Chromium OS 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. |
| 4 | |
Amin Hassani | 04fda43 | 2020-02-21 11:31:14 -0800 | [diff] [blame] | 5 | #include "dlcservice/dlc_manager.h" |
| 6 | |
Jae Hoon Kim | c98e3a3 | 2020-03-13 09:40:48 -0700 | [diff] [blame] | 7 | #include <cinttypes> |
Jae Hoon Kim | 823ead3 | 2019-12-13 09:30:09 -0800 | [diff] [blame] | 8 | #include <utility> |
| 9 | |
Qijiang Fan | 713061e | 2021-03-08 15:45:12 +0900 | [diff] [blame] | 10 | #include <base/check.h> |
Jae Hoon Kim | 823ead3 | 2019-12-13 09:30:09 -0800 | [diff] [blame] | 11 | #include <base/strings/stringprintf.h> |
Jae Hoon Kim | 823ead3 | 2019-12-13 09:30:09 -0800 | [diff] [blame] | 12 | #include <chromeos/dbus/service_constants.h> |
| 13 | #include <dbus/dlcservice/dbus-constants.h> |
Amin Hassani | a69f32e | 2020-03-30 15:20:42 -0700 | [diff] [blame] | 14 | #include <dlcservice/proto_bindings/dlcservice.pb.h> |
Jae Hoon Kim | 823ead3 | 2019-12-13 09:30:09 -0800 | [diff] [blame] | 15 | |
Amin Hassani | a69f32e | 2020-03-30 15:20:42 -0700 | [diff] [blame] | 16 | #include "dlcservice/dlc.h" |
Jae Hoon Kim | c98e3a3 | 2020-03-13 09:40:48 -0700 | [diff] [blame] | 17 | #include "dlcservice/error.h" |
Jae Hoon Kim | f4eed88 | 2020-01-28 17:29:16 -0800 | [diff] [blame] | 18 | #include "dlcservice/system_state.h" |
Jae Hoon Kim | 823ead3 | 2019-12-13 09:30:09 -0800 | [diff] [blame] | 19 | #include "dlcservice/utils.h" |
| 20 | |
Jae Hoon Kim | c98e3a3 | 2020-03-13 09:40:48 -0700 | [diff] [blame] | 21 | using brillo::ErrorPtr; |
Amin Hassani | 40c0f11 | 2020-04-15 09:55:00 -0700 | [diff] [blame] | 22 | using brillo::MessageLoop; |
Jae Hoon Kim | 823ead3 | 2019-12-13 09:30:09 -0800 | [diff] [blame] | 23 | |
| 24 | namespace dlcservice { |
| 25 | |
Amin Hassani | d421b41 | 2020-07-17 17:37:30 -0700 | [diff] [blame] | 26 | namespace { |
| 27 | DlcIdList ToDlcIdList(const DlcMap& dlcs, |
| 28 | const std::function<bool(const DlcBase&)>& filter) { |
| 29 | DlcIdList list; |
| 30 | for (const auto& pair : dlcs) { |
| 31 | if (filter(pair.second)) |
| 32 | list.push_back(pair.first); |
| 33 | } |
| 34 | return list; |
| 35 | } |
| 36 | } // namespace |
| 37 | |
Amin Hassani | 40c0f11 | 2020-04-15 09:55:00 -0700 | [diff] [blame] | 38 | DlcManager::~DlcManager() { |
| 39 | if (cleanup_dangling_task_id_ != MessageLoop::kTaskIdNull) { |
| 40 | MessageLoop::current()->CancelTask(cleanup_dangling_task_id_); |
| 41 | cleanup_dangling_task_id_ = MessageLoop::kTaskIdNull; |
| 42 | } |
| 43 | } |
| 44 | |
Amin Hassani | ca3cbb7 | 2020-04-10 12:26:50 -0700 | [diff] [blame] | 45 | void DlcManager::Initialize() { |
Amin Hassani | 40c0f11 | 2020-04-15 09:55:00 -0700 | [diff] [blame] | 46 | supported_.clear(); |
| 47 | |
Amin Hassani | 7373abd | 2020-03-27 12:56:37 -0700 | [diff] [blame] | 48 | // Initialize supported DLC(s). |
Jae Hoon Kim | 0d4ff62 | 2020-05-14 14:47:40 -0700 | [diff] [blame] | 49 | for (const auto& id : ScanDirectory(SystemState::Get()->manifest_dir())) { |
Amin Hassani | a69f32e | 2020-03-30 15:20:42 -0700 | [diff] [blame] | 50 | auto result = supported_.emplace(id, id); |
| 51 | if (!result.first->second.Initialize()) { |
| 52 | LOG(ERROR) << "Failed to initialize DLC " << id; |
| 53 | supported_.erase(id); |
| 54 | } |
| 55 | } |
Amin Hassani | 40c0f11 | 2020-04-15 09:55:00 -0700 | [diff] [blame] | 56 | |
Jae Hoon Kim | 0d4ff62 | 2020-05-14 14:47:40 -0700 | [diff] [blame] | 57 | CleanupUnsupportedDlcs(); |
Amin Hassani | 40c0f11 | 2020-04-15 09:55:00 -0700 | [diff] [blame] | 58 | |
| 59 | // Post cleaning up dangling Dlcs for after the user has worked on the device |
| 60 | // for a bit in case they install one of the dangling DLCs. |
| 61 | constexpr int kTimeoutMinutes = 30; |
| 62 | PostCleanupDanglingDlcs(base::TimeDelta::FromMinutes(kTimeoutMinutes)); |
Jae Hoon Kim | 0d4ff62 | 2020-05-14 14:47:40 -0700 | [diff] [blame] | 63 | } |
Jae Hoon Kim | 823ead3 | 2019-12-13 09:30:09 -0800 | [diff] [blame] | 64 | |
Jae Hoon Kim | 0d4ff62 | 2020-05-14 14:47:40 -0700 | [diff] [blame] | 65 | void DlcManager::CleanupUnsupportedDlcs() { |
Jae Hoon Kim | 6e3026d | 2020-07-10 11:04:29 -0700 | [diff] [blame] | 66 | auto* system_state = SystemState::Get(); |
Jae Hoon Kim | 0c2b6cd | 2020-04-30 13:23:16 -0700 | [diff] [blame] | 67 | // Delete deprecated DLC(s) in content directory. |
| 68 | for (const auto& id : ScanDirectory(system_state->content_dir())) { |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 69 | brillo::ErrorPtr tmp_err; |
| 70 | if (GetDlc(id, &tmp_err) != nullptr) |
Jae Hoon Kim | 0c2b6cd | 2020-04-30 13:23:16 -0700 | [diff] [blame] | 71 | continue; |
| 72 | for (const auto& path : DlcBase::GetPathsToDelete(id)) |
Andrew | 2673ee4 | 2020-05-08 15:27:10 -0700 | [diff] [blame] | 73 | if (base::PathExists(path)) { |
hscham | 53cf73a | 2020-11-30 15:58:42 +0900 | [diff] [blame] | 74 | if (!base::DeletePathRecursively(path)) |
Andrew | 2673ee4 | 2020-05-08 15:27:10 -0700 | [diff] [blame] | 75 | PLOG(ERROR) << "Failed to delete path=" << path; |
| 76 | else |
| 77 | LOG(INFO) << "Deleted path=" << path << " for deprecated DLC=" << id; |
| 78 | } |
Jae Hoon Kim | 0c2b6cd | 2020-04-30 13:23:16 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Jae Hoon Kim | 0d4ff62 | 2020-05-14 14:47:40 -0700 | [diff] [blame] | 81 | // Delete the unsupported/preload not allowed DLC(s) in the preloaded |
| 82 | // directory. |
| 83 | auto preloaded_content_dir = system_state->preloaded_content_dir(); |
| 84 | for (const auto& id : ScanDirectory(preloaded_content_dir)) { |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 85 | brillo::ErrorPtr tmp_err; |
| 86 | auto* dlc = GetDlc(id, &tmp_err); |
| 87 | if (dlc != nullptr && dlc->IsPreloadAllowed()) |
| 88 | continue; |
| 89 | |
Jae Hoon Kim | 0d4ff62 | 2020-05-14 14:47:40 -0700 | [diff] [blame] | 90 | // Preloading is not allowed for this image so it will be deleted. |
| 91 | auto path = JoinPaths(preloaded_content_dir, id); |
hscham | 53cf73a | 2020-11-30 15:58:42 +0900 | [diff] [blame] | 92 | if (!base::DeletePathRecursively(path)) |
Jae Hoon Kim | 0d4ff62 | 2020-05-14 14:47:40 -0700 | [diff] [blame] | 93 | PLOG(ERROR) << "Failed to delete path=" << path; |
| 94 | else |
| 95 | LOG(INFO) << "Deleted path=" << path |
| 96 | << " for unsupported/preload not allowed DLC=" << id; |
| 97 | } |
Amin Hassani | ca3cbb7 | 2020-04-10 12:26:50 -0700 | [diff] [blame] | 98 | } |
Amin Hassani | 1fd2082 | 2020-03-27 11:52:23 -0700 | [diff] [blame] | 99 | |
Amin Hassani | 40c0f11 | 2020-04-15 09:55:00 -0700 | [diff] [blame] | 100 | void DlcManager::CleanupDanglingDlcs() { |
| 101 | LOG(INFO) << "Going to clean up dangling DLCs."; |
| 102 | for (auto& pair : supported_) { |
| 103 | auto& dlc = pair.second; |
| 104 | if (dlc.ShouldPurge()) { |
| 105 | LOG(INFO) << "DLC=" << dlc.GetId() << " should be removed because it is " |
| 106 | << "dangling."; |
| 107 | brillo::ErrorPtr error; |
| 108 | if (!dlc.Purge(&error)) { |
Andrew | 936ccf6 | 2020-06-12 13:00:23 -0700 | [diff] [blame] | 109 | LOG(ERROR) << "Failed to delete dangling DLC=" << dlc.GetId(); |
Amin Hassani | 40c0f11 | 2020-04-15 09:55:00 -0700 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // Post another one to happen in a day in case they never shutdown their |
| 115 | // devices. |
| 116 | constexpr int kTimeoutDays = 1; |
| 117 | PostCleanupDanglingDlcs(base::TimeDelta::FromDays(kTimeoutDays)); |
| 118 | } |
| 119 | |
| 120 | void DlcManager::PostCleanupDanglingDlcs(const base::TimeDelta& timeout) { |
| 121 | cleanup_dangling_task_id_ = MessageLoop::current()->PostDelayedTask( |
| 122 | FROM_HERE, |
Jae Hoon Kim | c85824c | 2021-05-12 13:19:14 -0700 | [diff] [blame] | 123 | base::BindOnce(&DlcManager::CleanupDanglingDlcs, base::Unretained(this)), |
Amin Hassani | 40c0f11 | 2020-04-15 09:55:00 -0700 | [diff] [blame] | 124 | timeout); |
| 125 | } |
| 126 | |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 127 | DlcBase* DlcManager::GetDlc(const DlcId& id, brillo::ErrorPtr* err) { |
Amin Hassani | 8664998 | 2020-03-31 16:03:37 -0700 | [diff] [blame] | 128 | const auto& iter = supported_.find(id); |
Amin Hassani | b2f139c | 2020-05-15 11:43:26 -0700 | [diff] [blame] | 129 | if (iter == supported_.end()) { |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 130 | *err = Error::Create( |
| 131 | FROM_HERE, kErrorInvalidDlc, |
| 132 | base::StringPrintf("Passed unsupported DLC=%s", id.c_str())); |
Amin Hassani | b2f139c | 2020-05-15 11:43:26 -0700 | [diff] [blame] | 133 | return nullptr; |
| 134 | } |
Amin Hassani | aa38c79 | 2020-04-06 15:52:44 -0700 | [diff] [blame] | 135 | return &iter->second; |
Amin Hassani | 8664998 | 2020-03-31 16:03:37 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Amin Hassani | 9ca846f | 2020-04-17 12:41:01 -0700 | [diff] [blame] | 138 | DlcIdList DlcManager::GetInstalled() { |
Jae Hoon Kim | 9a27d15 | 2020-04-10 12:50:14 -0700 | [diff] [blame] | 139 | // TODO(kimjae): Once update_engine repeatedly calls into |GetInstalled()| for |
| 140 | // updating update, need to handle clearing differently. |
Amin Hassani | 38f3679 | 2020-04-17 11:47:08 -0700 | [diff] [blame] | 141 | return ToDlcIdList(supported_, |
| 142 | [](const DlcBase& dlc) { return dlc.IsInstalled(); }); |
| 143 | } |
| 144 | |
Amin Hassani | d5fc8b2 | 2020-04-29 12:44:52 -0700 | [diff] [blame] | 145 | DlcIdList DlcManager::GetExistingDlcs() { |
| 146 | return ToDlcIdList(supported_, |
| 147 | [](const DlcBase& dlc) { return dlc.HasContent(); }); |
| 148 | } |
| 149 | |
Amin Hassani | 38f3679 | 2020-04-17 11:47:08 -0700 | [diff] [blame] | 150 | DlcIdList DlcManager::GetDlcsToUpdate() { |
Amin Hassani | 4856777 | 2020-05-20 16:21:11 -0700 | [diff] [blame] | 151 | return ToDlcIdList( |
| 152 | supported_, [](const DlcBase& dlc) { return dlc.MakeReadyForUpdate(); }); |
Jae Hoon Kim | 6cb439b | 2020-03-23 14:02:44 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Amin Hassani | 9ca846f | 2020-04-17 12:41:01 -0700 | [diff] [blame] | 155 | DlcIdList DlcManager::GetSupported() { |
| 156 | return ToDlcIdList(supported_, [](const DlcBase&) { return true; }); |
Amin Hassani | a69f32e | 2020-03-30 15:20:42 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Amin Hassani | 9ca846f | 2020-04-17 12:41:01 -0700 | [diff] [blame] | 159 | bool DlcManager::InstallCompleted(const DlcIdList& ids, brillo::ErrorPtr* err) { |
Jae Hoon Kim | 9a27d15 | 2020-04-10 12:50:14 -0700 | [diff] [blame] | 160 | DCHECK(err); |
| 161 | bool ret = true; |
| 162 | for (const auto& id : ids) { |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 163 | auto* dlc = GetDlc(id, err); |
| 164 | if (dlc == nullptr) { |
Amin Hassani | f27aac0 | 2020-04-23 21:56:26 -0700 | [diff] [blame] | 165 | LOG(WARNING) << "Trying to complete installation for unsupported DLC=" |
| 166 | << id; |
Jae Hoon Kim | 9a27d15 | 2020-04-10 12:50:14 -0700 | [diff] [blame] | 167 | ret = false; |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 168 | } else if (!dlc->InstallCompleted(err)) { |
Andrew | 936ccf6 | 2020-06-12 13:00:23 -0700 | [diff] [blame] | 169 | PLOG(WARNING) << "Failed to complete install."; |
Jae Hoon Kim | 9a27d15 | 2020-04-10 12:50:14 -0700 | [diff] [blame] | 170 | ret = false; |
| 171 | } |
| 172 | } |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 173 | // The returned error pertains to the last error happened. We probably don't |
| 174 | // need any accumulation of errors. |
Jae Hoon Kim | 9a27d15 | 2020-04-10 12:50:14 -0700 | [diff] [blame] | 175 | return ret; |
| 176 | } |
| 177 | |
Amin Hassani | 9ca846f | 2020-04-17 12:41:01 -0700 | [diff] [blame] | 178 | bool DlcManager::UpdateCompleted(const DlcIdList& ids, brillo::ErrorPtr* err) { |
Jae Hoon Kim | 9a27d15 | 2020-04-10 12:50:14 -0700 | [diff] [blame] | 179 | DCHECK(err); |
| 180 | bool ret = true; |
| 181 | for (const auto& id : ids) { |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 182 | auto* dlc = GetDlc(id, err); |
| 183 | if (dlc == nullptr) { |
Amin Hassani | f27aac0 | 2020-04-23 21:56:26 -0700 | [diff] [blame] | 184 | LOG(WARNING) << "Trying to complete update for unsupported DLC=" << id; |
Jae Hoon Kim | 9a27d15 | 2020-04-10 12:50:14 -0700 | [diff] [blame] | 185 | ret = false; |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 186 | } else if (!dlc->UpdateCompleted(err)) { |
Andrew | 936ccf6 | 2020-06-12 13:00:23 -0700 | [diff] [blame] | 187 | LOG(WARNING) << "Failed to complete update."; |
Jae Hoon Kim | 9a27d15 | 2020-04-10 12:50:14 -0700 | [diff] [blame] | 188 | ret = false; |
| 189 | } |
| 190 | } |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 191 | // The returned error pertains to the last error happened. We probably don't |
| 192 | // need any accumulation of errors. |
Jae Hoon Kim | 9a27d15 | 2020-04-10 12:50:14 -0700 | [diff] [blame] | 193 | return ret; |
| 194 | } |
| 195 | |
Amin Hassani | 9a3f20c | 2020-05-25 16:38:33 -0700 | [diff] [blame] | 196 | bool DlcManager::Install(const DlcId& id, |
| 197 | bool* external_install_needed, |
| 198 | ErrorPtr* err) { |
Jae Hoon Kim | c98e3a3 | 2020-03-13 09:40:48 -0700 | [diff] [blame] | 199 | DCHECK(err); |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 200 | auto* dlc = GetDlc(id, err); |
| 201 | if (dlc == nullptr) { |
Amin Hassani | 6d0367d | 2020-05-10 18:07:03 -0700 | [diff] [blame] | 202 | return false; |
Amin Hassani | a69f32e | 2020-03-30 15:20:42 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Amin Hassani | 9a3f20c | 2020-05-25 16:38:33 -0700 | [diff] [blame] | 205 | // If the DLC is being installed, nothing can be done anymore. |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 206 | if (dlc->IsInstalling()) { |
Amin Hassani | 9a3f20c | 2020-05-25 16:38:33 -0700 | [diff] [blame] | 207 | return true; |
| 208 | } |
| 209 | |
| 210 | // Otherwise proceed to install the DLC. |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 211 | if (!dlc->Install(err)) { |
Andrew | 0a534ed | 2020-05-06 09:59:17 -0700 | [diff] [blame] | 212 | Error::AddInternalTo( |
| 213 | err, FROM_HERE, error::kFailedInternal, |
| 214 | base::StringPrintf("Failed to initialize installation for DLC=%s", |
| 215 | id.c_str())); |
Amin Hassani | 6d0367d | 2020-05-10 18:07:03 -0700 | [diff] [blame] | 216 | return false; |
Amin Hassani | a69f32e | 2020-03-30 15:20:42 -0700 | [diff] [blame] | 217 | } |
Amin Hassani | 9a3f20c | 2020-05-25 16:38:33 -0700 | [diff] [blame] | 218 | |
| 219 | // If the DLC is now in installing state, it means it now needs update_engine |
| 220 | // installation. |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 221 | *external_install_needed = dlc->IsInstalling(); |
Amin Hassani | a69f32e | 2020-03-30 15:20:42 -0700 | [diff] [blame] | 222 | return true; |
Jae Hoon Kim | 823ead3 | 2019-12-13 09:30:09 -0800 | [diff] [blame] | 223 | } |
| 224 | |
Amin Hassani | 40c0f11 | 2020-04-15 09:55:00 -0700 | [diff] [blame] | 225 | bool DlcManager::Uninstall(const DlcId& id, ErrorPtr* err) { |
Jae Hoon Kim | c98e3a3 | 2020-03-13 09:40:48 -0700 | [diff] [blame] | 226 | DCHECK(err); |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 227 | auto* dlc = GetDlc(id, err); |
| 228 | if (dlc == nullptr) { |
Jae Hoon Kim | 823ead3 | 2019-12-13 09:30:09 -0800 | [diff] [blame] | 229 | return false; |
| 230 | } |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 231 | return dlc->Uninstall(err); |
Amin Hassani | 40c0f11 | 2020-04-15 09:55:00 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | bool DlcManager::Purge(const DlcId& id, ErrorPtr* err) { |
| 235 | DCHECK(err); |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 236 | auto* dlc = GetDlc(id, err); |
| 237 | if (dlc == nullptr) { |
Amin Hassani | 40c0f11 | 2020-04-15 09:55:00 -0700 | [diff] [blame] | 238 | return false; |
| 239 | } |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 240 | return dlc->Purge(err); |
Amin Hassani | a69f32e | 2020-03-30 15:20:42 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Jae Hoon Kim | 53514af | 2020-07-27 11:50:26 -0700 | [diff] [blame] | 243 | bool DlcManager::FinishInstall(const DlcId& id, ErrorPtr* err) { |
Amin Hassani | a69f32e | 2020-03-30 15:20:42 -0700 | [diff] [blame] | 244 | DCHECK(err); |
Jae Hoon Kim | 53514af | 2020-07-27 11:50:26 -0700 | [diff] [blame] | 245 | auto dlc = GetDlc(id, err); |
| 246 | if (!dlc) { |
| 247 | *err = Error::Create(FROM_HERE, kErrorInvalidDlc, |
| 248 | "Finishing installation for invalid DLC."); |
| 249 | return false; |
Jae Hoon Kim | fdaa53a | 2020-03-13 11:28:36 -0700 | [diff] [blame] | 250 | } |
Jae Hoon Kim | 53514af | 2020-07-27 11:50:26 -0700 | [diff] [blame] | 251 | if (!dlc->IsInstalling()) { |
| 252 | *err = Error::Create( |
| 253 | FROM_HERE, kErrorInternal, |
| 254 | "Finishing installation for a DLC that is not being installed."); |
| 255 | return false; |
| 256 | } |
| 257 | return dlc->FinishInstall(/*installed_by_ue=*/true, err); |
Amin Hassani | a69f32e | 2020-03-30 15:20:42 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Andrew | bcc4bd8 | 2020-06-11 14:23:55 -0700 | [diff] [blame] | 260 | bool DlcManager::CancelInstall(const DlcId& id, |
| 261 | const ErrorPtr& err_in, |
| 262 | ErrorPtr* err) { |
Amin Hassani | 9a3f20c | 2020-05-25 16:38:33 -0700 | [diff] [blame] | 263 | DCHECK(err); |
Amin Hassani | 1ac2831 | 2020-06-04 18:16:30 -0700 | [diff] [blame] | 264 | auto* dlc = GetDlc(id, err); |
| 265 | if (dlc == nullptr) { |
Jae Hoon Kim | 53514af | 2020-07-27 11:50:26 -0700 | [diff] [blame] | 266 | *err = Error::Create(FROM_HERE, kErrorInvalidDlc, |
| 267 | "Cancelling installation for invalid DLC."); |
Amin Hassani | 9a3f20c | 2020-05-25 16:38:33 -0700 | [diff] [blame] | 268 | return false; |
| 269 | } |
Andrew | bcc4bd8 | 2020-06-11 14:23:55 -0700 | [diff] [blame] | 270 | return !dlc->IsInstalling() || dlc->CancelInstall(err_in, err); |
Amin Hassani | 9a3f20c | 2020-05-25 16:38:33 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Amin Hassani | 78a5ec8 | 2020-05-19 09:47:49 -0700 | [diff] [blame] | 273 | void DlcManager::ChangeProgress(double progress) { |
| 274 | for (auto& pr : supported_) { |
| 275 | auto& dlc = pr.second; |
| 276 | if (dlc.IsInstalling()) { |
| 277 | dlc.ChangeProgress(progress); |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
Jae Hoon Kim | 823ead3 | 2019-12-13 09:30:09 -0800 | [diff] [blame] | 282 | } // namespace dlcservice |