Remove ARC IMEs from prefs in Shutdown().

These prefs should be removed in Shutdown() instead of the destructor
because in the destructor Profile is already destructing.

Bug: b/123020953
Test: Not crash when logging out.
Change-Id: I8a9b728e9e0b032dbaebbe2d59dc0ac5134c4e12
Reviewed-on: https://chromium-review.googlesource.com/c/1426347
Reviewed-by: Tetsui Ohkubo <tetsui@chromium.org>
Commit-Queue: Yuichiro Hanada <yhanada@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625058}
diff --git a/chrome/browser/chromeos/arc/input_method_manager/arc_input_method_manager_service.cc b/chrome/browser/chromeos/arc/input_method_manager/arc_input_method_manager_service.cc
index 28aae18..a00b265 100644
--- a/chrome/browser/chromeos/arc/input_method_manager/arc_input_method_manager_service.cc
+++ b/chrome/browser/chromeos/arc/input_method_manager/arc_input_method_manager_service.cc
@@ -263,20 +263,7 @@
   }
 }
 
-ArcInputMethodManagerService::~ArcInputMethodManagerService() {
-  // Remove any Arc IME entry from preferences before shutting down.
-  // IME states (installed/enabled/disabled) are stored in Android's settings,
-  // that will be restored after Arc container starts next time.
-  RemoveArcIMEFromPrefs();
-  profile_->GetPrefs()->CommitPendingWrite();
-
-  if (TabletModeClient::Get())
-    TabletModeClient::Get()->RemoveObserver(tablet_mode_observer_.get());
-
-  auto* imm = chromeos::input_method::InputMethodManager::Get();
-  imm->RemoveImeMenuObserver(this);
-  imm->RemoveObserver(this);
-}
+ArcInputMethodManagerService::~ArcInputMethodManagerService() = default;
 
 void ArcInputMethodManagerService::SetInputMethodManagerBridgeForTesting(
     std::unique_ptr<ArcInputMethodManagerBridge> test_bridge) {
@@ -291,6 +278,21 @@
   observers_.RemoveObserver(observer);
 }
 
+void ArcInputMethodManagerService::Shutdown() {
+  // Remove any Arc IME entry from preferences before shutting down.
+  // IME states (installed/enabled/disabled) are stored in Android's settings,
+  // that will be restored after Arc container starts next time.
+  RemoveArcIMEFromPrefs();
+  profile_->GetPrefs()->CommitPendingWrite();
+
+  if (TabletModeClient::Get())
+    TabletModeClient::Get()->RemoveObserver(tablet_mode_observer_.get());
+
+  auto* imm = chromeos::input_method::InputMethodManager::Get();
+  imm->RemoveImeMenuObserver(this);
+  imm->RemoveObserver(this);
+}
+
 void ArcInputMethodManagerService::OnActiveImeChanged(
     const std::string& ime_id) {
   if (ime_id == kChromeOSIMEIdInArcContainer) {
diff --git a/chrome/browser/chromeos/arc/input_method_manager/arc_input_method_manager_service.h b/chrome/browser/chromeos/arc/input_method_manager/arc_input_method_manager_service.h
index 36632a3..8ae044d 100644
--- a/chrome/browser/chromeos/arc/input_method_manager/arc_input_method_manager_service.h
+++ b/chrome/browser/chromeos/arc/input_method_manager/arc_input_method_manager_service.h
@@ -61,6 +61,9 @@
   void AddObserver(Observer* observer);
   void RemoveObserver(Observer* observer);
 
+  // KeyedService overrides:
+  void Shutdown() override;
+
   // ArcInputMethodManagerBridge::Delegate overrides:
   void OnActiveImeChanged(const std::string& ime_id) override;
   void OnImeDisabled(const std::string& ime_id) override;