update_engine: Support DLC Cohorts

UE at the moment doesn't send the correct cohorts to Omaha for DLCs. In
fact, the platform cohorts that are persisted are used for all DLCs.
This is incorrect and this CL fixes it.

```
Example DLC Response:
... cohort="1:7:" cohortname="eve_dlc_pita_canary"...

localhost ~ # ls /var/lib/update_engine/prefs/dlc/pita/omaha-cohort*
/var/lib/update_engine/prefs/dlc/pita/omaha-cohort
/var/lib/update_engine/prefs/dlc/pita/omaha-cohort-name
localhost ~ # cat /var/lib/update_engine/prefs/dlc/pita/omaha-cohort
1:7:
localhost ~ # cat
/var/lib/update_engine/prefs/dlc/pita/omaha-cohort-name
eve_dlc_pita_canary
```

BUG=b:162463872
TEST=FEATURES=test emerge-$B update_engine
TEST=# cros deploy + comment above

Change-Id: Ie503f0a63d3b19a51abb88379cb2e8f85919858b
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2515072
Tested-by: Jae Hoon Kim <kimjae@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/cros/omaha_request_builder_xml.cc b/cros/omaha_request_builder_xml.cc
index 43ee548..739abbf 100644
--- a/cros/omaha_request_builder_xml.cc
+++ b/cros/omaha_request_builder_xml.cc
@@ -215,9 +215,10 @@
   return app_body;
 }
 
-string OmahaRequestBuilderXml::GetCohortArg(const string arg_name,
-                                            const string prefs_key,
-                                            const string override_value) const {
+string OmahaRequestBuilderXml::GetCohortArg(
+    const string& arg_name,
+    const string& prefs_key,
+    const string& override_value) const {
   string cohort_value;
   if (!override_value.empty()) {
     // |override_value| take precedence over pref value.
@@ -296,14 +297,30 @@
   }
 
   string app_cohort_args;
-  app_cohort_args += GetCohortArg("cohort", kPrefsOmahaCohort);
-  app_cohort_args += GetCohortArg("cohortname", kPrefsOmahaCohortName);
+  string cohort_key = kPrefsOmahaCohort;
+  string cohortname_key = kPrefsOmahaCohortName;
+  string cohorthint_key = kPrefsOmahaCohortHint;
 
+  // Override the cohort keys for DLC App IDs.
+  const auto& dlc_apps_params = params_->dlc_apps_params();
+  auto itr = dlc_apps_params.find(app_data.id);
+  if (itr != dlc_apps_params.end()) {
+    auto dlc_id = itr->second.name;
+    cohort_key =
+        prefs_->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsOmahaCohort});
+    cohortname_key =
+        prefs_->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsOmahaCohortName});
+    cohorthint_key =
+        prefs_->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsOmahaCohortHint});
+  }
+
+  app_cohort_args += GetCohortArg("cohort", cohort_key);
+  app_cohort_args += GetCohortArg("cohortname", cohortname_key);
   // Policy provided value overrides pref.
-  string autoupdate_token = params_->autoupdate_token();
-  app_cohort_args += GetCohortArg("cohorthint",
-                                  kPrefsOmahaCohortHint,
-                                  autoupdate_token /* override_value */);
+  app_cohort_args +=
+      GetCohortArg("cohorthint",
+                   cohorthint_key,
+                   params_->autoupdate_token() /* override_value */);
 
   string fingerprint_arg;
   if (!params_->os_build_fingerprint().empty()) {