Commit 2819a419 authored by Jing Wang's avatar Jing Wang Committed by Commit Bot

Reset pref change registrar when profile is destroyed

Test: tested on Chrome on Linux to verify the crash is gone.
Bug: 1109386
Change-Id: I57761a67b0765d5c0c39e7bafa88a711c5478cc2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2318890
Commit-Queue: Jing Wang <jiwan@chromium.org>
Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792555}
parent 6f0f8a2c
...@@ -160,6 +160,7 @@ void InputMethodEngineBase::Initialize( ...@@ -160,6 +160,7 @@ void InputMethodEngineBase::Initialize(
profile_ = profile; profile_ = profile;
if (profile_ && profile->GetPrefs()) { if (profile_ && profile->GetPrefs()) {
profile_observer_.Add(profile);
input_method_settings_snapshot_ = input_method_settings_snapshot_ =
profile->GetPrefs() profile->GetPrefs()
->GetDictionary(prefs::kLanguageInputMethodSpecificSettings) ->GetDictionary(prefs::kLanguageInputMethodSpecificSettings)
...@@ -193,6 +194,14 @@ void InputMethodEngineBase::OnInputMethodOptionsChanged() { ...@@ -193,6 +194,14 @@ void InputMethodEngineBase::OnInputMethodOptionsChanged() {
input_method_settings_snapshot_ = new_settings->Clone(); input_method_settings_snapshot_ = new_settings->Clone();
} }
void InputMethodEngineBase::OnProfileWillBeDestroyed(Profile* profile) {
if (profile == profile_) {
pref_change_registrar_.reset();
profile_observer_.Remove(profile_);
profile_ = nullptr;
}
}
void InputMethodEngineBase::FocusIn( void InputMethodEngineBase::FocusIn(
const ui::IMEEngineHandlerInterface::InputContext& input_context) { const ui::IMEEngineHandlerInterface::InputContext& input_context) {
current_input_type_ = input_context.type; current_input_type_ = input_context.type;
......
...@@ -10,16 +10,17 @@ ...@@ -10,16 +10,17 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/scoped_observer.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
#include "ui/base/ime/chromeos/input_method_descriptor.h" #include "ui/base/ime/chromeos/input_method_descriptor.h"
#include "ui/base/ime/composition_text.h" #include "ui/base/ime/composition_text.h"
#include "ui/base/ime/ime_engine_handler_interface.h" #include "ui/base/ime/ime_engine_handler_interface.h"
#include "url/gurl.h" #include "url/gurl.h"
class Profile;
namespace ui { namespace ui {
struct CompositionText; struct CompositionText;
class IMEEngineHandlerInterface; class IMEEngineHandlerInterface;
...@@ -32,7 +33,8 @@ struct AssistiveWindowButton; ...@@ -32,7 +33,8 @@ struct AssistiveWindowButton;
namespace chromeos { namespace chromeos {
class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface { class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface,
public ProfileObserver {
public: public:
struct KeyboardEvent { struct KeyboardEvent {
KeyboardEvent(); KeyboardEvent();
...@@ -240,11 +242,18 @@ class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface { ...@@ -240,11 +242,18 @@ class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface {
int GetContextIdForTesting() const { return context_id_; } int GetContextIdForTesting() const { return context_id_; }
PrefChangeRegistrar* GetPrefChangeRegistrarForTesting() const {
return pref_change_registrar_.get();
}
// Get the composition bounds. // Get the composition bounds.
const std::vector<gfx::Rect>& composition_bounds() const { const std::vector<gfx::Rect>& composition_bounds() const {
return composition_bounds_; return composition_bounds_;
} }
// ProfileObserver:
void OnProfileWillBeDestroyed(Profile* profile) override;
protected: protected:
struct PendingKeyEvent { struct PendingKeyEvent {
PendingKeyEvent( PendingKeyEvent(
...@@ -346,6 +355,8 @@ class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface { ...@@ -346,6 +355,8 @@ class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface {
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
base::Value input_method_settings_snapshot_; base::Value input_method_settings_snapshot_;
ScopedObserver<Profile, ProfileObserver> profile_observer_{this};
}; };
} // namespace chromeos } // namespace chromeos
......
...@@ -594,6 +594,12 @@ IN_PROC_BROWSER_TEST_F(NativeInputMethodEngineTest, ...@@ -594,6 +594,12 @@ IN_PROC_BROWSER_TEST_F(NativeInputMethodEngineTest,
EXPECT_EQ(observer_->GetChangedEngineId(), "pinyin"); EXPECT_EQ(observer_->GetChangedEngineId(), "pinyin");
} }
IN_PROC_BROWSER_TEST_F(NativeInputMethodEngineTest, DestroyProfile) {
EXPECT_NE(engine_.GetPrefChangeRegistrarForTesting(), nullptr);
profile_->MaybeSendDestroyedNotification();
EXPECT_EQ(engine_.GetPrefChangeRegistrarForTesting(), nullptr);
}
class NativeInputMethodEngineAssistiveOff : public InProcessBrowserTest { class NativeInputMethodEngineAssistiveOff : public InProcessBrowserTest {
public: public:
NativeInputMethodEngineAssistiveOff() { NativeInputMethodEngineAssistiveOff() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment