cros: Allow demo session to change locale and limit it to one session

We should allow demo session users to change locale from Settings,
which takes effect after a restart. But by the second time the session
restarts, the system should revert to the original locale.

This CL tries to simulate the following user actions:

1) In the Settings page, you can find the "Currently displayed" locale
   (A), which comes from the kApplicationLocale in user profile.
   When you select locale B, the Settings page calls |ChangeAppLocale|
   but it requires a restart to take effect. Before the restart,
   there's no visible UI change.

2) After restart B is displayed, now go to Settings and change the
   locale back to A.

3) After a second restart A is displayed. We can assume the system is
   now in the same state with 1).

So we could save the value A as the original default locale and
whenever we detect there's a difference between A and the current
locale, call |ChangeAppLocale| to change it back which takes effect in
the next session.

It's safe to initialize the original default locale with the value A,
because there's no way for users to change locale prior to this CL.
This is also preferable than getting the value directly from enrollment
because:

1) By the time this code is deployed, there're devices already enrolled
   in demo mode so they can't go through OOBE again.

2) OOBE saves the locale pref in local state, and convert it to a pref
   in user profile (which Settings page uses). It's safe to be
   consistent with the Settings page so that the above user actions
   are simulated.

Bug: 877749
Change-Id: Iabbdfcf10fdb19f931c3122c21fd3af792b93191
Reviewed-on: https://chromium-review.googlesource.com/c/1292054
Reviewed-by: Michael Giuffrida <[email protected]>
Reviewed-by: Dominic Battré <[email protected]>
Reviewed-by: Stefan Kuhne <[email protected]>
Commit-Queue: Wenzhao (Colin) Zang <[email protected]>
Cr-Commit-Position: refs/heads/master@{#602011}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index be3fc5c8..8c86eb18 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -235,6 +235,7 @@
 #include "chrome/browser/chromeos/lock_screen_apps/state_controller.h"
 #include "chrome/browser/chromeos/login/demo_mode/demo_mode_detector.h"
 #include "chrome/browser/chromeos/login/demo_mode/demo_mode_resources_remover.h"
+#include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
 #include "chrome/browser/chromeos/login/demo_mode/demo_setup_controller.h"
 #include "chrome/browser/chromeos/login/quick_unlock/fingerprint_storage.h"
 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage_prefs.h"
@@ -482,6 +483,7 @@
   chromeos::ChromeUserManagerImpl::RegisterPrefs(registry);
   chromeos::DemoModeDetector::RegisterPrefs(registry);
   chromeos::DemoModeResourcesRemover::RegisterLocalStatePrefs(registry);
+  chromeos::DemoSession::RegisterLocalStatePrefs(registry);
   chromeos::DemoSetupController::RegisterLocalStatePrefs(registry);
   chromeos::DeviceOAuth2TokenService::RegisterPrefs(registry);
   chromeos::device_settings_cache::RegisterPrefs(registry);