Add {Get,Set}CohortHint interface.

Export the "cohort hint" getter and setter in the client interfaces
(D-Bus and Binder). The cohort hint is sent to Omaha on every update
check request but can be ignored and/or reset by Omaha on every
response.

Other minor linter fixes to the affected files.

Bug: 31740109
Test: Build with D-Bus and with Binder.

(cherry picked from commit 5b5fa8b412312a41cfd4d7ab475b54d4f730ed2a)

Change-Id: Ieb40c2d4bbe2ce926d54b6348b22f2840d8327db
Reviewed-on: https://chromium-review.googlesource.com/395206
Commit-Ready: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Christopher Book <cbook@chromium.org>
diff --git a/common_service.cc b/common_service.cc
index ade5349..20f55ab 100644
--- a/common_service.cc
+++ b/common_service.cc
@@ -187,6 +187,37 @@
   return true;
 }
 
+bool UpdateEngineService::SetCohortHint(ErrorPtr* error,
+                                        string in_cohort_hint) {
+  PrefsInterface* prefs = system_state_->prefs();
+
+  // It is ok to override the cohort hint with an invalid value since it is
+  // stored in stateful partition. The code reading it should sanitize it
+  // anyway.
+  if (!prefs->SetString(kPrefsOmahaCohortHint, in_cohort_hint)) {
+    LogAndSetError(
+        error,
+        FROM_HERE,
+        StringPrintf("Error setting the cohort hint value to \"%s\".",
+                     in_cohort_hint.c_str()));
+    return false;
+  }
+  return true;
+}
+
+bool UpdateEngineService::GetCohortHint(ErrorPtr* error,
+                                        string* out_cohort_hint) {
+  PrefsInterface* prefs = system_state_->prefs();
+
+  *out_cohort_hint = "";
+  if (prefs->Exists(kPrefsOmahaCohortHint) &&
+      !prefs->GetString(kPrefsOmahaCohortHint, out_cohort_hint)) {
+    LogAndSetError(error, FROM_HERE, "Error getting the cohort hint.");
+    return false;
+  }
+  return true;
+}
+
 bool UpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error,
                                                  bool in_enabled) {
   PrefsInterface* prefs = system_state_->prefs();