| OLD | NEW |
| 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/input_method/browser_state_monitor.h" | 5 #include "chrome/browser/chromeos/input_method/browser_state_monitor.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 9 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 10 #include "chromeos/ime/input_method_delegate.h" | 10 #include "chromeos/ime/input_method_delegate.h" |
| 11 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
| 12 | 12 |
| 13 namespace chromeos { | 13 namespace chromeos { |
| 14 namespace input_method { | 14 namespace input_method { |
| 15 | 15 |
| 16 BrowserStateMonitor::BrowserStateMonitor( | 16 BrowserStateMonitor::BrowserStateMonitor( |
| 17 const base::Callback<void(InputMethodManager::State)>& observer) | 17 const base::Callback<void(InputMethodManager::UIState)>& observer) |
| 18 : observer_(observer), | 18 : observer_(observer), state_(InputMethodManager::STATE_LOGIN_SCREEN) { |
| 19 state_(InputMethodManager::STATE_LOGIN_SCREEN) { | |
| 20 notification_registrar_.Add(this, | 19 notification_registrar_.Add(this, |
| 21 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 20 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 22 content::NotificationService::AllSources()); | 21 content::NotificationService::AllSources()); |
| 23 notification_registrar_.Add(this, | 22 notification_registrar_.Add(this, |
| 24 chrome::NOTIFICATION_SESSION_STARTED, | 23 chrome::NOTIFICATION_SESSION_STARTED, |
| 25 content::NotificationService::AllSources()); | 24 content::NotificationService::AllSources()); |
| 26 notification_registrar_.Add(this, | 25 notification_registrar_.Add(this, |
| 27 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 26 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
| 28 content::NotificationService::AllSources()); | 27 content::NotificationService::AllSources()); |
| 29 // We should not use ALL_BROWSERS_CLOSING here since logout might be cancelled | 28 // We should not use ALL_BROWSERS_CLOSING here since logout might be cancelled |
| 30 // by JavaScript after ALL_BROWSERS_CLOSING is sent (crosbug.com/11055). | 29 // by JavaScript after ALL_BROWSERS_CLOSING is sent (crosbug.com/11055). |
| 31 notification_registrar_.Add(this, | 30 notification_registrar_.Add(this, |
| 32 chrome::NOTIFICATION_APP_TERMINATING, | 31 chrome::NOTIFICATION_APP_TERMINATING, |
| 33 content::NotificationService::AllSources()); | 32 content::NotificationService::AllSources()); |
| 34 | 33 |
| 35 if (!observer_.is_null()) | 34 if (!observer_.is_null()) |
| 36 observer_.Run(state_); | 35 observer_.Run(state_); |
| 37 } | 36 } |
| 38 | 37 |
| 39 BrowserStateMonitor::~BrowserStateMonitor() { | 38 BrowserStateMonitor::~BrowserStateMonitor() { |
| 40 } | 39 } |
| 41 | 40 |
| 42 void BrowserStateMonitor::Observe( | 41 void BrowserStateMonitor::Observe( |
| 43 int type, | 42 int type, |
| 44 const content::NotificationSource& source, | 43 const content::NotificationSource& source, |
| 45 const content::NotificationDetails& details) { | 44 const content::NotificationDetails& details) { |
| 46 const InputMethodManager::State old_state = state_; | 45 const InputMethodManager::UIState old_state = state_; |
| 47 switch (type) { | 46 switch (type) { |
| 48 case chrome::NOTIFICATION_APP_TERMINATING: { | 47 case chrome::NOTIFICATION_APP_TERMINATING: { |
| 49 state_ = InputMethodManager::STATE_TERMINATING; | 48 state_ = InputMethodManager::STATE_TERMINATING; |
| 50 break; | 49 break; |
| 51 } | 50 } |
| 52 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { | 51 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { |
| 53 // The user logged in, but the browser window for user session is not yet | 52 // The user logged in, but the browser window for user session is not yet |
| 54 // ready. An initial input method hasn't been set to the manager. | 53 // ready. An initial input method hasn't been set to the manager. |
| 55 // Note that the notification is also sent when Chrome crashes/restarts | 54 // Note that the notification is also sent when Chrome crashes/restarts |
| 56 // as of writing, but it might be changed in the future (therefore we need | 55 // as of writing, but it might be changed in the future (therefore we need |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 // | 100 // |
| 102 // We have to be careful not to overwrite both local and user prefs when | 101 // We have to be careful not to overwrite both local and user prefs when |
| 103 // preloaded engine is set. Note that it does not work to do nothing in | 102 // preloaded engine is set. Note that it does not work to do nothing in |
| 104 // InputMethodChanged() between chrome::NOTIFICATION_LOGIN_USER_CHANGED and | 103 // InputMethodChanged() between chrome::NOTIFICATION_LOGIN_USER_CHANGED and |
| 105 // chrome::NOTIFICATION_SESSION_STARTED because SESSION_STARTED is sent very | 104 // chrome::NOTIFICATION_SESSION_STARTED because SESSION_STARTED is sent very |
| 106 // early on Chrome crash/restart. | 105 // early on Chrome crash/restart. |
| 107 } | 106 } |
| 108 | 107 |
| 109 } // namespace input_method | 108 } // namespace input_method |
| 110 } // namespace chromeos | 109 } // namespace chromeos |
| OLD | NEW |