forked from qt-creator/qt-creator
MimeDatabase: Add some startup phase tracking
... to warn about situations where Mime types are registered too late (i.e. after Plugin::initialize() or used too early (i.e. before Plugin::extensionsInitialized()) Change-Id: I22681e94bfdd508e954bb3457b834ec3ad1f0fee Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -49,6 +49,7 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/executeondestruction.h>
|
#include <utils/executeondestruction.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
|
#include <utils/mimetypes/mimedatabase.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/synchronousprocess.h>
|
#include <utils/synchronousprocess.h>
|
||||||
|
|
||||||
@@ -271,9 +272,10 @@ enum { debugLeaks = 0 };
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
using namespace ExtensionSystem;
|
|
||||||
using namespace ExtensionSystem::Internal;
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
using namespace ExtensionSystem::Internal;
|
||||||
|
|
||||||
|
namespace ExtensionSystem {
|
||||||
|
|
||||||
static Internal::PluginManagerPrivate *d = 0;
|
static Internal::PluginManagerPrivate *d = 0;
|
||||||
static PluginManager *m_instance = 0;
|
static PluginManager *m_instance = 0;
|
||||||
@@ -1232,12 +1234,15 @@ void PluginManagerPrivate::removeObject(QObject *obj)
|
|||||||
void PluginManagerPrivate::loadPlugins()
|
void PluginManagerPrivate::loadPlugins()
|
||||||
{
|
{
|
||||||
QList<PluginSpec *> queue = loadQueue();
|
QList<PluginSpec *> queue = loadQueue();
|
||||||
|
MimeDatabase::setStartupPhase(MimeDatabase::PluginsLoading);
|
||||||
foreach (PluginSpec *spec, queue) {
|
foreach (PluginSpec *spec, queue) {
|
||||||
loadPlugin(spec, PluginSpec::Loaded);
|
loadPlugin(spec, PluginSpec::Loaded);
|
||||||
}
|
}
|
||||||
|
MimeDatabase::setStartupPhase(MimeDatabase::PluginsInitializing);
|
||||||
foreach (PluginSpec *spec, queue) {
|
foreach (PluginSpec *spec, queue) {
|
||||||
loadPlugin(spec, PluginSpec::Initialized);
|
loadPlugin(spec, PluginSpec::Initialized);
|
||||||
}
|
}
|
||||||
|
MimeDatabase::setStartupPhase(MimeDatabase::PluginsDelayedInitializing);
|
||||||
Utils::reverseForeach(queue, [this](PluginSpec *spec) {
|
Utils::reverseForeach(queue, [this](PluginSpec *spec) {
|
||||||
loadPlugin(spec, PluginSpec::Running);
|
loadPlugin(spec, PluginSpec::Running);
|
||||||
if (spec->state() == PluginSpec::Running) {
|
if (spec->state() == PluginSpec::Running) {
|
||||||
@@ -1248,6 +1253,7 @@ void PluginManagerPrivate::loadPlugins()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit q->pluginsChanged();
|
emit q->pluginsChanged();
|
||||||
|
MimeDatabase::setStartupPhase(MimeDatabase::UpAndRunning);
|
||||||
|
|
||||||
delayedInitializeTimer = new QTimer;
|
delayedInitializeTimer = new QTimer;
|
||||||
delayedInitializeTimer->setInterval(DELAYED_INITIALIZE_INTERVAL);
|
delayedInitializeTimer->setInterval(DELAYED_INITIALIZE_INTERVAL);
|
||||||
@@ -1699,3 +1705,5 @@ QObject *PluginManager::getObjectByClassName(const QString &className)
|
|||||||
return obj->inherits(ba.constData());
|
return obj->inherits(ba.constData());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // ExtensionSystem
|
||||||
|
@@ -335,6 +335,11 @@ void MimeDatabase::addMimeTypes(const QString &fileName)
|
|||||||
{
|
{
|
||||||
auto d = MimeDatabasePrivate::instance();
|
auto d = MimeDatabasePrivate::instance();
|
||||||
QMutexLocker locker(&d->mutex);
|
QMutexLocker locker(&d->mutex);
|
||||||
|
|
||||||
|
if (d->m_startupPhase >= MimeDatabase::PluginsDelayedInitializing)
|
||||||
|
qWarning("Adding items from %s to MimeDatabase after initialization time",
|
||||||
|
qPrintable(fileName));
|
||||||
|
|
||||||
auto xmlProvider = static_cast<MimeXMLProvider *>(d->provider());
|
auto xmlProvider = static_cast<MimeXMLProvider *>(d->provider());
|
||||||
xmlProvider->addFile(fileName);
|
xmlProvider->addFile(fileName);
|
||||||
}
|
}
|
||||||
@@ -364,11 +369,19 @@ QString MimeDatabase::allFiltersString(QString *allFilesFilter)
|
|||||||
|
|
||||||
QString MimeDatabase::allFilesFilterString()
|
QString MimeDatabase::allFilesFilterString()
|
||||||
{
|
{
|
||||||
|
auto d = MimeDatabasePrivate::instance();
|
||||||
|
if (d->m_startupPhase <= MimeDatabase::PluginsInitializing)
|
||||||
|
qWarning("Accessing MimeDatabase files filter strings before plugins are initialized");
|
||||||
|
|
||||||
return QCoreApplication::translate("Core", ALL_FILES_FILTER.source, ALL_FILES_FILTER.comment);
|
return QCoreApplication::translate("Core", ALL_FILES_FILTER.source, ALL_FILES_FILTER.comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList MimeDatabase::allGlobPatterns()
|
QStringList MimeDatabase::allGlobPatterns()
|
||||||
{
|
{
|
||||||
|
auto d = MimeDatabasePrivate::instance();
|
||||||
|
if (d->m_startupPhase <= MimeDatabase::PluginsInitializing)
|
||||||
|
qWarning("Accessing MimeDatabase glob patterns before plugins are initialized");
|
||||||
|
|
||||||
MimeDatabase mdb;
|
MimeDatabase mdb;
|
||||||
QStringList patterns;
|
QStringList patterns;
|
||||||
foreach (const MimeType &mt, mdb.allMimeTypes())
|
foreach (const MimeType &mt, mdb.allMimeTypes())
|
||||||
@@ -384,6 +397,9 @@ MimeType MimeDatabase::mimeTypeForName(const QString &nameOrAlias) const
|
|||||||
{
|
{
|
||||||
QMutexLocker locker(&d->mutex);
|
QMutexLocker locker(&d->mutex);
|
||||||
|
|
||||||
|
if (d->m_startupPhase <= MimeDatabase::PluginsInitializing)
|
||||||
|
qWarning("Accessing MimeDatabase for %s before plugins are initialized", qPrintable(nameOrAlias));
|
||||||
|
|
||||||
return d->mimeTypeForName(nameOrAlias);
|
return d->mimeTypeForName(nameOrAlias);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,3 +702,12 @@ void MimeDatabase::setMagicRulesForMimeType(const MimeType &mimeType, const QMap
|
|||||||
QMutexLocker locker(&d->mutex);
|
QMutexLocker locker(&d->mutex);
|
||||||
return d->provider()->setMagicRulesForMimeType(mimeType, rules);
|
return d->provider()->setMagicRulesForMimeType(mimeType, rules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MimeDatabase::setStartupPhase(MimeDatabase::StartupPhase phase)
|
||||||
|
{
|
||||||
|
auto d = MimeDatabasePrivate::instance();
|
||||||
|
QMutexLocker locker(&d->mutex);
|
||||||
|
if (phase != d->m_startupPhase + 1)
|
||||||
|
qWarning("Unexpected jump in MimedDatabase lifetime from %d to %d", d->m_startupPhase, phase);
|
||||||
|
d->m_startupPhase = phase;
|
||||||
|
}
|
||||||
|
@@ -98,6 +98,16 @@ public:
|
|||||||
static void setMagicRulesForMimeType(const MimeType &mimeType,
|
static void setMagicRulesForMimeType(const MimeType &mimeType,
|
||||||
const QMap<int, QList<Internal::MimeMagicRule> > &rules); // priority -> rules
|
const QMap<int, QList<Internal::MimeMagicRule> > &rules); // priority -> rules
|
||||||
|
|
||||||
|
// For debugging purposes.
|
||||||
|
enum StartupPhase {
|
||||||
|
BeforeInitialize,
|
||||||
|
PluginsLoading,
|
||||||
|
PluginsInitializing, // Register up to here.
|
||||||
|
PluginsDelayedInitializing, // Use from here on.
|
||||||
|
UpAndRunning
|
||||||
|
};
|
||||||
|
static void setStartupPhase(StartupPhase);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Internal::MimeDatabasePrivate *d;
|
Internal::MimeDatabasePrivate *d;
|
||||||
};
|
};
|
||||||
|
@@ -96,6 +96,8 @@ public:
|
|||||||
mutable MimeProviderBase *m_provider;
|
mutable MimeProviderBase *m_provider;
|
||||||
const QString m_defaultMimeType;
|
const QString m_defaultMimeType;
|
||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
|
|
||||||
|
int m_startupPhase = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
Reference in New Issue
Block a user