Starts running a task. This function will return before the task is finished, but will resolve or reject the |promise| when it finishes.
| 207 | // Starts running a task. This function will return before the task is |
| 208 | // finished, but will resolve or reject the |promise| when it finishes. |
| 209 | static void Run( |
| 210 | BrowsingDataRemover* remover, |
| 211 | gin_helper::Promise<void> promise, |
| 212 | BrowsingDataRemover::DataType data_type_mask, |
| 213 | std::vector<url::Origin> origins, |
| 214 | BrowsingDataFilterBuilder::Mode filter_mode, |
| 215 | BrowsingDataFilterBuilder::OriginMatchingMode origin_matching_mode) { |
| 216 | auto* task = new ClearDataTask(std::move(promise)); |
| 217 | |
| 218 | // This method counts as an operation. This is important so we can call |
| 219 | // `OnOperationFinished` at the end of this method as a fallback if all the |
| 220 | // other operations finished while this method was still executing |
| 221 | task->operations_running_ = 1; |
| 222 | |
| 223 | // Cookies are scoped more broadly than other types of data, so if we are |
| 224 | // filtering then we need to do it at the registrable domain level |
| 225 | if (!origins.empty() && |
| 226 | data_type_mask & BrowsingDataRemover::DATA_TYPE_COOKIES) { |
| 227 | data_type_mask &= ~BrowsingDataRemover::DATA_TYPE_COOKIES; |
| 228 | |
| 229 | auto cookies_filter_builder = |
| 230 | BrowsingDataFilterBuilder::Create(filter_mode); |
| 231 | |
| 232 | for (const url::Origin& origin : origins) { |
| 233 | std::string domain = GetDomainAndRegistry( |
| 234 | origin, |
| 235 | net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 236 | if (domain.empty()) { |
| 237 | domain = origin.host(); |
| 238 | } |
| 239 | cookies_filter_builder->AddRegisterableDomain(domain); |
| 240 | } |
| 241 | |
| 242 | StartOperation(task, remover, BrowsingDataRemover::DATA_TYPE_COOKIES, |
| 243 | std::move(cookies_filter_builder)); |
| 244 | } |
| 245 | |
| 246 | // If cookies aren't the only data type and weren't handled above, then we |
| 247 | // can start an operation that is scoped to origins |
| 248 | if (data_type_mask) { |
| 249 | auto filter_builder = |
| 250 | BrowsingDataFilterBuilder::Create(filter_mode, origin_matching_mode); |
| 251 | |
| 252 | for (auto const& origin : origins) { |
| 253 | filter_builder->AddOrigin(origin); |
| 254 | } |
| 255 | |
| 256 | StartOperation(task, remover, data_type_mask, std::move(filter_builder)); |
| 257 | } |
| 258 | |
| 259 | // This static method counts as an operation. |
| 260 | task->OnOperationFinished(nullptr, std::nullopt); |
| 261 | } |
| 262 | |
| 263 | private: |
| 264 | // An individual |content::BrowsingDataRemover::Remove...| operation as part |
no test coverage detected