| Index: chrome/browser/chromeos/status/input_method_menu.cc
|
| diff --git a/chrome/browser/chromeos/status/input_method_menu.cc b/chrome/browser/chromeos/status/input_method_menu.cc
|
| index fe78900396ca1f6b02e058ca7942d3505a9bdf99..4da7165b599be3970db3ac86691bb5a46ffbf2dc 100644
|
| --- a/chrome/browser/chromeos/status/input_method_menu.cc
|
| +++ b/chrome/browser/chromeos/status/input_method_menu.cc
|
| @@ -16,6 +16,8 @@
|
| #include "chrome/browser/chromeos/language_preferences.h"
|
| #include "chrome/browser/chromeos/status/status_area_view_chromeos.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| +#include "chrome/browser/prefs/pref_service.h"
|
| +#include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/common/chrome_notification_types.h"
|
| #include "chrome/common/pref_names.h"
|
| #include "content/public/browser/notification_service.h"
|
| @@ -125,6 +127,13 @@ string16 GetLanguageName(const std::string& language_code) {
|
| return language_name;
|
| }
|
|
|
| +PrefService* GetPrefService() {
|
| + Profile* profile = ProfileManager::GetDefaultProfile();
|
| + if (profile)
|
| + return profile->GetPrefs();
|
| + return NULL;
|
| +}
|
| +
|
| } // namespace
|
|
|
| namespace chromeos {
|
| @@ -134,8 +143,7 @@ using input_method::InputMethodManager;
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // InputMethodMenu
|
|
|
| -InputMethodMenu::InputMethodMenu(PrefService* pref_service,
|
| - bool for_out_of_box_experience_dialog)
|
| +InputMethodMenu::InputMethodMenu(bool for_out_of_box_experience_dialog)
|
| : initialized_prefs_(false),
|
| initialized_observers_(false),
|
| input_method_descriptors_(InputMethodManager::GetInstance()->
|
| @@ -148,15 +156,13 @@ InputMethodMenu::InputMethodMenu(PrefService* pref_service,
|
| input_method_menu_runner_(new views::MenuRunner(input_method_menu_)),
|
| minimum_input_method_menu_width_(0),
|
| menu_alignment_(views::MenuItemView::TOPRIGHT),
|
| - pref_service_(pref_service),
|
| for_out_of_box_experience_dialog_(for_out_of_box_experience_dialog) {
|
| DCHECK(input_method_descriptors_.get() &&
|
| !input_method_descriptors_->empty());
|
|
|
| // Sync current and previous input methods on Chrome prefs with ibus-daemon.
|
| - if (pref_service_ && StatusAreaViewChromeos::IsBrowserMode()) {
|
| + if (StatusAreaViewChromeos::IsBrowserMode())
|
| InitializePrefMembers();
|
| - }
|
|
|
| if (StatusAreaViewChromeos::IsLoginMode()) {
|
| registrar_.Add(this,
|
| @@ -422,7 +428,7 @@ void InputMethodMenu::PreferenceUpdateNeeded(
|
| const input_method::InputMethodDescriptor& previous_input_method,
|
| const input_method::InputMethodDescriptor& current_input_method) {
|
| if (StatusAreaViewChromeos::IsBrowserMode()) {
|
| - if (pref_service_) { // make sure we're not in unit tests.
|
| + if (initialized_prefs_) { // make sure we're not in unit tests.
|
| // Sometimes (e.g. initial boot) |previous_input_method.id()| is empty.
|
| previous_input_method_pref_.SetValue(previous_input_method.id());
|
| current_input_method_pref_.SetValue(current_input_method.id());
|
| @@ -462,7 +468,7 @@ void InputMethodMenu::FirstObserverIsAdded(InputMethodManager* manager) {
|
| // NOTICE: Since this function might be called from the constructor of this
|
| // class, it's better to avoid calling virtual functions.
|
|
|
| - if (pref_service_ && (StatusAreaViewChromeos::IsBrowserMode())) {
|
| + if (initialized_prefs_ && StatusAreaViewChromeos::IsBrowserMode()) {
|
| // Get the input method name in the Preferences file which was in use last
|
| // time, and switch to the method. We remember two input method names in the
|
| // preference so that the Control+space hot-key could work fine from the
|
| @@ -742,11 +748,14 @@ void InputMethodMenu::RemoveObservers() {
|
|
|
| void InputMethodMenu::InitializePrefMembers() {
|
| if (!initialized_prefs_) {
|
| - initialized_prefs_ = true;
|
| - previous_input_method_pref_.Init(
|
| - prefs::kLanguagePreviousInputMethod, pref_service_, this);
|
| - current_input_method_pref_.Init(
|
| - prefs::kLanguageCurrentInputMethod, pref_service_, this);
|
| + PrefService* pref_service = GetPrefService();
|
| + if (pref_service) {
|
| + initialized_prefs_ = true;
|
| + previous_input_method_pref_.Init(
|
| + prefs::kLanguagePreviousInputMethod, pref_service, this);
|
| + current_input_method_pref_.Init(
|
| + prefs::kLanguageCurrentInputMethod, pref_service, this);
|
| + }
|
| }
|
| }
|
|
|
|
|