Bug 1280355 part.1 TISInputSourceWrapper::CurrentInputSource() should create the static instance when it's called r=m_kato

This is preparation. TISInputSourceWrapper is created before starting XPCOM, however, when its first instance is created, TextInputHandler.mm tries to log all keyboard layouts and IMEs which are installed into the system. This would be problem if it uses LazyLogModule because it's initialized at starting XPCOM.

MozReview-Commit-ID: DWz8TylL175

--HG--
extra : rebase_source : f377530f6325d6fcf8f90be5d6856972e9d312e5
This commit is contained in:
Masayuki Nakano 2016-06-16 17:00:38 +09:00
parent d829b3effe
commit a39783f70c
2 changed files with 28 additions and 20 deletions

View File

@ -55,6 +55,10 @@ class TISInputSourceWrapper
{
public:
static TISInputSourceWrapper& CurrentInputSource();
/**
* Shutdown() should be called when nobody doesn't need to use this class.
*/
static void Shutdown();
TISInputSourceWrapper()
{
@ -346,6 +350,8 @@ protected:
int8_t mIsRTL;
bool mOverrideKeyboard;
static TISInputSourceWrapper* sCurrentInputSource;
};
/**

View File

@ -290,7 +290,6 @@ IsControlChar(uint32_t aCharCode)
}
static uint32_t gHandlerInstanceCount = 0;
static TISInputSourceWrapper gCurrentInputSource;
static void
InitLogModule()
@ -303,22 +302,6 @@ InitLogModule()
}
}
static void
InitCurrentInputSource()
{
if (gHandlerInstanceCount > 0 &&
!gCurrentInputSource.IsInitializedByCurrentInputSource()) {
gCurrentInputSource.InitByCurrentInputSource();
}
}
static void
FinalizeCurrentInputSource()
{
gCurrentInputSource.Clear();
}
#pragma mark -
@ -328,12 +311,31 @@ FinalizeCurrentInputSource()
*
******************************************************************************/
TISInputSourceWrapper* TISInputSourceWrapper::sCurrentInputSource = nullptr;
// static
TISInputSourceWrapper&
TISInputSourceWrapper::CurrentInputSource()
{
InitCurrentInputSource();
return gCurrentInputSource;
if (!sCurrentInputSource) {
sCurrentInputSource = new TISInputSourceWrapper();
}
if (!sCurrentInputSource->IsInitializedByCurrentInputSource()) {
sCurrentInputSource->InitByCurrentInputSource();
}
return *sCurrentInputSource;
}
// static
void
TISInputSourceWrapper::Shutdown()
{
if (!sCurrentInputSource) {
return;
}
sCurrentInputSource->Clear();
delete sCurrentInputSource;
sCurrentInputSource = nullptr;
}
bool
@ -3949,7 +3951,7 @@ TextInputHandlerBase::~TextInputHandlerBase()
{
[mView release];
if (--gHandlerInstanceCount == 0) {
FinalizeCurrentInputSource();
TISInputSourceWrapper::Shutdown();
}
}