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

Side by Side 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: 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 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/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/chromeos/extensions/input_method_api_factory.h"
8 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" 9 #include "chrome/browser/chromeos/extensions/input_method_event_router.h"
9 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" 10 #include "chrome/browser/chromeos/input_method/input_method_configuration.h"
10 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 11 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
11 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/event_names.h"
12 #include "chrome/browser/extensions/extension_system.h" 13 #include "chrome/browser/extensions/extension_system.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 15
15 namespace extensions { 16 namespace extensions {
16 17
17 GetInputMethodFunction::GetInputMethodFunction() { 18 GetInputMethodFunction::GetInputMethodFunction() {
18 } 19 }
19 20
20 GetInputMethodFunction::~GetInputMethodFunction() { 21 GetInputMethodFunction::~GetInputMethodFunction() {
21 } 22 }
22 23
23 bool GetInputMethodFunction::RunImpl() { 24 bool GetInputMethodFunction::RunImpl() {
24 #if !defined(OS_CHROMEOS) 25 #if !defined(OS_CHROMEOS)
25 NOTREACHED(); 26 NOTREACHED();
26 return false; 27 return false;
27 #else 28 #else
28 chromeos::ExtensionInputMethodEventRouter* router = 29 chromeos::ExtensionInputMethodEventRouter* router =
29 extensions::ExtensionSystem::Get(profile_)->extension_service()-> 30 InputMethodAPI::Get(profile_)->input_method_event_router();
30 input_method_event_router();
31 chromeos::input_method::InputMethodManager* manager = 31 chromeos::input_method::InputMethodManager* manager =
32 chromeos::input_method::GetInputMethodManager(); 32 chromeos::input_method::GetInputMethodManager();
33 const std::string input_method = 33 const std::string input_method =
34 router->GetInputMethodForXkb(manager->GetCurrentInputMethod().id()); 34 router->GetInputMethodForXkb(manager->GetCurrentInputMethod().id());
Yoyo Zhou 2012/12/13 18:27:03 I was looking at this earlier and it seems like Ge
Joe Thomas 2012/12/17 20:56:28 Done. that makes sense.
35 SetResult(Value::CreateStringValue(input_method)); 35 SetResult(Value::CreateStringValue(input_method));
36 return true; 36 return true;
37 #endif 37 #endif
38 } 38 }
39 39
40 InputMethodAPI::InputMethodAPI(Profile* profile)
41 : profile_(profile) {
42 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
43 this, event_names::kOnInputMethodChanged);
44 }
45
46 InputMethodAPI::~InputMethodAPI() {
47 }
48
49 // static
50 InputMethodAPI* InputMethodAPI::Get(Profile* profile) {
51 return InputMethodAPIFactory::GetForProfile(profile);
52 }
53
54 chromeos::ExtensionInputMethodEventRouter*
55 InputMethodAPI::input_method_event_router() {
56 if (!input_method_event_router_) {
57 input_method_event_router_.reset(
58 new chromeos::ExtensionInputMethodEventRouter());
59 }
60 return input_method_event_router_.get();
61 }
62
63 void InputMethodAPI::Shutdown() {
64 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
65 }
66
67 void InputMethodAPI::OnListenerAdded(
68 const extensions::EventListenerInfo& details) {
69 input_method_event_router();
70 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
71 }
72
40 } // namespace extensions 73 } // namespace extensions
OLDNEW
« 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