Chromium Code Reviews| Index: chrome/browser/chromeos/input_method/browser_state_monitor.cc |
| diff --git a/chrome/browser/chromeos/input_method/browser_state_monitor.cc b/chrome/browser/chromeos/input_method/browser_state_monitor.cc |
| index c938d4ad99847c940a9cf594804bc2fe9122f0d9..2ae707fbf1e9c3a1d5f480e4a60f1344d17edb76 100644 |
| --- a/chrome/browser/chromeos/input_method/browser_state_monitor.cc |
| +++ b/chrome/browser/chromeos/input_method/browser_state_monitor.cc |
| @@ -13,10 +13,9 @@ |
| namespace chromeos { |
| namespace input_method { |
| -BrowserStateMonitor::BrowserStateMonitor(InputMethodManager* manager, |
| - InputMethodDelegate* delegate) |
| - : manager_(manager), |
| - delegate_(delegate), |
| +BrowserStateMonitor::BrowserStateMonitor( |
| + const base::Callback<void(InputMethodManager::State)>& observer) |
| + : observer_(observer), |
| state_(InputMethodManager::STATE_LOGIN_SCREEN) { |
| notification_registrar_.Add(this, |
| chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| @@ -33,51 +32,20 @@ BrowserStateMonitor::BrowserStateMonitor(InputMethodManager* manager, |
| chrome::NOTIFICATION_APP_TERMINATING, |
| content::NotificationService::AllSources()); |
| - manager_->SetState(state_); |
| - manager_->AddObserver(this); |
| + observer.Run(state_); |
| } |
| BrowserStateMonitor::~BrowserStateMonitor() { |
| - manager_->RemoveObserver(this); |
| } |
| -void BrowserStateMonitor::InputMethodChanged(InputMethodManager* manager, |
| - bool show_message) { |
| - DCHECK_EQ(manager_, manager); |
| - const std::string current_input_method = |
| - manager->GetCurrentInputMethod().id(); |
| - // Save the new input method id depending on the current browser state. |
| - switch (state_) { |
| - case InputMethodManager::STATE_LOGIN_SCREEN: |
| - if (!InputMethodUtil::IsKeyboardLayout(current_input_method)) { |
| - DVLOG(1) << "Only keyboard layouts are supported: " |
| - << current_input_method; |
| - return; |
| - } |
| - delegate_->SetSystemInputMethod(current_input_method); |
| - return; |
| - case InputMethodManager::STATE_BROWSER_SCREEN: |
| - delegate_->SetUserInputMethod(current_input_method); |
| - return; |
| - case InputMethodManager::STATE_LOCK_SCREEN: |
| - // We use a special set of input methods on the screen. Do not update. |
| - return; |
| - case InputMethodManager::STATE_TERMINATING: |
| - return; |
| - } |
| - NOTREACHED(); |
| -} |
| - |
| -void BrowserStateMonitor::InputMethodPropertyChanged( |
| - InputMethodManager* manager) {} |
| - |
| void BrowserStateMonitor::Observe( |
| int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| + const InputMethodManager::State old_state = state_; |
| switch (type) { |
| case chrome::NOTIFICATION_APP_TERMINATING: { |
| - SetState(InputMethodManager::STATE_TERMINATING); |
| + state_ = InputMethodManager::STATE_TERMINATING; |
| break; |
| } |
| case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { |
| @@ -87,7 +55,7 @@ void BrowserStateMonitor::Observe( |
| // as of writing, but it might be changed in the future (therefore we need |
| // to listen to NOTIFICATION_SESSION_STARTED as well.) |
| DVLOG(1) << "Received chrome::NOTIFICATION_LOGIN_USER_CHANGED"; |
| - SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
| + state_ = InputMethodManager::STATE_BROWSER_SCREEN; |
| break; |
| } |
| case chrome::NOTIFICATION_SESSION_STARTED: { |
| @@ -97,13 +65,13 @@ void BrowserStateMonitor::Observe( |
| // is sent in the PreProfileInit phase in case when Chrome crashes and |
| // restarts. |
| DVLOG(1) << "Received chrome::NOTIFICATION_SESSION_STARTED"; |
| - SetState(InputMethodManager::STATE_BROWSER_SCREEN); |
| + state_ = InputMethodManager::STATE_BROWSER_SCREEN; |
| break; |
| } |
| case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { |
| const bool is_screen_locked = *content::Details<bool>(details).ptr(); |
| - SetState(is_screen_locked ? InputMethodManager::STATE_LOCK_SCREEN : |
| - InputMethodManager::STATE_BROWSER_SCREEN); |
| + state_ = is_screen_locked ? InputMethodManager::STATE_LOCK_SCREEN : |
| + InputMethodManager::STATE_BROWSER_SCREEN; |
| break; |
| } |
| default: { |
| @@ -111,6 +79,10 @@ void BrowserStateMonitor::Observe( |
| break; |
| } |
| } |
| + |
| + if (old_state != state_) |
| + observer_.Run(state_); |
|
Seigo Nonaka
2012/12/11 04:33:04
null check? If |observer_| become never NULL, plea
erikwright (departed)
2012/12/11 16:39:44
Done.
|
| + |
| // Note: browser notifications are sent in the following order. |
| // |
| // Normal login: |
| @@ -133,12 +105,5 @@ void BrowserStateMonitor::Observe( |
| // early on Chrome crash/restart. |
| } |
| -void BrowserStateMonitor::SetState(InputMethodManager::State new_state) { |
| - const InputMethodManager::State old_state = state_; |
| - state_ = new_state; |
| - if (old_state != state_) |
| - manager_->SetState(state_); |
| -} |
| - |
| } // namespace input_method |
| } // namespace chromeos |