This source file includes following definitions.
- state_
- Observe
#include "chrome/browser/chromeos/input_method/browser_state_monitor.h"
#include "base/logging.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/input_method/input_method_util.h"
#include "chromeos/ime/input_method_delegate.h"
#include "content/public/browser/notification_service.h"
namespace chromeos {
namespace input_method {
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,
content::NotificationService::AllSources());
notification_registrar_.Add(this,
chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources());
notification_registrar_.Add(this,
chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
content::NotificationService::AllSources());
notification_registrar_.Add(this,
chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
if (!observer_.is_null())
observer_.Run(state_);
}
BrowserStateMonitor::~BrowserStateMonitor() {
}
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: {
state_ = InputMethodManager::STATE_TERMINATING;
break;
}
case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
DVLOG(1) << "Received chrome::NOTIFICATION_LOGIN_USER_CHANGED";
state_ = InputMethodManager::STATE_BROWSER_SCREEN;
break;
}
case chrome::NOTIFICATION_SESSION_STARTED: {
DVLOG(1) << "Received chrome::NOTIFICATION_SESSION_STARTED";
state_ = InputMethodManager::STATE_BROWSER_SCREEN;
break;
}
case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: {
const bool is_screen_locked = *content::Details<bool>(details).ptr();
state_ = is_screen_locked ? InputMethodManager::STATE_LOCK_SCREEN :
InputMethodManager::STATE_BROWSER_SCREEN;
break;
}
default: {
NOTREACHED();
break;
}
}
if (old_state != state_ && !observer_.is_null())
observer_.Run(state_);
}
}
}