~indicator-applet-developers/hud/trunk.14.04

« back to all changes in this revision

Viewing changes to service/HudServiceImpl.cpp

  • Committer: CI bot
  • Author(s): Pete Woods, Marcus Tomlinson
  • Date: 2014-06-04 14:04:03 UTC
  • mfrom: (390.1.44 trunk)
  • Revision ID: ps-jenkins@lists.canonical.com-20140604140403-a70c33snru5b6k4x
Harden HUD against misbehaving applications

Report the offending applications using Apport's recoverable problem tool.
Switch to using shared pointers where possible for managing memory. Fixes: 1298656, 1316473, 1322050, 1325538

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
                QList<Suggestion> &suggestions, QDBusVariant &querykey) {
105
105
        QString sender(messageSender());
106
106
 
107
 
        Query::Ptr query(m_legacyQueries[sender]);
 
107
        QPair<Query::Ptr, QSharedPointer<QTimer>> entry(m_legacyQueries[sender]);
 
108
        Query::Ptr query(entry.first);
 
109
        QSharedPointer<QTimer> legacyTimeout(entry.second);
108
110
        if (query.isNull()) {
109
111
                query = createQuery(queryString, sender,
110
112
                                Query::EmptyBehaviour::NO_SUGGESTIONS);
111
 
                m_legacyQueries[sender] = query;
 
113
 
 
114
                legacyTimeout.reset(new QTimer());
 
115
                legacyTimeout->setInterval(2000);
 
116
                legacyTimeout->setSingleShot(true);
 
117
                connect(legacyTimeout.data(), SIGNAL(timeout()), this,
 
118
                                SLOT(legacyTimeout()));
 
119
 
 
120
                m_legacyQueries[sender] = qMakePair(query, legacyTimeout);
112
121
        } else {
113
122
                query->UpdateQuery(queryString);
 
123
                legacyTimeout->stop();
 
124
                legacyTimeout->setProperty("sender", QVariant());
114
125
        }
115
126
 
116
127
        // The legacy API only allows you to search the current application
142
153
        Q_UNUSED(timestamp);
143
154
        QString sender(messageSender());
144
155
 
145
 
        Query::Ptr query(m_legacyQueries.take(sender));
 
156
        QPair<Query::Ptr, QSharedPointer<QTimer>> entry(m_legacyQueries.take(sender));
 
157
        Query::Ptr query(entry.first);
 
158
        QSharedPointer<QTimer> legacyTimeout(entry.second);
146
159
        if (!query.isNull()) {
 
160
                legacyTimeout->stop();
 
161
                legacyTimeout->setProperty("sender", QVariant());
 
162
 
147
163
                query->ExecuteCommand(itemKey, timestamp);
148
164
                closeQuery(query->path());
149
165
        }
156
172
        // We don't actually close legacy queries, or we'd be constructing
157
173
        // and destructing them during the search, due to the way that
158
174
        // Unity7 uses the API.
159
 
        Query::Ptr query(m_legacyQueries[sender]);
 
175
        QPair<Query::Ptr, QSharedPointer<QTimer>> entry(m_legacyQueries[sender]);
 
176
        Query::Ptr query(entry.first);
 
177
        QSharedPointer<QTimer> legacyTimeout(entry.second);
160
178
        if (!query.isNull()) {
161
179
                query->UpdateQuery(QString());
162
 
        }
 
180
                legacyTimeout->start();
 
181
                legacyTimeout->setProperty("sender", sender);
 
182
        }
 
183
}
 
184
 
 
185
void HudServiceImpl::legacyTimeout() {
 
186
        QObject *timer(sender());
 
187
        if (!timer) {
 
188
                return;
 
189
        }
 
190
 
 
191
        QVariant from(timer->property("sender"));
 
192
        if (from.isNull()) {
 
193
                return;
 
194
        }
 
195
 
 
196
        QString sender(from.toString());
 
197
        QPair<Query::Ptr, QSharedPointer<QTimer>> entry(m_legacyQueries.take(sender));
 
198
        Query::Ptr query(entry.first);
 
199
        if (query) {
 
200
                closeQuery(query->path());
 
201
        }
 
202
 
163
203
}