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

Side by Side Diff: chrome/browser/extensions/api/input_ime/input_ime_api.cc

Issue 428783008: GetActiveUserProfile() should not be called before profile is initialized. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment on GetProfile added. Created 6 years, 4 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/extensions/api/input_ime/input_ime_api.h" 5 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/chromeos/login/lock/screen_locker.h" 9 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
10 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" 10 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 } // namespace chromeos 342 } // namespace chromeos
343 343
344 namespace extensions { 344 namespace extensions {
345 345
346 InputImeEventRouter* 346 InputImeEventRouter*
347 InputImeEventRouter::GetInstance() { 347 InputImeEventRouter::GetInstance() {
348 return Singleton<InputImeEventRouter>::get(); 348 return Singleton<InputImeEventRouter>::get();
349 } 349 }
350 350
351 bool InputImeEventRouter::RegisterIme( 351 bool InputImeEventRouter::RegisterIme(
352 Profile* profile,
352 const std::string& extension_id, 353 const std::string& extension_id,
353 const extensions::InputComponentInfo& component) { 354 const extensions::InputComponentInfo& component) {
354 #if defined(USE_X11) 355 #if defined(USE_X11)
355 VLOG(1) << "RegisterIme: " << extension_id << " id: " << component.id; 356 VLOG(1) << "RegisterIme: " << extension_id << " id: " << component.id;
356 357
357 Profile* profile = ProfileManager::GetActiveUserProfile();
358 // Avoid potential mem leaks due to duplicated component IDs. 358 // Avoid potential mem leaks due to duplicated component IDs.
359 if (!profile_engine_map_[profile][extension_id][component.id]) { 359 if (!profile_engine_map_[profile][extension_id][component.id]) {
360 std::vector<std::string> layouts; 360 std::vector<std::string> layouts;
361 layouts.assign(component.layouts.begin(), component.layouts.end()); 361 layouts.assign(component.layouts.begin(), component.layouts.end());
362 362
363 std::vector<std::string> languages; 363 std::vector<std::string> languages;
364 languages.assign(component.languages.begin(), component.languages.end()); 364 languages.assign(component.languages.begin(), component.languages.end());
365 365
366 // Ideally Observer should be per (extension_id + Profile), and multiple 366 // Ideally Observer should be per (extension_id + Profile), and multiple
367 // InputMethodEngine can share one Observer. But it would become tricky 367 // InputMethodEngine can share one Observer. But it would become tricky
368 // to maintain an internal map for observers which does nearly nothing 368 // to maintain an internal map for observers which does nearly nothing
369 // but just make sure they can properly deleted. 369 // but just make sure they can properly deleted.
370 // Making Obesrver per InputMethodEngine can make things cleaner. 370 // Making Obesrver per InputMethodEngine can make things cleaner.
371 scoped_ptr<chromeos::InputMethodEngineInterface::Observer> observer( 371 scoped_ptr<chromeos::InputMethodEngineInterface::Observer> observer(
372 new chromeos::ImeObserver(profile, extension_id)); 372 new chromeos::ImeObserver(profile, extension_id));
373 chromeos::InputMethodEngine* engine = new chromeos::InputMethodEngine(); 373 chromeos::InputMethodEngine* engine = new chromeos::InputMethodEngine();
374 engine->Initialize(observer.Pass(), 374 engine->Initialize(profile,
375 observer.Pass(),
375 component.name.c_str(), 376 component.name.c_str(),
376 extension_id.c_str(), 377 extension_id.c_str(),
377 component.id.c_str(), 378 component.id.c_str(),
378 languages, 379 languages,
379 layouts, 380 layouts,
380 component.options_page_url, 381 component.options_page_url,
381 component.input_view_url); 382 component.input_view_url);
382 profile_engine_map_[profile][extension_id][component.id] = engine; 383 profile_engine_map_[profile][extension_id][component.id] = engine;
383 } 384 }
384 385
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 const Extension* extension) { 848 const Extension* extension) {
848 const std::vector<InputComponentInfo>* input_components = 849 const std::vector<InputComponentInfo>* input_components =
849 extensions::InputComponents::GetInputComponents(extension); 850 extensions::InputComponents::GetInputComponents(extension);
850 if (!input_components) 851 if (!input_components)
851 return; 852 return;
852 for (std::vector<extensions::InputComponentInfo>::const_iterator component = 853 for (std::vector<extensions::InputComponentInfo>::const_iterator component =
853 input_components->begin(); 854 input_components->begin();
854 component != input_components->end(); 855 component != input_components->end();
855 ++component) { 856 ++component) {
856 if (component->type == extensions::INPUT_COMPONENT_TYPE_IME) { 857 if (component->type == extensions::INPUT_COMPONENT_TYPE_IME) {
857 // Don't pass profile_ to register ime, instead always use 858 // If |browser_context| looks like signin profile, use the real signin
858 // GetActiveUserProfile. It is because: 859 // profile. This is because IME extensions for signin profile are run
859 // The original profile for login screen is called signin profile. 860 // in Off-The-Record profile, based on given static defaults.
860 // And the active profile is the incognito profile based on signin 861 // So if |profile_| is signin profile, we need to make sure
861 // profile. So if |profile_| is signin profile, we need to make sure
862 // the router/observer runs under its incognito profile, because the 862 // the router/observer runs under its incognito profile, because the
863 // component extensions were installed under its incognito profile. 863 // component extensions were installed under its incognito profile.
864 input_ime_event_router()->RegisterIme(extension->id(), *component); 864 Profile* profile = Profile::FromBrowserContext(browser_context);
865 if (chromeos::ProfileHelper::IsSigninProfile(profile))
866 profile = chromeos::ProfileHelper::GetSigninProfile();
867 input_ime_event_router()->RegisterIme(
868 profile, extension->id(), *component);
865 } 869 }
866 } 870 }
867 } 871 }
868 872
869 void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context, 873 void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context,
870 const Extension* extension, 874 const Extension* extension,
871 UnloadedExtensionInfo::Reason reason) { 875 UnloadedExtensionInfo::Reason reason) {
872 const std::vector<InputComponentInfo>* input_components = 876 const std::vector<InputComponentInfo>* input_components =
873 extensions::InputComponents::GetInputComponents(extension); 877 extensions::InputComponents::GetInputComponents(extension);
874 if (!input_components) 878 if (!input_components)
875 return; 879 return;
876 if (input_components->size() > 0) 880 if (input_components->size() > 0)
877 input_ime_event_router()->UnregisterAllImes(extension->id()); 881 input_ime_event_router()->UnregisterAllImes(extension->id());
878 } 882 }
879 883
880 void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) { 884 void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) {
881 InputMethodEngineInterface* engine = 885 InputMethodEngineInterface* engine =
882 input_ime_event_router()->GetActiveEngine(details.extension_id); 886 input_ime_event_router()->GetActiveEngine(details.extension_id);
883 if (engine) 887 if (engine)
884 engine->NotifyImeReady(); 888 engine->NotifyImeReady();
885 } 889 }
886 890
887 InputImeEventRouter* InputImeAPI::input_ime_event_router() { 891 InputImeEventRouter* InputImeAPI::input_ime_event_router() {
888 return InputImeEventRouter::GetInstance(); 892 return InputImeEventRouter::GetInstance();
889 } 893 }
890 894
891 } // namespace extensions 895 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/input_ime/input_ime_api.h ('k') | chromeos/ime/input_method_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698