summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/input_method/DEPS31
-rw-r--r--chrome/browser/chromeos/input_method/browser_state_monitor.cc64
-rw-r--r--chrome/browser/chromeos/input_method/browser_state_monitor.h34
-rw-r--r--chrome/browser/chromeos/input_method/browser_state_monitor_unittest.cc231
-rw-r--r--chrome/browser/chromeos/input_method/input_method_configuration.cc22
-rw-r--r--chrome/browser/chromeos/input_method/input_method_delegate.h4
-rw-r--r--chrome/browser/chromeos/input_method/input_method_delegate_impl.cc40
-rw-r--r--chrome/browser/chromeos/input_method/input_method_delegate_impl.h8
-rw-r--r--chrome/browser/chromeos/input_method/input_method_manager.h3
-rw-r--r--chrome/browser/chromeos/input_method/input_method_manager_impl.cc3
-rw-r--r--chrome/browser/chromeos/input_method/input_method_manager_impl.h13
-rw-r--r--chrome/browser/chromeos/input_method/input_method_persistence.cc96
-rw-r--r--chrome/browser/chromeos/input_method/input_method_persistence.h45
-rw-r--r--chrome/browser/chromeos/input_method/input_method_persistence_unittest.cc111
-rw-r--r--chrome/browser/chromeos/input_method/mock_input_method_delegate.cc16
-rw-r--r--chrome/browser/chromeos/input_method/mock_input_method_delegate.h27
-rw-r--r--chrome/browser/chromeos/input_method/mock_input_method_manager.cc7
-rw-r--r--chrome/browser/chromeos/input_method/mock_input_method_manager.h3
-rw-r--r--chrome/chrome_browser_chromeos.gypi2
-rw-r--r--chrome/chrome_tests_unit.gypi1
20 files changed, 408 insertions, 353 deletions
diff --git a/chrome/browser/chromeos/input_method/DEPS b/chrome/browser/chromeos/input_method/DEPS
new file mode 100644
index 0000000..0294033
--- /dev/null
+++ b/chrome/browser/chromeos/input_method/DEPS
@@ -0,0 +1,31 @@
+include_rules = [
+ "-chrome",
+ "+chrome/browser/chromeos/input_method",
+ "-content",
+]
+
+specific_include_rules = {
+ # The configuration layer.
+ '(input_method_delegate_impl|input_method_persistence|browser_state_monitor)'
+ '(_unittest)?\.(h|cc)': [
+ "+chrome/common",
+ "+chrome/browser",
+ "+chrome/test",
+ "+content/public",
+ ],
+ # TODO(erikwright): Bring this list to zero.
+ #
+ # Do not add to the list of temporarily-allowed dependencies below,
+ # and please do not introduce more #includes of these files.
+ 'input_method_manager_impl\.cc': [
+ # TODO(erikwright): Much/all of language_preferences can/should be decoupled
+ # from chrome/browser.
+ "!chrome/browser/chromeos/language_preferences.h"
+ ],
+ 'ibus_controller_impl\.cc|xkeyboard\.cc': [
+ "!content/public/browser/browser_thread.h",
+ ],
+ 'xkeyboard_unittest\.cc': [
+ "!content/public/test/test_browser_thread.h",
+ ],
+}
diff --git a/chrome/browser/chromeos/input_method/browser_state_monitor.cc b/chrome/browser/chromeos/input_method/browser_state_monitor.cc
index c938d4a..486d21b 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,21 @@ BrowserStateMonitor::BrowserStateMonitor(InputMethodManager* manager,
chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
- manager_->SetState(state_);
- manager_->AddObserver(this);
+ if (!observer_.is_null())
+ 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 +56,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 +66,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 +80,10 @@ void BrowserStateMonitor::Observe(
break;
}
}
+
+ if (old_state != state_ && !observer_.is_null())
+ observer_.Run(state_);
+
// Note: browser notifications are sent in the following order.
//
// Normal login:
@@ -133,12 +106,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
diff --git a/chrome/browser/chromeos/input_method/browser_state_monitor.h b/chrome/browser/chromeos/input_method/browser_state_monitor.h
index bc3e73a..ba07af0 100644
--- a/chrome/browser/chromeos/input_method/browser_state_monitor.h
+++ b/chrome/browser/chromeos/input_method/browser_state_monitor.h
@@ -8,50 +8,36 @@
#include <string>
#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/compiler_specific.h"
-#include "base/prefs/public/pref_member.h"
#include "chrome/browser/chromeos/input_method/input_method_manager.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_types.h"
namespace chromeos {
namespace input_method {
-class InputMethodDelegate;
-
-// A class which monitors a notification from the browser to keep track of the
-// browser state (not logged in, logged in, etc.) and notify the current state
-// to the input method manager. The class also updates the appropriate Chrome
-// prefs via the InputMethodDelegate, depending on the current browser state.
-class BrowserStateMonitor : public content::NotificationObserver,
- public InputMethodManager::Observer {
+// Translates notifications from the browser (not logged in, logged in, etc.),
+// into InputMethodManager::State transitions.
+class BrowserStateMonitor : public content::NotificationObserver {
public:
- BrowserStateMonitor(InputMethodManager* manager,
- InputMethodDelegate* delegate);
+ // Constructs a monitor that will invoke the given observer callback whenever
+ // the InputMethodManager::State changes. Assumes that the current state is
+ // STATE_LOGIN_SCREEN. |observer| may be null.
+ explicit BrowserStateMonitor(
+ const base::Callback<void(InputMethodManager::State)>& observer);
virtual ~BrowserStateMonitor();
InputMethodManager::State state() const { return state_; }
- protected:
- // InputMethodManager::Observer overrides:
- virtual void InputMethodChanged(InputMethodManager* manager,
- bool show_message) OVERRIDE;
- virtual void InputMethodPropertyChanged(InputMethodManager* manager) OVERRIDE;
-
// content::NotificationObserver overrides:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
private:
- void SetState(InputMethodManager::State new_state);
-
- InputMethodManager* manager_;
- InputMethodDelegate* delegate_;
+ base::Callback<void(InputMethodManager::State)> observer_;
InputMethodManager::State state_;
-
- // This is used to register this object to some browser notifications.
content::NotificationRegistrar notification_registrar_;
DISALLOW_COPY_AND_ASSIGN(BrowserStateMonitor);
diff --git a/chrome/browser/chromeos/input_method/browser_state_monitor_unittest.cc b/chrome/browser/chromeos/input_method/browser_state_monitor_unittest.cc
index 746009c..0a057ec 100644
--- a/chrome/browser/chromeos/input_method/browser_state_monitor_unittest.cc
+++ b/chrome/browser/chromeos/input_method/browser_state_monitor_unittest.cc
@@ -7,9 +7,7 @@
#include <string>
#include "base/basictypes.h"
-#include "base/prefs/public/pref_member.h"
-#include "chrome/browser/chromeos/input_method/mock_input_method_delegate.h"
-#include "chrome/browser/chromeos/input_method/mock_input_method_manager.h"
+#include "base/bind.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
@@ -19,38 +17,46 @@ namespace chromeos {
namespace input_method {
namespace {
-class TestableBrowserStateMonitor : public BrowserStateMonitor {
+class MockObserver {
public:
- using BrowserStateMonitor::InputMethodChanged;
- using BrowserStateMonitor::Observe;
+ MockObserver()
+ : state_(InputMethodManager::STATE_TERMINATING),
+ update_state_count_(0) { }
- TestableBrowserStateMonitor(InputMethodManager* manager,
- InputMethodDelegate* delegate)
- : BrowserStateMonitor(manager, delegate) {
+ void SetState(InputMethodManager::State new_state) {
+ ++update_state_count_;
+ state_ = new_state;
}
+
+ base::Callback<void(InputMethodManager::State new_state)> AsCallback() {
+ return base::Bind(&MockObserver::SetState, base::Unretained(this));
+ }
+
+ int update_state_count() const {
+ return update_state_count_;
+ }
+
+ InputMethodManager::State state() const {
+ return state_;
+ }
+
+ private:
+ InputMethodManager::State state_;
+ int update_state_count_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockObserver);
};
} // anonymous namespace
TEST(BrowserStateMonitorLifetimeTest, TestConstruction) {
- MockInputMethodManager mock_manager;
- MockInputMethodDelegate mock_delegate;
- TestableBrowserStateMonitor monitor(&mock_manager, &mock_delegate);
-
- // Check the initial state of the |mock_manager| and |monitor| objects.
- EXPECT_EQ(1, mock_manager.add_observer_count_);
- EXPECT_EQ(1, mock_manager.set_state_count_);
- EXPECT_EQ(InputMethodManager::STATE_LOGIN_SCREEN, mock_manager.last_state_);
- EXPECT_EQ(InputMethodManager::STATE_LOGIN_SCREEN, monitor.state());
-}
+ MockObserver mock_observer;
+ BrowserStateMonitor monitor(mock_observer.AsCallback());
-TEST(BrowserStateMonitorLifetimeTest, TestDestruction) {
- MockInputMethodManager mock_manager;
- MockInputMethodDelegate mock_delegate;
- {
- TestableBrowserStateMonitor monitor(&mock_manager, &mock_delegate);
- }
- EXPECT_EQ(1, mock_manager.remove_observer_count_);
+ // Check the initial state of the |mock_observer| and |monitor| objects.
+ EXPECT_EQ(1, mock_observer.update_state_count());
+ EXPECT_EQ(InputMethodManager::STATE_LOGIN_SCREEN, mock_observer.state());
+ EXPECT_EQ(InputMethodManager::STATE_LOGIN_SCREEN, monitor.state());
}
namespace {
@@ -58,13 +64,12 @@ namespace {
class BrowserStateMonitorTest : public testing::Test {
public:
BrowserStateMonitorTest()
- : monitor_(&mock_manager_, &mock_delegate_) {
+ : monitor_(mock_observer_.AsCallback()) {
}
protected:
- MockInputMethodManager mock_manager_;
- MockInputMethodDelegate mock_delegate_;
- TestableBrowserStateMonitor monitor_;
+ MockObserver mock_observer_;
+ BrowserStateMonitor monitor_;
private:
DISALLOW_COPY_AND_ASSIGN(BrowserStateMonitorTest);
@@ -73,44 +78,44 @@ class BrowserStateMonitorTest : public testing::Test {
} // anonymous namespace
TEST_F(BrowserStateMonitorTest, TestObserveLoginUserChanged) {
- EXPECT_EQ(1, mock_manager_.set_state_count_);
+ EXPECT_EQ(1, mock_observer_.update_state_count());
monitor_.Observe(chrome::NOTIFICATION_LOGIN_USER_CHANGED,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
- // Check if the state of the |mock_manager_| as well as the |monitor| are both
- // changed.
- EXPECT_EQ(2, mock_manager_.set_state_count_);
+ // Check if the state of the |mock_observer_| as well as the |monitor| are
+ // both changed.
+ EXPECT_EQ(2, mock_observer_.update_state_count());
EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN,
- mock_manager_.last_state_);
+ mock_observer_.state());
EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN, monitor_.state());
}
TEST_F(BrowserStateMonitorTest, TestObserveSessionStarted) {
- EXPECT_EQ(1, mock_manager_.set_state_count_);
+ EXPECT_EQ(1, mock_observer_.update_state_count());
monitor_.Observe(chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
- // Check if the state of the |mock_manager_| as well as the |monitor| are both
- // changed.
- EXPECT_EQ(2, mock_manager_.set_state_count_);
+ // Check if the state of the |mock_observer_| as well as the |monitor| are
+ // both changed.
+ EXPECT_EQ(2, mock_observer_.update_state_count());
EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN,
- mock_manager_.last_state_);
+ mock_observer_.state());
EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN, monitor_.state());
}
TEST_F(BrowserStateMonitorTest, TestObserveLoginUserChangedThenSessionStarted) {
- EXPECT_EQ(1, mock_manager_.set_state_count_);
+ EXPECT_EQ(1, mock_observer_.update_state_count());
monitor_.Observe(chrome::NOTIFICATION_LOGIN_USER_CHANGED,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
- // Check if the state of the |mock_manager_| as well as the |monitor| are both
- // changed.
- EXPECT_EQ(2, mock_manager_.set_state_count_);
+ // Check if the state of the |mock_observer_| as well as the |monitor| are
+ // both changed.
+ EXPECT_EQ(2, mock_observer_.update_state_count());
EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN,
- mock_manager_.last_state_);
+ mock_observer_.state());
EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN, monitor_.state());
monitor_.Observe(chrome::NOTIFICATION_SESSION_STARTED,
@@ -118,161 +123,53 @@ TEST_F(BrowserStateMonitorTest, TestObserveLoginUserChangedThenSessionStarted) {
content::NotificationService::NoDetails());
// The second notification should be nop.
- EXPECT_EQ(2, mock_manager_.set_state_count_);
+ EXPECT_EQ(2, mock_observer_.update_state_count());
EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN,
- mock_manager_.last_state_);
+ mock_observer_.state());
EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN, monitor_.state());
}
TEST_F(BrowserStateMonitorTest, TestObserveScreenLockUnlock) {
- EXPECT_EQ(1, mock_manager_.set_state_count_);
+ EXPECT_EQ(1, mock_observer_.update_state_count());
monitor_.Observe(chrome::NOTIFICATION_LOGIN_USER_CHANGED,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
- EXPECT_EQ(2, mock_manager_.set_state_count_);
+ EXPECT_EQ(2, mock_observer_.update_state_count());
monitor_.Observe(chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
- EXPECT_EQ(2, mock_manager_.set_state_count_);
+ EXPECT_EQ(2, mock_observer_.update_state_count());
bool locked = true;
monitor_.Observe(chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
content::NotificationService::AllSources(),
content::Details<bool>(&locked));
- EXPECT_EQ(3, mock_manager_.set_state_count_);
+ EXPECT_EQ(3, mock_observer_.update_state_count());
EXPECT_EQ(InputMethodManager::STATE_LOCK_SCREEN,
- mock_manager_.last_state_);
+ mock_observer_.state());
EXPECT_EQ(InputMethodManager::STATE_LOCK_SCREEN, monitor_.state());
- // When the screen is locked, the monitor should ignore input method changes.
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(0, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(0, mock_delegate_.update_user_input_method_count());
-
locked = false;
monitor_.Observe(chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
content::NotificationService::AllSources(),
content::Details<bool>(&locked));
- EXPECT_EQ(4, mock_manager_.set_state_count_);
+ EXPECT_EQ(4, mock_observer_.update_state_count());
EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN,
- mock_manager_.last_state_);
+ mock_observer_.state());
EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN, monitor_.state());
-
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(0, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(1, mock_delegate_.update_user_input_method_count());
}
TEST_F(BrowserStateMonitorTest, TestObserveAppTerminating) {
- EXPECT_EQ(1, mock_manager_.set_state_count_);
+ EXPECT_EQ(1, mock_observer_.update_state_count());
monitor_.Observe(chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
- // Check if the state of the |mock_manager_| as well as the |monitor| are both
- // changed.
- EXPECT_EQ(2, mock_manager_.set_state_count_);
+ // Check if the state of the |mock_observer_| as well as the |monitor| are
+ // both changed.
+ EXPECT_EQ(2, mock_observer_.update_state_count());
EXPECT_EQ(InputMethodManager::STATE_TERMINATING,
- mock_manager_.last_state_);
+ mock_observer_.state());
EXPECT_EQ(InputMethodManager::STATE_TERMINATING, monitor_.state());
-
- // In the terminating state, the monitor should ignore input method changes.
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(0, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(0, mock_delegate_.update_user_input_method_count());
-}
-
-TEST_F(BrowserStateMonitorTest, TestUpdatePrefOnLoginScreen) {
- EXPECT_EQ(InputMethodManager::STATE_LOGIN_SCREEN, monitor_.state());
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(1, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(0, mock_delegate_.update_user_input_method_count());
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(2, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(0, mock_delegate_.update_user_input_method_count());
-}
-
-TEST_F(BrowserStateMonitorTest, TestUpdatePrefOnBrowserScreen) {
- monitor_.Observe(chrome::NOTIFICATION_LOGIN_USER_CHANGED,
- content::NotificationService::AllSources(),
- content::NotificationService::NoDetails());
- EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN, monitor_.state());
-
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(0, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(1, mock_delegate_.update_user_input_method_count());
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(0, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(2, mock_delegate_.update_user_input_method_count());
-
- monitor_.Observe(chrome::NOTIFICATION_SESSION_STARTED,
- content::NotificationService::AllSources(),
- content::NotificationService::NoDetails());
- EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN, monitor_.state());
-
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(0, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(3, mock_delegate_.update_user_input_method_count());
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(0, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(4, mock_delegate_.update_user_input_method_count());
-}
-
-TEST_F(BrowserStateMonitorTest, TestUpdatePrefOnLoginScreenDetails) {
- EXPECT_EQ(InputMethodManager::STATE_LOGIN_SCREEN, monitor_.state());
- std::string input_method_id = "xkb:us:dvorak:eng";
- mock_manager_.SetCurrentInputMethodId(input_method_id);
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(1, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(0, mock_delegate_.update_user_input_method_count());
- EXPECT_EQ(input_method_id, mock_delegate_.system_input_method());
- input_method_id = "xkb:us:colemak:eng";
- mock_manager_.SetCurrentInputMethodId(input_method_id);
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(2, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(0, mock_delegate_.update_user_input_method_count());
- EXPECT_EQ(input_method_id, mock_delegate_.system_input_method());
-}
-
-TEST_F(BrowserStateMonitorTest, TestUpdatePrefOnBrowserScreenDetails) {
- monitor_.Observe(chrome::NOTIFICATION_LOGIN_USER_CHANGED,
- content::NotificationService::AllSources(),
- content::NotificationService::NoDetails());
- EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN, monitor_.state());
- monitor_.Observe(chrome::NOTIFICATION_SESSION_STARTED,
- content::NotificationService::AllSources(),
- content::NotificationService::NoDetails());
- EXPECT_EQ(InputMethodManager::STATE_BROWSER_SCREEN, monitor_.state());
-
- const std::string input_method_id = "xkb:us:dvorak:eng";
- mock_manager_.SetCurrentInputMethodId(input_method_id);
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(0, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(1, mock_delegate_.update_user_input_method_count());
- EXPECT_EQ(input_method_id, mock_delegate_.user_input_method());
-
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(0, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(2, mock_delegate_.update_user_input_method_count());
- EXPECT_EQ(input_method_id, mock_delegate_.user_input_method());
-
- const std::string input_method_id_2 = "xkb:us:colemak:eng";
- mock_manager_.SetCurrentInputMethodId(input_method_id_2);
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(0, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(3, mock_delegate_.update_user_input_method_count());
- EXPECT_EQ(input_method_id_2, mock_delegate_.user_input_method());
-
- const std::string input_method_id_3 = "xkb:us::eng";
- mock_manager_.SetCurrentInputMethodId(input_method_id_3);
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(0, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(4, mock_delegate_.update_user_input_method_count());
- EXPECT_EQ(input_method_id_3, mock_delegate_.user_input_method());
-
- monitor_.InputMethodChanged(&mock_manager_, false);
- EXPECT_EQ(0, mock_delegate_.update_system_input_method_count());
- EXPECT_EQ(5, mock_delegate_.update_user_input_method_count());
- EXPECT_EQ(input_method_id_3, mock_delegate_.user_input_method());
}
} // namespace input_method
diff --git a/chrome/browser/chromeos/input_method/input_method_configuration.cc b/chrome/browser/chromeos/input_method/input_method_configuration.cc
index 647cf3b..f98025f 100644
--- a/chrome/browser/chromeos/input_method/input_method_configuration.cc
+++ b/chrome/browser/chromeos/input_method/input_method_configuration.cc
@@ -4,18 +4,29 @@
#include "chrome/browser/chromeos/input_method/input_method_configuration.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/chromeos/input_method/browser_state_monitor.h"
#include "chrome/browser/chromeos/input_method/input_method_delegate_impl.h"
#include "chrome/browser/chromeos/input_method/input_method_manager_impl.h"
+#include "chrome/browser/chromeos/input_method/input_method_persistence.h"
namespace chromeos {
namespace input_method {
namespace {
InputMethodManager* g_input_method_manager = NULL;
+InputMethodPersistence* g_input_method_persistence = NULL;
+BrowserStateMonitor* g_browser_state_monitor = NULL;
} // namespace
+void OnSessionStateChange(InputMethodManagerImpl* input_method_manager_impl,
+ InputMethodPersistence* input_method_persistence,
+ InputMethodManager::State new_state) {
+ input_method_persistence->OnSessionStateChange(new_state);
+ input_method_manager_impl->SetState(new_state);
+}
void Initialize() {
DCHECK(!g_input_method_manager);
@@ -24,6 +35,10 @@ void Initialize() {
scoped_ptr<InputMethodDelegate>(new InputMethodDelegateImpl));
impl->Init();
g_input_method_manager = impl;
+ g_input_method_persistence =
+ new InputMethodPersistence(g_input_method_manager);
+ g_browser_state_monitor = new BrowserStateMonitor(
+ base::Bind(&OnSessionStateChange, impl, g_input_method_persistence));
DVLOG(1) << "InputMethodManager initialized";
}
@@ -35,8 +50,15 @@ void InitializeForTesting(InputMethodManager* mock_manager) {
}
void Shutdown() {
+ delete g_browser_state_monitor;
+ g_browser_state_monitor = NULL;
+
+ delete g_input_method_persistence;
+ g_input_method_persistence = NULL;
+
delete g_input_method_manager;
g_input_method_manager = NULL;
+
DVLOG(1) << "InputMethodManager shutdown";
}
diff --git a/chrome/browser/chromeos/input_method/input_method_delegate.h b/chrome/browser/chromeos/input_method/input_method_delegate.h
index 4117ad3..ed07173 100644
--- a/chrome/browser/chromeos/input_method/input_method_delegate.h
+++ b/chrome/browser/chromeos/input_method/input_method_delegate.h
@@ -18,10 +18,6 @@ class InputMethodDelegate {
InputMethodDelegate() {}
virtual ~InputMethodDelegate() {}
- // Persists input method choices when no user is logged in.
- virtual void SetSystemInputMethod(const std::string& input_method) = 0;
- // Persists input method choices when the user is logged in.
- virtual void SetUserInputMethod(const std::string& input_method) = 0;
// Retrieves the hardware keyboard layout ID. May return an empty string if
// the ID is unknown.
virtual std::string GetHardwareKeyboardLayout() const = 0;
diff --git a/chrome/browser/chromeos/input_method/input_method_delegate_impl.cc b/chrome/browser/chromeos/input_method/input_method_delegate_impl.cc
index 4b6e71f..a69cdc4 100644
--- a/chrome/browser/chromeos/input_method/input_method_delegate_impl.cc
+++ b/chrome/browser/chromeos/input_method/input_method_delegate_impl.cc
@@ -4,11 +4,9 @@
#include "chrome/browser/chromeos/input_method/input_method_delegate_impl.h"
-#include "base/prefs/public/pref_service_base.h"
+#include "base/logging.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chromeos/language_preferences.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/pref_names.h"
namespace chromeos {
@@ -16,40 +14,6 @@ namespace input_method {
InputMethodDelegateImpl::InputMethodDelegateImpl() {}
-void InputMethodDelegateImpl::SetSystemInputMethod(
- const std::string& input_method) {
- if (g_browser_process) {
- PrefServiceBase* local_state = g_browser_process->local_state();
- if (local_state) {
- local_state->SetString(language_prefs::kPreferredKeyboardLayout,
- input_method);
- return;
- }
- }
-
- NOTREACHED();
-}
-
-void InputMethodDelegateImpl::SetUserInputMethod(
- const std::string& input_method) {
- PrefServiceBase* user_prefs = NULL;
- Profile* profile = ProfileManager::GetDefaultProfile();
- if (profile)
- user_prefs = profile->GetPrefs();
- if (!user_prefs)
- return;
-
- const std::string current_input_method_on_pref =
- user_prefs->GetString(prefs::kLanguageCurrentInputMethod);
- if (current_input_method_on_pref == input_method)
- return;
-
- user_prefs->SetString(prefs::kLanguagePreviousInputMethod,
- current_input_method_on_pref);
- user_prefs->SetString(prefs::kLanguageCurrentInputMethod,
- input_method);
-}
-
std::string InputMethodDelegateImpl::GetHardwareKeyboardLayout() const {
if (g_browser_process) {
PrefServiceBase* local_state = g_browser_process->local_state();
diff --git a/chrome/browser/chromeos/input_method/input_method_delegate_impl.h b/chrome/browser/chromeos/input_method/input_method_delegate_impl.h
index 6aea2ae..b327b61 100644
--- a/chrome/browser/chromeos/input_method/input_method_delegate_impl.h
+++ b/chrome/browser/chromeos/input_method/input_method_delegate_impl.h
@@ -14,17 +14,13 @@
namespace chromeos {
namespace input_method {
-// Persists input method changes to the BrowserProcess local state or to the
-// user preferences, as appropriate. Accesses the hardware keyboard layout and
-// application locale from the BrowserProcess.
+// Accesses the hardware keyboard layout and application locale from the
+// BrowserProcess.
class InputMethodDelegateImpl : public InputMethodDelegate {
public:
InputMethodDelegateImpl();
// InputMethodDelegate implementation.
- virtual void SetSystemInputMethod(
- const std::string& input_method) OVERRIDE;
- virtual void SetUserInputMethod(const std::string& input_method) OVERRIDE;
virtual std::string GetHardwareKeyboardLayout() const OVERRIDE;
virtual std::string GetActiveLocale() const OVERRIDE;
diff --git a/chrome/browser/chromeos/input_method/input_method_manager.h b/chrome/browser/chromeos/input_method/input_method_manager.h
index 510b9fc..786db50 100644
--- a/chrome/browser/chromeos/input_method/input_method_manager.h
+++ b/chrome/browser/chromeos/input_method/input_method_manager.h
@@ -73,9 +73,6 @@ class InputMethodManager {
virtual void RemoveCandidateWindowObserver(
CandidateWindowObserver* observer) = 0;
- // Sets the current browser status.
- virtual void SetState(State new_state) = 0;
-
// Returns all input methods that are supported, including ones not active.
// This function never returns NULL. Note that input method extensions are NOT
// included in the result.
diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
index 8a4fa7c..2f9a67c 100644
--- a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
+++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
@@ -10,7 +10,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
-#include "chrome/browser/chromeos/input_method/browser_state_monitor.h"
#include "chrome/browser/chromeos/input_method/candidate_window_controller.h"
#include "chrome/browser/chromeos/input_method/input_method_delegate.h"
#include "chrome/browser/chromeos/input_method/input_method_engine_ibus.h"
@@ -83,7 +82,6 @@ void InputMethodManagerImpl::SetState(State new_state) {
break;
case STATE_TERMINATING: {
ibus_controller_->Stop();
- browser_state_monitor_.reset(); // For crbug.com/120183.
if (candidate_window_controller_.get()) {
candidate_window_controller_->Shutdown(ibus_controller_.get());
candidate_window_controller_.reset();
@@ -581,7 +579,6 @@ void InputMethodManagerImpl::OnDisconnected() {
void InputMethodManagerImpl::Init() {
DCHECK(!ibus_controller_.get());
- browser_state_monitor_.reset(new BrowserStateMonitor(this, delegate_.get()));
ibus_controller_.reset(IBusController::Create());
xkeyboard_.reset(XKeyboard::Create(util_));
ibus_controller_->AddObserver(this);
diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.h b/chrome/browser/chromeos/input_method/input_method_manager_impl.h
index 700bdf8..0a5715b 100644
--- a/chrome/browser/chromeos/input_method/input_method_manager_impl.h
+++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.h
@@ -11,24 +11,25 @@
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
-#include "chrome/browser/chromeos/input_method/browser_state_monitor.h"
#include "chrome/browser/chromeos/input_method/candidate_window_controller.h"
#include "chrome/browser/chromeos/input_method/ibus_controller.h"
#include "chrome/browser/chromeos/input_method/input_method_manager.h"
#include "chrome/browser/chromeos/input_method/input_method_util.h"
#include "chrome/browser/chromeos/input_method/input_method_whitelist.h"
-#include "chrome/browser/chromeos/input_method/xkeyboard.h"
namespace chromeos {
class InputMethodEngineIBus;
namespace input_method {
class InputMethodDelegate;
+class XKeyboard;
// The implementation of InputMethodManager.
class InputMethodManagerImpl : public InputMethodManager,
public CandidateWindowController::Observer,
public IBusController::Observer {
public:
+ // Constructs an InputMethodManager instance. The client is responsible for
+ // calling |SetState| in response to relevant changes in browser state.
explicit InputMethodManagerImpl(scoped_ptr<InputMethodDelegate> delegate);
virtual ~InputMethodManagerImpl();
@@ -38,6 +39,9 @@ class InputMethodManagerImpl : public InputMethodManager,
// setters.
void Init();
+ // Receives notification of an InputMethodManager::State transition.
+ void SetState(State new_state);
+
// InputMethodManager override:
virtual void AddObserver(InputMethodManager::Observer* observer) OVERRIDE;
virtual void AddCandidateWindowObserver(
@@ -45,7 +49,6 @@ class InputMethodManagerImpl : public InputMethodManager,
virtual void RemoveObserver(InputMethodManager::Observer* observer) OVERRIDE;
virtual void RemoveCandidateWindowObserver(
InputMethodManager::CandidateWindowObserver* observer) OVERRIDE;
- virtual void SetState(State new_state) OVERRIDE;
virtual scoped_ptr<InputMethodDescriptors>
GetSupportedInputMethods() const OVERRIDE;
virtual scoped_ptr<InputMethodDescriptors>
@@ -160,10 +163,6 @@ class InputMethodManagerImpl : public InputMethodManager,
std::map<std::string, InputMethodDescriptor> extra_input_methods_;
std::map<std::string, InputMethodEngineIBus*> extra_input_method_instances_;
- // The browser state monitor is used to receive notifications from the browser
- // and call SetState() method of |this| class.
- scoped_ptr<BrowserStateMonitor> browser_state_monitor_;
-
// The IBus controller is used to control the input method status and
// allow callbacks when the input method status changes.
scoped_ptr<IBusController> ibus_controller_;
diff --git a/chrome/browser/chromeos/input_method/input_method_persistence.cc b/chrome/browser/chromeos/input_method/input_method_persistence.cc
new file mode 100644
index 0000000..4bb10e9
--- /dev/null
+++ b/chrome/browser/chromeos/input_method/input_method_persistence.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/input_method/input_method_persistence.h"
+
+#include "base/logging.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/input_method/input_method_util.h"
+#include "chrome/browser/chromeos/language_preferences.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/pref_names.h"
+
+namespace chromeos {
+namespace input_method {
+namespace {
+
+void PersistSystemInputMethod(const std::string& input_method) {
+ if (!g_browser_process || !g_browser_process->local_state())
+ return;
+
+ g_browser_process->local_state()->SetString(
+ language_prefs::kPreferredKeyboardLayout, input_method);
+}
+
+void PersistUserInputMethod(const std::string& input_method) {
+ PrefServiceBase* user_prefs = NULL;
+ Profile* profile = ProfileManager::GetDefaultProfile();
+ if (profile)
+ user_prefs = profile->GetPrefs();
+ if (!user_prefs)
+ return;
+
+ const std::string current_input_method_on_pref =
+ user_prefs->GetString(prefs::kLanguageCurrentInputMethod);
+ if (current_input_method_on_pref == input_method)
+ return;
+
+ user_prefs->SetString(prefs::kLanguagePreviousInputMethod,
+ current_input_method_on_pref);
+ user_prefs->SetString(prefs::kLanguageCurrentInputMethod,
+ input_method);
+}
+
+} // namespace
+
+InputMethodPersistence::InputMethodPersistence(
+ InputMethodManager* input_method_manager)
+ : input_method_manager_(input_method_manager),
+ state_(InputMethodManager::STATE_LOGIN_SCREEN) {
+ input_method_manager_->AddObserver(this);
+}
+
+InputMethodPersistence::~InputMethodPersistence() {
+ input_method_manager_->RemoveObserver(this);
+}
+
+void InputMethodPersistence::InputMethodChanged(
+ InputMethodManager* manager, bool show_message) {
+ DCHECK_EQ(input_method_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;
+ }
+ PersistSystemInputMethod(current_input_method);
+ return;
+ case InputMethodManager::STATE_BROWSER_SCREEN:
+ PersistUserInputMethod(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 InputMethodPersistence::InputMethodPropertyChanged(
+ InputMethodManager* manager) {}
+
+void InputMethodPersistence::OnSessionStateChange(
+ InputMethodManager::State new_state) {
+ state_ = new_state;
+}
+
+} // namespace input_method
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/input_method/input_method_persistence.h b/chrome/browser/chromeos/input_method/input_method_persistence.h
new file mode 100644
index 0000000..3935572
--- /dev/null
+++ b/chrome/browser/chromeos/input_method/input_method_persistence.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_PERSISTENCE_H_
+#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_PERSISTENCE_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "chrome/browser/chromeos/input_method/input_method_manager.h"
+
+namespace chromeos {
+namespace input_method {
+
+// Observes input method and session state changes, and persists input method
+// changes to the BrowserProcess local state or to the user preferences,
+// according to the session state.
+class InputMethodPersistence : public InputMethodManager::Observer {
+ public:
+ // Constructs an instance that will observe input method changes on the
+ // provided InputMethodManager. The client is responsible for calling
+ // OnSessionStateChange whenever the InputMethodManager::State changes.
+ explicit InputMethodPersistence(InputMethodManager* input_method_manager);
+ virtual ~InputMethodPersistence();
+
+ // Receives notification of session state changes.
+ void OnSessionStateChange(InputMethodManager::State new_state);
+
+ // InputMethodManager::Observer overrides.
+ virtual void InputMethodChanged(InputMethodManager* manager,
+ bool show_message) OVERRIDE;
+ virtual void InputMethodPropertyChanged(InputMethodManager* manager) OVERRIDE;
+
+ private:
+ InputMethodManager* input_method_manager_;
+ InputMethodManager::State state_;
+ DISALLOW_COPY_AND_ASSIGN(InputMethodPersistence);
+};
+
+} // namespace input_method
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_PERSISTENCE_H_
diff --git a/chrome/browser/chromeos/input_method/input_method_persistence_unittest.cc b/chrome/browser/chromeos/input_method/input_method_persistence_unittest.cc
new file mode 100644
index 0000000..2581070
--- /dev/null
+++ b/chrome/browser/chromeos/input_method/input_method_persistence_unittest.cc
@@ -0,0 +1,111 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/input_method/input_method_persistence.h"
+
+#include "base/command_line.h"
+#include "chrome/browser/chromeos/input_method/mock_input_method_manager.h"
+#include "chrome/browser/chromeos/language_preferences.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_pref_service.h"
+#include "chrome/test/base/testing_profile.h"
+#include "chrome/test/base/testing_profile_manager.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+namespace input_method {
+
+namespace {
+const char kInputId1[] = "xkb:us:dvorak:eng";
+const char kInputId2[] = "xkb:us:colemak:eng";
+const char kProfileName[] = "input_method_test";
+}
+
+class InputMethodPersistenceTest : public testing::Test {
+ protected:
+ InputMethodPersistenceTest()
+ : mock_profile_manager_(
+ static_cast<TestingBrowserProcess*>(g_browser_process)) {
+ }
+
+ virtual void SetUp() OVERRIDE {
+ // Set up a profile that will be returned by
+ // ProfileManager::GetDefaultProfile().
+ ASSERT_TRUE(mock_profile_manager_.SetUp());
+ TestingProfile* mock_profile =
+ mock_profile_manager_.CreateTestingProfile(kProfileName);
+ CommandLine *cl = CommandLine::ForCurrentProcess();
+ cl->AppendSwitchASCII(switches::kLoginProfile, kProfileName);
+ mock_profile_manager_.SetLoggedIn(true);
+ EXPECT_TRUE(ProfileManager::GetDefaultProfile() != NULL);
+ mock_user_prefs_ = mock_profile->GetTestingPrefService();
+ }
+
+ // Verifies that the user and system prefs contain the expected values.
+ void VerifyPrefs(const std::string& current_input_method,
+ const std::string& previous_input_method,
+ const std::string& preferred_keyboard_layout) {
+ EXPECT_EQ(current_input_method,
+ mock_user_prefs_->GetString(prefs::kLanguageCurrentInputMethod));
+ EXPECT_EQ(previous_input_method,
+ mock_user_prefs_->GetString(prefs::kLanguagePreviousInputMethod));
+ EXPECT_EQ(preferred_keyboard_layout,
+ g_browser_process->local_state()->GetString(
+ language_prefs::kPreferredKeyboardLayout));
+ }
+
+ TestingPrefService* mock_user_prefs_;
+ MockInputMethodManager mock_manager_;
+ TestingProfileManager mock_profile_manager_;
+};
+
+TEST_F(InputMethodPersistenceTest, TestLifetime) {
+ {
+ InputMethodPersistence persistence(&mock_manager_);
+ EXPECT_EQ(1, mock_manager_.add_observer_count_);
+ }
+ EXPECT_EQ(1, mock_manager_.remove_observer_count_);
+}
+
+TEST_F(InputMethodPersistenceTest, TestPrefPersistenceByState) {
+ InputMethodPersistence persistence(&mock_manager_);
+
+ persistence.OnSessionStateChange(InputMethodManager::STATE_LOGIN_SCREEN);
+ mock_manager_.SetCurrentInputMethodId(kInputId1);
+ persistence.InputMethodChanged(&mock_manager_, false);
+ VerifyPrefs("", "", kInputId1);
+
+ persistence.OnSessionStateChange(InputMethodManager::STATE_BROWSER_SCREEN);
+ mock_manager_.SetCurrentInputMethodId(kInputId2);
+ persistence.InputMethodChanged(&mock_manager_, false);
+ VerifyPrefs(kInputId2, "", kInputId1);
+
+ persistence.OnSessionStateChange(InputMethodManager::STATE_LOCK_SCREEN);
+ mock_manager_.SetCurrentInputMethodId(kInputId1);
+ persistence.InputMethodChanged(&mock_manager_, false);
+ VerifyPrefs(kInputId2, "", kInputId1);
+
+ persistence.OnSessionStateChange(InputMethodManager::STATE_TERMINATING);
+ mock_manager_.SetCurrentInputMethodId(kInputId1);
+ persistence.InputMethodChanged(&mock_manager_, false);
+ VerifyPrefs(kInputId2, "", kInputId1);
+
+ persistence.OnSessionStateChange(InputMethodManager::STATE_LOGIN_SCREEN);
+ mock_manager_.SetCurrentInputMethodId(kInputId2);
+ persistence.InputMethodChanged(&mock_manager_, false);
+ VerifyPrefs(kInputId2, "", kInputId2);
+
+ persistence.OnSessionStateChange(InputMethodManager::STATE_BROWSER_SCREEN);
+ mock_manager_.SetCurrentInputMethodId(kInputId1);
+ persistence.InputMethodChanged(&mock_manager_, false);
+ VerifyPrefs(kInputId1, kInputId2, kInputId2);
+}
+
+} // namespace input_method
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/input_method/mock_input_method_delegate.cc b/chrome/browser/chromeos/input_method/mock_input_method_delegate.cc
index 62111e66..7114fbe 100644
--- a/chrome/browser/chromeos/input_method/mock_input_method_delegate.cc
+++ b/chrome/browser/chromeos/input_method/mock_input_method_delegate.cc
@@ -8,26 +8,12 @@ namespace chromeos {
namespace input_method {
MockInputMethodDelegate::MockInputMethodDelegate()
- : active_locale_("en"),
- update_system_input_method_count_(0),
- update_user_input_method_count_(0) {
+ : active_locale_("en") {
}
MockInputMethodDelegate::~MockInputMethodDelegate() {
}
-void MockInputMethodDelegate::SetSystemInputMethod(
- const std::string& input_method) {
- ++update_system_input_method_count_;
- system_input_method_ = input_method;
-}
-
-void MockInputMethodDelegate::SetUserInputMethod(
- const std::string& input_method) {
- ++update_user_input_method_count_;
- user_input_method_ = input_method;
-}
-
std::string MockInputMethodDelegate::GetHardwareKeyboardLayout() const {
return hardware_keyboard_layout_;
}
diff --git a/chrome/browser/chromeos/input_method/mock_input_method_delegate.h b/chrome/browser/chromeos/input_method/mock_input_method_delegate.h
index be03d41..58f0703 100644
--- a/chrome/browser/chromeos/input_method/mock_input_method_delegate.h
+++ b/chrome/browser/chromeos/input_method/mock_input_method_delegate.h
@@ -5,8 +5,6 @@
#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_MOCK_INPUT_METHOD_DELEGATE_H_
#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_MOCK_INPUT_METHOD_DELEGATE_H_
-#include <string>
-
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "chrome/browser/chromeos/input_method/input_method_delegate.h"
@@ -20,20 +18,9 @@ class MockInputMethodDelegate : public InputMethodDelegate {
virtual ~MockInputMethodDelegate();
// InputMethodDelegate implementation:
- virtual void SetSystemInputMethod(
- const std::string& input_method) OVERRIDE;
- virtual void SetUserInputMethod(const std::string& input_method) OVERRIDE;
virtual std::string GetHardwareKeyboardLayout() const OVERRIDE;
virtual std::string GetActiveLocale() const OVERRIDE;
- int update_system_input_method_count() const {
- return update_system_input_method_count_;
- }
-
- int update_user_input_method_count() const {
- return update_user_input_method_count_;
- }
-
void set_hardware_keyboard_layout(const std::string& value) {
hardware_keyboard_layout_ = value;
}
@@ -42,23 +29,9 @@ class MockInputMethodDelegate : public InputMethodDelegate {
active_locale_ = value;
}
- const std::string& system_input_method() const {
- return system_input_method_;
- }
-
- const std::string& user_input_method() const {
- return user_input_method_;
- }
-
private:
std::string hardware_keyboard_layout_;
std::string active_locale_;
- std::string system_input_method_;
- std::string user_input_method_;
-
- int update_system_input_method_count_;
- int update_user_input_method_count_;
-
DISALLOW_COPY_AND_ASSIGN(MockInputMethodDelegate);
};
diff --git a/chrome/browser/chromeos/input_method/mock_input_method_manager.cc b/chrome/browser/chromeos/input_method/mock_input_method_manager.cc
index 7a1facd..d79810c 100644
--- a/chrome/browser/chromeos/input_method/mock_input_method_manager.cc
+++ b/chrome/browser/chromeos/input_method/mock_input_method_manager.cc
@@ -10,8 +10,6 @@ namespace input_method {
MockInputMethodManager::MockInputMethodManager()
: add_observer_count_(0),
remove_observer_count_(0),
- set_state_count_(0),
- last_state_(STATE_TERMINATING),
util_(&delegate_, whitelist_.GetSupportedInputMethods()) {
}
@@ -36,11 +34,6 @@ void MockInputMethodManager::RemoveCandidateWindowObserver(
InputMethodManager::CandidateWindowObserver* observer) {
}
-void MockInputMethodManager::SetState(State new_state) {
- ++set_state_count_;
- last_state_ = new_state;
-}
-
scoped_ptr<InputMethodDescriptors>
MockInputMethodManager::GetSupportedInputMethods() const {
scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors);
diff --git a/chrome/browser/chromeos/input_method/mock_input_method_manager.h b/chrome/browser/chromeos/input_method/mock_input_method_manager.h
index 31425a8..8eb8d0f 100644
--- a/chrome/browser/chromeos/input_method/mock_input_method_manager.h
+++ b/chrome/browser/chromeos/input_method/mock_input_method_manager.h
@@ -27,7 +27,6 @@ class MockInputMethodManager : public InputMethodManager {
virtual void RemoveObserver(InputMethodManager::Observer* observer) OVERRIDE;
virtual void RemoveCandidateWindowObserver(
InputMethodManager::CandidateWindowObserver* observer) OVERRIDE;
- virtual void SetState(State new_state) OVERRIDE;
virtual scoped_ptr<InputMethodDescriptors>
GetSupportedInputMethods() const OVERRIDE;
virtual scoped_ptr<InputMethodDescriptors>
@@ -74,8 +73,6 @@ class MockInputMethodManager : public InputMethodManager {
// TODO(yusukes): Add more variables for counting the numbers of the API calls
int add_observer_count_;
int remove_observer_count_;
- int set_state_count_;
- State last_state_;
private:
// The value GetCurrentInputMethod().id() will return.
diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi
index 89779dd..9a2c2d3 100644
--- a/chrome/chrome_browser_chromeos.gypi
+++ b/chrome/chrome_browser_chromeos.gypi
@@ -336,6 +336,8 @@
'browser/chromeos/input_method/input_method_manager.h',
'browser/chromeos/input_method/input_method_manager_impl.cc',
'browser/chromeos/input_method/input_method_manager_impl.h',
+ 'browser/chromeos/input_method/input_method_persistence.cc',
+ 'browser/chromeos/input_method/input_method_persistence.h',
'browser/chromeos/input_method/input_method_property.cc',
'browser/chromeos/input_method/input_method_property.h',
'browser/chromeos/input_method/input_method_util.cc',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index 6a85eac..5a5d16d 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -579,6 +579,7 @@
'browser/chromeos/input_method/input_method_configuration_unittest.cc',
'browser/chromeos/input_method/input_method_descriptor_unittest.cc',
'browser/chromeos/input_method/input_method_manager_impl_unittest.cc',
+ 'browser/chromeos/input_method/input_method_persistence_unittest.cc',
'browser/chromeos/input_method/input_method_property_unittest.cc',
'browser/chromeos/input_method/input_method_util_unittest.cc',
'browser/chromeos/input_method/input_method_whitelist_unittest.cc',