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

Unified Diff: chrome/browser/chromeos/extensions/input_method_api.cc

Issue 11442074: Lazy initialization for ExtensionInputMethodEventRouter (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased Created 8 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/extensions/input_method_api.cc
diff --git a/chrome/browser/chromeos/extensions/input_method_api.cc b/chrome/browser/chromeos/extensions/input_method_api.cc
index 0b965e5256fc3fcc19d4ff5d5adb7902666e45e1..484c56d4288797c2a489b4c818b69c4237878ec9 100644
--- a/chrome/browser/chromeos/extensions/input_method_api.cc
+++ b/chrome/browser/chromeos/extensions/input_method_api.cc
@@ -8,10 +8,17 @@
#include "chrome/browser/chromeos/extensions/input_method_event_router.h"
#include "chrome/browser/chromeos/input_method/input_method_configuration.h"
#include "chrome/browser/chromeos/input_method/input_method_manager.h"
-#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/event_names.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/profiles/profile.h"
+namespace {
+
+// Prefix, which is used by XKB.
+const char kXkbPrefix[] = "xkb:";
+
+} // namespace
+
namespace extensions {
GetInputMethodFunction::GetInputMethodFunction() {
@@ -25,16 +32,43 @@ bool GetInputMethodFunction::RunImpl() {
NOTREACHED();
return false;
#else
- chromeos::ExtensionInputMethodEventRouter* router =
- extensions::ExtensionSystem::Get(profile_)->extension_service()->
- input_method_event_router();
chromeos::input_method::InputMethodManager* manager =
chromeos::input_method::GetInputMethodManager();
- const std::string input_method =
- router->GetInputMethodForXkb(manager->GetCurrentInputMethod().id());
+ const std::string input_method = InputMethodAPI::GetInputMethodForXkb(
+ manager->GetCurrentInputMethod().id());
SetResult(Value::CreateStringValue(input_method));
return true;
#endif
}
+InputMethodAPI::InputMethodAPI(Profile* profile)
+ : profile_(profile) {
+ ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
+ this, event_names::kOnInputMethodChanged);
+}
+
+InputMethodAPI::~InputMethodAPI() {
+}
+
+// static
+std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) {
+ size_t prefix_length = std::string(kXkbPrefix).length();
+ DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix);
+ return xkb_id.substr(prefix_length);
+}
+
+void InputMethodAPI::Shutdown() {
+ // UnregisterObserver may have already been called in OnListenerAdded,
+ // but it is safe to call it more than once.
+ ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
+}
+
+void InputMethodAPI::OnListenerAdded(
+ const extensions::EventListenerInfo& details) {
+ DCHECK(!input_method_event_router_.get());
+ input_method_event_router_.reset(
+ new chromeos::ExtensionInputMethodEventRouter());
+ ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
+}
+
} // namespace extensions
« no previous file with comments | « chrome/browser/chromeos/extensions/input_method_api.h ('k') | chrome/browser/chromeos/extensions/input_method_api_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698