| OLD | NEW | 
|    1 // Copyright 2013 The Chromium Authors. All rights reserved. |    1 // Copyright 2013 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/base/locale_util.h" |    5 #include "chrome/browser/chromeos/base/locale_util.h" | 
|    6  |    6  | 
 |    7 #include <vector> | 
 |    8  | 
|    7 #include "chrome/browser/browser_process.h" |    9 #include "chrome/browser/browser_process.h" | 
|    8 #include "chrome/browser/chromeos/input_method/input_method_util.h" |   10 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 
|    9 #include "chromeos/ime/input_method_manager.h" |   11 #include "chromeos/ime/input_method_manager.h" | 
|   10 #include "content/public/browser/browser_thread.h" |   12 #include "content/public/browser/browser_thread.h" | 
|   11 #include "ui/base/resource/resource_bundle.h" |   13 #include "ui/base/resource/resource_bundle.h" | 
|   12 #include "ui/gfx/platform_font_pango.h" |   14 #include "ui/gfx/platform_font_pango.h" | 
|   13  |   15  | 
|   14 namespace chromeos { |   16 namespace chromeos { | 
|   15  |   17  | 
|   16 namespace { |   18 namespace { | 
|   17  |   19  | 
|   18 struct SwitchLanguageData { |   20 struct SwitchLanguageData { | 
|   19   SwitchLanguageData(const std::string& locale, |   21   SwitchLanguageData(const std::string& locale, | 
|   20                      const bool enableLocaleKeyboardLayouts, |   22                      const bool enableLocaleKeyboardLayouts, | 
 |   23                      const bool login_layouts_only, | 
|   21                      scoped_ptr<locale_util::SwitchLanguageCallback> callback) |   24                      scoped_ptr<locale_util::SwitchLanguageCallback> callback) | 
|   22       : callback(callback.Pass()), |   25       : callback(callback.Pass()), | 
|   23         locale(locale), |   26         locale(locale), | 
|   24         enableLocaleKeyboardLayouts(enableLocaleKeyboardLayouts), |   27         enableLocaleKeyboardLayouts(enableLocaleKeyboardLayouts), | 
 |   28         login_layouts_only(login_layouts_only), | 
|   25         success(false) {} |   29         success(false) {} | 
|   26  |   30  | 
|   27   scoped_ptr<locale_util::SwitchLanguageCallback> callback; |   31   scoped_ptr<locale_util::SwitchLanguageCallback> callback; | 
|   28  |   32  | 
|   29   const std::string locale; |   33   const std::string locale; | 
|   30   const bool enableLocaleKeyboardLayouts; |   34   const bool enableLocaleKeyboardLayouts; | 
 |   35   const bool login_layouts_only; | 
|   31   std::string loaded_locale; |   36   std::string loaded_locale; | 
|   32   bool success; |   37   bool success; | 
|   33 }; |   38 }; | 
|   34  |   39  | 
|   35 // Runs on SequencedWorkerPool thread under PostTaskAndReply(). |   40 // Runs on SequencedWorkerPool thread under PostTaskAndReply(). | 
|   36 // So data is owned by "Reply" part of PostTaskAndReply() process. |   41 // So data is owned by "Reply" part of PostTaskAndReply() process. | 
|   37 void SwitchLanguageDoReloadLocale(SwitchLanguageData* data) { |   42 void SwitchLanguageDoReloadLocale(SwitchLanguageData* data) { | 
|   38   DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |   43   DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 
|   39  |   44  | 
|   40   data->loaded_locale = |   45   data->loaded_locale = | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|   51   if (data->success) { |   56   if (data->success) { | 
|   52     g_browser_process->SetApplicationLocale(data->loaded_locale); |   57     g_browser_process->SetApplicationLocale(data->loaded_locale); | 
|   53  |   58  | 
|   54     if (data->enableLocaleKeyboardLayouts) { |   59     if (data->enableLocaleKeyboardLayouts) { | 
|   55       // If we have switched the locale, enable the keyboard layouts that |   60       // If we have switched the locale, enable the keyboard layouts that | 
|   56       // are necessary for the new locale.  Change the current input method |   61       // are necessary for the new locale.  Change the current input method | 
|   57       // to the hardware keyboard layout since the input method currently in |   62       // to the hardware keyboard layout since the input method currently in | 
|   58       // use may not be supported by the new locale (3rd parameter). |   63       // use may not be supported by the new locale (3rd parameter). | 
|   59       input_method::InputMethodManager* manager = |   64       input_method::InputMethodManager* manager = | 
|   60           input_method::InputMethodManager::Get(); |   65           input_method::InputMethodManager::Get(); | 
|   61       manager->EnableLayouts( |   66       manager->EnableLoginLayouts( | 
|   62           data->locale, |   67           data->locale, | 
|   63           manager->GetInputMethodUtil()->GetHardwareInputMethodId()); |   68           manager->GetInputMethodUtil()->GetHardwareLoginInputMethodId()); | 
 |   69       if (!data->login_layouts_only) { | 
 |   70         // Enable all the other layouts | 
 |   71         std::vector<std::string> candidates; | 
 |   72         input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); | 
 |   73         // Add input methods associated with the language. | 
 |   74         util->GetInputMethodIdsFromLanguageCode( | 
 |   75             data->locale, input_method::kKeyboardLayoutsOnly, &candidates); | 
 |   76         manager->EnableInputMethods(candidates); | 
 |   77       } | 
|   64     } |   78     } | 
|   65   } |   79   } | 
|   66   gfx::PlatformFontPango::ReloadDefaultFont(); |   80   gfx::PlatformFontPango::ReloadDefaultFont(); | 
|   67   if (data->callback) |   81   if (data->callback) | 
|   68     data->callback->Run(data->locale, data->loaded_locale, data->success); |   82     data->callback->Run(data->locale, data->loaded_locale, data->success); | 
|   69 } |   83 } | 
|   70  |   84  | 
|   71 }  // namespace |   85 }  // namespace | 
|   72  |   86  | 
|   73 namespace locale_util { |   87 namespace locale_util { | 
|   74  |   88  | 
|   75 void SwitchLanguage(const std::string& locale, |   89 void SwitchLanguage(const std::string& locale, | 
|   76                     bool enableLocaleKeyboardLayouts, |   90                     const bool enableLocaleKeyboardLayouts, | 
 |   91                     const bool login_layouts_only, | 
|   77                     scoped_ptr<SwitchLanguageCallback> callback) { |   92                     scoped_ptr<SwitchLanguageCallback> callback) { | 
|   78   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |   93   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 
|   79   scoped_ptr<SwitchLanguageData> data(new SwitchLanguageData( |   94   scoped_ptr<SwitchLanguageData> data( | 
|   80       locale, enableLocaleKeyboardLayouts, callback.Pass())); |   95       new SwitchLanguageData(locale, | 
 |   96                              enableLocaleKeyboardLayouts, | 
 |   97                              login_layouts_only, | 
 |   98                              callback.Pass())); | 
|   81   base::Closure reloader( |   99   base::Closure reloader( | 
|   82       base::Bind(&SwitchLanguageDoReloadLocale, base::Unretained(data.get()))); |  100       base::Bind(&SwitchLanguageDoReloadLocale, base::Unretained(data.get()))); | 
|   83   content::BrowserThread::PostBlockingPoolTaskAndReply( |  101   content::BrowserThread::PostBlockingPoolTaskAndReply( | 
|   84       FROM_HERE, |  102       FROM_HERE, | 
|   85       reloader, |  103       reloader, | 
|   86       base::Bind(&FinishSwitchLanguage, base::Passed(data.Pass()))); |  104       base::Bind(&FinishSwitchLanguage, base::Passed(data.Pass()))); | 
|   87 } |  105 } | 
|   88  |  106  | 
|   89 }  // namespace locale_util |  107 }  // namespace locale_util | 
|   90 }  // namespace chromeos |  108 }  // namespace chromeos | 
| OLD | NEW |