Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/browser/chromeos/status/input_method_menu.cc

Issue 9651023: Get the ProfileService object after NOTIFICATION_SESSION_STARTED is sent to Chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/status/input_method_menu.h" 5 #include "chrome/browser/chromeos/status/input_method_menu.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/string_split.h" 10 #include "base/string_split.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chromeos/input_method/input_method_util.h" 15 #include "chrome/browser/chromeos/input_method/input_method_util.h"
16 #include "chrome/browser/chromeos/language_preferences.h" 16 #include "chrome/browser/chromeos/language_preferences.h"
17 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" 17 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h"
18 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/prefs/pref_service.h"
20 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
21 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/user_metrics.h" 24 #include "content/public/browser/user_metrics.h"
23 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
24 #include "grit/theme_resources.h" 26 #include "grit/theme_resources.h"
25 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/models/simple_menu_model.h" 28 #include "ui/base/models/simple_menu_model.h"
27 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/views/controls/menu/menu_model_adapter.h" 30 #include "ui/views/controls/menu/menu_model_adapter.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 const size_t kMappingFromIdToIndicatorTextLen = 120 const size_t kMappingFromIdToIndicatorTextLen =
119 ARRAYSIZE_UNSAFE(kMappingFromIdToIndicatorText); 121 ARRAYSIZE_UNSAFE(kMappingFromIdToIndicatorText);
120 122
121 // Returns the language name for the given |language_code|. 123 // Returns the language name for the given |language_code|.
122 string16 GetLanguageName(const std::string& language_code) { 124 string16 GetLanguageName(const std::string& language_code) {
123 const string16 language_name = l10n_util::GetDisplayNameForLocale( 125 const string16 language_name = l10n_util::GetDisplayNameForLocale(
124 language_code, g_browser_process->GetApplicationLocale(), true); 126 language_code, g_browser_process->GetApplicationLocale(), true);
125 return language_name; 127 return language_name;
126 } 128 }
127 129
130 PrefService* GetPrefService() {
131 Profile* profile = ProfileManager::GetDefaultProfile();
132 if (profile)
133 return profile->GetPrefs();
134 return NULL;
135 }
136
128 } // namespace 137 } // namespace
129 138
130 namespace chromeos { 139 namespace chromeos {
131 140
132 using input_method::InputMethodManager; 141 using input_method::InputMethodManager;
133 142
134 //////////////////////////////////////////////////////////////////////////////// 143 ////////////////////////////////////////////////////////////////////////////////
135 // InputMethodMenu 144 // InputMethodMenu
136 145
137 InputMethodMenu::InputMethodMenu(PrefService* pref_service, 146 InputMethodMenu::InputMethodMenu()
138 bool for_out_of_box_experience_dialog)
139 : initialized_prefs_(false), 147 : initialized_prefs_(false),
140 initialized_observers_(false), 148 initialized_observers_(false),
141 input_method_descriptors_(InputMethodManager::GetInstance()-> 149 input_method_descriptors_(InputMethodManager::GetInstance()->
142 GetActiveInputMethods()), 150 GetActiveInputMethods()),
143 model_(new ui::SimpleMenuModel(NULL)), 151 model_(new ui::SimpleMenuModel(NULL)),
144 ALLOW_THIS_IN_INITIALIZER_LIST(input_method_menu_delegate_( 152 ALLOW_THIS_IN_INITIALIZER_LIST(input_method_menu_delegate_(
145 new views::MenuModelAdapter(this))), 153 new views::MenuModelAdapter(this))),
146 input_method_menu_( 154 input_method_menu_(
147 new views::MenuItemView(input_method_menu_delegate_.get())), 155 new views::MenuItemView(input_method_menu_delegate_.get())),
148 input_method_menu_runner_(new views::MenuRunner(input_method_menu_)), 156 input_method_menu_runner_(new views::MenuRunner(input_method_menu_)),
149 minimum_input_method_menu_width_(0), 157 minimum_input_method_menu_width_(0),
150 menu_alignment_(views::MenuItemView::TOPRIGHT), 158 menu_alignment_(views::MenuItemView::TOPRIGHT) {
151 pref_service_(pref_service),
152 for_out_of_box_experience_dialog_(for_out_of_box_experience_dialog) {
153 DCHECK(input_method_descriptors_.get() && 159 DCHECK(input_method_descriptors_.get() &&
154 !input_method_descriptors_->empty()); 160 !input_method_descriptors_->empty());
155 161
156 // Sync current and previous input methods on Chrome prefs with ibus-daemon. 162 // Sync current and previous input methods on Chrome prefs with ibus-daemon.
157 if (pref_service_ && StatusAreaViewChromeos::IsBrowserMode()) { 163 if (StatusAreaViewChromeos::IsBrowserMode())
158 InitializePrefMembers(); 164 InitializePrefMembers();
159 }
160 165
161 if (StatusAreaViewChromeos::IsLoginMode()) { 166 if (StatusAreaViewChromeos::IsLoginMode()) {
162 registrar_.Add(this, 167 registrar_.Add(this,
163 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 168 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
164 content::NotificationService::AllSources()); 169 content::NotificationService::AllSources());
165 #if defined(USE_AURA) 170 #if defined(USE_AURA)
166 // On Aura status area is not recreated on sign in. Instead, 2 notifications 171 // On Aura status area is not recreated on sign in. Instead, 2 notifications
167 // are sent to Chrome on sign in: NOTIFICATION_LOGIN_USER_CHANGED with 172 // are sent to Chrome on sign in: NOTIFICATION_LOGIN_USER_CHANGED with
168 // StatusAreaViewChromeos::IsLoginMode() and NOTIFICATION_SESSION_STARTED 173 // StatusAreaViewChromeos::IsLoginMode() and NOTIFICATION_SESSION_STARTED
169 // with StatusAreaViewChromeos::IsBrowserMode(). 174 // with StatusAreaViewChromeos::IsBrowserMode().
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 return property_list.at(index).is_selection_item_checked; 224 return property_list.at(index).is_selection_item_checked;
220 } 225 }
221 226
222 // Separator(s) or the "Customize language and input..." button. 227 // Separator(s) or the "Customize language and input..." button.
223 return false; 228 return false;
224 } 229 }
225 230
226 int InputMethodMenu::GetGroupIdAt(int index) const { 231 int InputMethodMenu::GetGroupIdAt(int index) const {
227 DCHECK_GE(index, 0); 232 DCHECK_GE(index, 0);
228 233
229 if (IndexIsInInputMethodList(index)) { 234 if (IndexIsInInputMethodList(index))
230 return for_out_of_box_experience_dialog_ ? 235 return kRadioGroupLanguage;
231 kRadioGroupNone : kRadioGroupLanguage;
232 }
233 236
234 if (GetPropertyIndex(index, &index)) { 237 if (GetPropertyIndex(index, &index)) {
235 const input_method::InputMethodPropertyList& property_list 238 const input_method::InputMethodPropertyList& property_list
236 = InputMethodManager::GetInstance()->GetCurrentInputMethodProperties(); 239 = InputMethodManager::GetInstance()->GetCurrentInputMethodProperties();
237 return property_list.at(index).selection_item_id; 240 return property_list.at(index).selection_item_id;
238 } 241 }
239 242
240 return kRadioGroupNone; 243 return kRadioGroupNone;
241 } 244 }
242 245
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 return model_->GetItemCount(); 289 return model_->GetItemCount();
287 } 290 }
288 291
289 ui::MenuModel::ItemType InputMethodMenu::GetTypeAt(int index) const { 292 ui::MenuModel::ItemType InputMethodMenu::GetTypeAt(int index) const {
290 DCHECK_GE(index, 0); 293 DCHECK_GE(index, 0);
291 294
292 if (IndexPointsToConfigureImeMenuItem(index)) { 295 if (IndexPointsToConfigureImeMenuItem(index)) {
293 return ui::MenuModel::TYPE_COMMAND; // "Customize language and input" 296 return ui::MenuModel::TYPE_COMMAND; // "Customize language and input"
294 } 297 }
295 298
296 if (IndexIsInInputMethodList(index)) { 299 if (IndexIsInInputMethodList(index))
297 return for_out_of_box_experience_dialog_ ? 300 return ui::MenuModel::TYPE_RADIO;
298 ui::MenuModel::TYPE_COMMAND : ui::MenuModel::TYPE_RADIO;
299 }
300 301
301 if (GetPropertyIndex(index, &index)) { 302 if (GetPropertyIndex(index, &index)) {
302 const input_method::InputMethodPropertyList& property_list 303 const input_method::InputMethodPropertyList& property_list
303 = InputMethodManager::GetInstance()->GetCurrentInputMethodProperties(); 304 = InputMethodManager::GetInstance()->GetCurrentInputMethodProperties();
304 if (property_list.at(index).is_selection_item) { 305 if (property_list.at(index).is_selection_item) {
305 return ui::MenuModel::TYPE_RADIO; 306 return ui::MenuModel::TYPE_RADIO;
306 } 307 }
307 return ui::MenuModel::TYPE_COMMAND; 308 return ui::MenuModel::TYPE_COMMAND;
308 } 309 }
309 310
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 size_t num_active_input_methods) { 416 size_t num_active_input_methods) {
416 UpdateUIFromInputMethod(current_input_method, num_active_input_methods); 417 UpdateUIFromInputMethod(current_input_method, num_active_input_methods);
417 } 418 }
418 419
419 // TODO(yusukes): Move code for handling preferences to chromeos/input_method/. 420 // TODO(yusukes): Move code for handling preferences to chromeos/input_method/.
420 void InputMethodMenu::PreferenceUpdateNeeded( 421 void InputMethodMenu::PreferenceUpdateNeeded(
421 InputMethodManager* manager, 422 InputMethodManager* manager,
422 const input_method::InputMethodDescriptor& previous_input_method, 423 const input_method::InputMethodDescriptor& previous_input_method,
423 const input_method::InputMethodDescriptor& current_input_method) { 424 const input_method::InputMethodDescriptor& current_input_method) {
424 if (StatusAreaViewChromeos::IsBrowserMode()) { 425 if (StatusAreaViewChromeos::IsBrowserMode()) {
425 if (pref_service_) { // make sure we're not in unit tests. 426 if (initialized_prefs_) { // make sure we're not in unit tests.
426 // Sometimes (e.g. initial boot) |previous_input_method.id()| is empty. 427 // Sometimes (e.g. initial boot) |previous_input_method.id()| is empty.
427 previous_input_method_pref_.SetValue(previous_input_method.id()); 428 previous_input_method_pref_.SetValue(previous_input_method.id());
428 current_input_method_pref_.SetValue(current_input_method.id()); 429 current_input_method_pref_.SetValue(current_input_method.id());
429 } 430 }
430 } else if (StatusAreaViewChromeos::IsLoginMode()) { 431 } else if (StatusAreaViewChromeos::IsLoginMode()) {
431 if (g_browser_process && g_browser_process->local_state()) { 432 if (g_browser_process && g_browser_process->local_state()) {
432 g_browser_process->local_state()->SetString( 433 g_browser_process->local_state()->SetString(
433 language_prefs::kPreferredKeyboardLayout, current_input_method.id()); 434 language_prefs::kPreferredKeyboardLayout, current_input_method.id());
434 } 435 }
435 } 436 }
(...skipping 19 matching lines...) Expand all
455 manager->GetCurrentInputMethod(); 456 manager->GetCurrentInputMethod();
456 size_t num_active_input_methods = manager->GetNumActiveInputMethods(); 457 size_t num_active_input_methods = manager->GetNumActiveInputMethods();
457 UpdateUIFromInputMethod(input_method, num_active_input_methods); 458 UpdateUIFromInputMethod(input_method, num_active_input_methods);
458 } 459 }
459 } 460 }
460 461
461 void InputMethodMenu::FirstObserverIsAdded(InputMethodManager* manager) { 462 void InputMethodMenu::FirstObserverIsAdded(InputMethodManager* manager) {
462 // NOTICE: Since this function might be called from the constructor of this 463 // NOTICE: Since this function might be called from the constructor of this
463 // class, it's better to avoid calling virtual functions. 464 // class, it's better to avoid calling virtual functions.
464 465
465 if (pref_service_ && (StatusAreaViewChromeos::IsBrowserMode())) { 466 if (initialized_prefs_ && StatusAreaViewChromeos::IsBrowserMode()) {
466 // Get the input method name in the Preferences file which was in use last 467 // Get the input method name in the Preferences file which was in use last
467 // time, and switch to the method. We remember two input method names in the 468 // time, and switch to the method. We remember two input method names in the
468 // preference so that the Control+space hot-key could work fine from the 469 // preference so that the Control+space hot-key could work fine from the
469 // beginning. InputMethodChanged() will be called soon and the indicator 470 // beginning. InputMethodChanged() will be called soon and the indicator
470 // will be updated. 471 // will be updated.
471 const std::string previous_input_method_id = 472 const std::string previous_input_method_id =
472 previous_input_method_pref_.GetValue(); 473 previous_input_method_pref_.GetValue();
473 if (!previous_input_method_id.empty()) { 474 if (!previous_input_method_id.empty()) {
474 manager->ChangeInputMethod(previous_input_method_id); 475 manager->ChangeInputMethod(previous_input_method_id);
475 } 476 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 manager->RemovePreLoginPreferenceObserver(this); 736 manager->RemovePreLoginPreferenceObserver(this);
736 } else if (StatusAreaViewChromeos::IsBrowserMode()) { 737 } else if (StatusAreaViewChromeos::IsBrowserMode()) {
737 manager->RemovePostLoginPreferenceObserver(this); 738 manager->RemovePostLoginPreferenceObserver(this);
738 } 739 }
739 manager->RemoveObserver(this); 740 manager->RemoveObserver(this);
740 initialized_observers_ = false; 741 initialized_observers_ = false;
741 } 742 }
742 743
743 void InputMethodMenu::InitializePrefMembers() { 744 void InputMethodMenu::InitializePrefMembers() {
744 if (!initialized_prefs_) { 745 if (!initialized_prefs_) {
745 initialized_prefs_ = true; 746 PrefService* pref_service = GetPrefService();
746 previous_input_method_pref_.Init( 747 if (pref_service) {
747 prefs::kLanguagePreviousInputMethod, pref_service_, this); 748 initialized_prefs_ = true;
748 current_input_method_pref_.Init( 749 previous_input_method_pref_.Init(
749 prefs::kLanguageCurrentInputMethod, pref_service_, this); 750 prefs::kLanguagePreviousInputMethod, pref_service, this);
751 current_input_method_pref_.Init(
752 prefs::kLanguageCurrentInputMethod, pref_service, this);
753 }
750 } 754 }
751 } 755 }
752 756
753 } // namespace chromeos 757 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/input_method_menu.h ('k') | chrome/browser/chromeos/status/input_method_menu_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698