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

Side by Side Diff: chrome/browser/chromeos/extensions/input_method_api.cc

Issue 238963002: Use EventRouter instead of ExtensionSystem::Get->event_router() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months 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 unified diff | Download patch
OLDNEW
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/extensions/input_method_api.h" 5 #include "chrome/browser/chromeos/extensions/input_method_api.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" 9 #include "chrome/browser/chromeos/extensions/input_method_event_router.h"
10 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" 10 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 return true; 60 return true;
61 #endif 61 #endif
62 } 62 }
63 63
64 // static 64 // static
65 const char InputMethodAPI::kOnInputMethodChanged[] = 65 const char InputMethodAPI::kOnInputMethodChanged[] =
66 "inputMethodPrivate.onChanged"; 66 "inputMethodPrivate.onChanged";
67 67
68 InputMethodAPI::InputMethodAPI(content::BrowserContext* context) 68 InputMethodAPI::InputMethodAPI(content::BrowserContext* context)
69 : context_(context) { 69 : context_(context) {
70 ExtensionSystem::Get(context_)->event_router()->RegisterObserver( 70 EventRouter::Get(context_)->RegisterObserver(this, kOnInputMethodChanged);
71 this, kOnInputMethodChanged);
72 ExtensionFunctionRegistry* registry = 71 ExtensionFunctionRegistry* registry =
73 ExtensionFunctionRegistry::GetInstance(); 72 ExtensionFunctionRegistry::GetInstance();
74 registry->RegisterFunction<GetInputMethodFunction>(); 73 registry->RegisterFunction<GetInputMethodFunction>();
75 registry->RegisterFunction<StartImeFunction>(); 74 registry->RegisterFunction<StartImeFunction>();
76 } 75 }
77 76
78 InputMethodAPI::~InputMethodAPI() { 77 InputMethodAPI::~InputMethodAPI() {
79 } 78 }
80 79
81 // static 80 // static
82 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) { 81 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) {
83 std::string xkb_prefix = 82 std::string xkb_prefix =
84 chromeos::extension_ime_util::GetInputMethodIDByKeyboardLayout( 83 chromeos::extension_ime_util::GetInputMethodIDByKeyboardLayout(
85 kXkbPrefix); 84 kXkbPrefix);
86 size_t prefix_length = xkb_prefix.length(); 85 size_t prefix_length = xkb_prefix.length();
87 DCHECK(xkb_id.substr(0, prefix_length) == xkb_prefix); 86 DCHECK(xkb_id.substr(0, prefix_length) == xkb_prefix);
88 return xkb_id.substr(prefix_length); 87 return xkb_id.substr(prefix_length);
89 } 88 }
90 89
91 void InputMethodAPI::Shutdown() { 90 void InputMethodAPI::Shutdown() {
92 // UnregisterObserver may have already been called in OnListenerAdded, 91 // UnregisterObserver may have already been called in OnListenerAdded,
93 // but it is safe to call it more than once. 92 // but it is safe to call it more than once.
94 ExtensionSystem::Get(context_)->event_router()->UnregisterObserver(this); 93 EventRouter::Get(context_)->UnregisterObserver(this);
95 } 94 }
96 95
97 void InputMethodAPI::OnListenerAdded( 96 void InputMethodAPI::OnListenerAdded(
98 const extensions::EventListenerInfo& details) { 97 const extensions::EventListenerInfo& details) {
99 DCHECK(!input_method_event_router_.get()); 98 DCHECK(!input_method_event_router_.get());
100 input_method_event_router_.reset( 99 input_method_event_router_.reset(
101 new chromeos::ExtensionInputMethodEventRouter(context_)); 100 new chromeos::ExtensionInputMethodEventRouter(context_));
102 ExtensionSystem::Get(context_)->event_router()->UnregisterObserver(this); 101 EventRouter::Get(context_)->UnregisterObserver(this);
103 } 102 }
104 103
105 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > 104 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> >
106 g_factory = LAZY_INSTANCE_INITIALIZER; 105 g_factory = LAZY_INSTANCE_INITIALIZER;
107 106
108 // static 107 // static
109 BrowserContextKeyedAPIFactory<InputMethodAPI>* 108 BrowserContextKeyedAPIFactory<InputMethodAPI>*
110 InputMethodAPI::GetFactoryInstance() { 109 InputMethodAPI::GetFactoryInstance() {
111 return g_factory.Pointer(); 110 return g_factory.Pointer();
112 } 111 }
113 112
114 } // namespace extensions 113 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698