Merge lp:~mardy/ubuntu-system-settings-online-accounts/headless-service into lp:~mardy/ubuntu-system-settings-online-accounts/master

Proposed by Alberto Mardegan
Status: Merged
Merged at revision: 131
Proposed branch: lp:~mardy/ubuntu-system-settings-online-accounts/headless-service
Merge into: lp:~mardy/ubuntu-system-settings-online-accounts/master
Diff against target: 3480 lines (+1864/-474)
54 files modified
.bzrignore (+9/-8)
client/OnlineAccountsClient/OnlineAccountsClient.pro (+2/-2)
client/OnlineAccountsClient/setup.cpp (+1/-1)
common-project-config.pri (+3/-0)
debian/ubuntu-system-settings-online-accounts.install (+1/-0)
online-accounts-service/com.ubuntu.OnlineAccountsUi.service.in (+1/-1)
online-accounts-service/main.cpp (+109/-0)
online-accounts-service/online-accounts-service.pro (+73/-0)
online-accounts-service/request-manager.cpp (+39/-6)
online-accounts-service/request-manager.h (+3/-1)
online-accounts-service/request.cpp (+214/-0)
online-accounts-service/request.h (+70/-0)
online-accounts-service/service.cpp (+3/-11)
online-accounts-service/signonui-service.cpp (+19/-33)
online-accounts-service/ui-proxy.cpp (+250/-0)
online-accounts-service/ui-proxy.h (+54/-0)
online-accounts-ui/browser-request.cpp (+6/-9)
online-accounts-ui/browser-request.h (+2/-4)
online-accounts-ui/ipc.cpp (+184/-0)
online-accounts-ui/ipc.h (+67/-0)
online-accounts-ui/main.cpp (+18/-68)
online-accounts-ui/online-accounts-ui-helper.pro (+4/-27)
online-accounts-ui/online-accounts-ui.pro (+1/-1)
online-accounts-ui/panel-request.cpp (+6/-7)
online-accounts-ui/panel-request.h (+4/-3)
online-accounts-ui/provider-request.cpp (+4/-3)
online-accounts-ui/provider-request.h (+3/-2)
online-accounts-ui/request-handler.cpp (+6/-0)
online-accounts-ui/request.cpp (+65/-52)
online-accounts-ui/request.h (+12/-6)
online-accounts-ui/signonui-request.cpp (+10/-9)
online-accounts-ui/signonui-request.h (+6/-6)
online-accounts-ui/ui-server.cpp (+199/-0)
online-accounts-ui/ui-server.h (+57/-0)
tests/client/tst_client.cpp (+1/-1)
tests/client/tst_qml_client.cpp (+1/-1)
tests/online-accounts-service/online-accounts-service.pro (+4/-0)
tests/online-accounts-service/tst_inactivity_timer.pro (+7/-3)
tests/online-accounts-service/tst_service.cpp (+128/-104)
tests/online-accounts-service/tst_service.pro (+14/-11)
tests/online-accounts-ui/mock/request-mock.cpp (+10/-7)
tests/online-accounts-ui/mock/request-mock.h (+3/-6)
tests/online-accounts-ui/mock/ui-server-mock.cpp (+68/-0)
tests/online-accounts-ui/mock/ui-server-mock.h (+53/-0)
tests/online-accounts-ui/online-accounts-ui.pri (+18/-0)
tests/online-accounts-ui/online-accounts-ui.pro (+0/-2)
tests/online-accounts-ui/qml/Source/qmldir (+1/-1)
tests/online-accounts-ui/tst_access_model.pro (+8/-15)
tests/online-accounts-ui/tst_application_manager.pro (+8/-15)
tests/online-accounts-ui/tst_notification.pro (+3/-11)
tests/online-accounts-ui/tst_signonui_request.cpp (+11/-13)
tests/online-accounts-ui/tst_signonui_request.pro (+16/-21)
tests/tests.pro (+1/-0)
ubuntu-system-settings-online-accounts.pro (+4/-3)
To merge this branch: bzr merge lp:~mardy/ubuntu-system-settings-online-accounts/headless-service
Reviewer Review Type Date Requested Status
Alexandre Abreu (community) Approve
David Barth (community) Approve
Justin McPherson Pending
Alberto Mardegan Pending
Review via email: mp+230433@code.launchpad.net

Commit message

Move the UI into a separate process

Introduce online-accounts-service as a UI-less DBus service which acts as a dispatcher for authentication and authorization requests; the requests themselves are processed by a subprocess, online-accounts-ui, of which multiple instances can exists (each instance having single window).

This is the first step towards implementing trust session support.

Description of the change

Move the UI into a separate process

Introduce online-accounts-service as a UI-less DBus service which acts as a dispatcher for authentication and authorization requests; the requests themselves are processed by a subprocess, online-accounts-ui, of which multiple instances can exists (each instance having single window).

This is the first step towards implementing trust session support.

To post a comment you must log in.
Revision history for this message
David Barth (dbarth) wrote :

Nothing obvious to say on that large changeset. It will take some manual testing in a silo to check how the new code holds in real life conditions.

review: Approve
Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

After a "quick-ish" scan seems ok overall, could not do a thorough review though,

review: Approve
136. By Alberto Mardegan

Workaround for crash

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2014-06-09 13:57:32 +0000
3+++ .bzrignore 2014-08-13 14:43:55 +0000
4@@ -31,19 +31,20 @@
5 /debian/*.substvars
6 /plugins/example/libexample.so*
7 /po/*.mo
8-/src/com.ubuntu.OnlineAccountsUi.service
9-/src/module/OnlineAccountsPlugin.pc
10-/src/module/libOnlineAccountsPlugin.so*
11-/src/module/qmldir
12-/src/online-accounts-ui.desktop
13-/src/online-accounts-ui
14+/online-accounts-service/com.ubuntu.OnlineAccountsUi.service
15+/online-accounts-service/online-accounts-service
16+/online-accounts-ui/module/OnlineAccountsPlugin.pc
17+/online-accounts-ui/module/libOnlineAccountsPlugin.so*
18+/online-accounts-ui/module/qmldir
19+/online-accounts-ui/online-accounts-ui.desktop
20+/online-accounts-ui/online-accounts-ui
21 /tests/click-hooks/tst_online_accounts_hooks
22 /tests/client/tst_client
23 /tests/client/tst_qml_client
24+/tests/online-accounts-service/tst_inactivity_timer
25+/tests/online-accounts-service/tst_service
26 /tests/online-accounts-ui/qml/tst_online_accounts_qml
27 /tests/online-accounts-ui/tst_access_model
28 /tests/online-accounts-ui/tst_application_manager
29-/tests/online-accounts-ui/tst_inactivity_timer
30 /tests/online-accounts-ui/tst_notification
31-/tests/online-accounts-ui/tst_service
32 /tests/online-accounts-ui/tst_signonui_request
33
34=== modified file 'client/OnlineAccountsClient/OnlineAccountsClient.pro'
35--- client/OnlineAccountsClient/OnlineAccountsClient.pro 2014-03-19 12:14:14 +0000
36+++ client/OnlineAccountsClient/OnlineAccountsClient.pro 2014-08-13 14:43:55 +0000
37@@ -25,10 +25,10 @@
38 INCLUDEPATH += \
39 $${TOP_SRC_DIR}
40
41-ONLINE_ACCOUNTS_UI_SRC = $${TOP_SRC_DIR}/src
42+ONLINE_ACCOUNTS_SERVICE_SRC = $${TOP_SRC_DIR}/online-accounts-service
43
44 DBUS_INTERFACES += \
45- $${ONLINE_ACCOUNTS_UI_SRC}/com.ubuntu.OnlineAccountsUi.xml
46+ $${ONLINE_ACCOUNTS_SERVICE_SRC}/com.ubuntu.OnlineAccountsUi.xml
47
48 SOURCES += \
49 setup.cpp
50
51=== modified file 'client/OnlineAccountsClient/setup.cpp'
52--- client/OnlineAccountsClient/setup.cpp 2014-05-30 08:09:02 +0000
53+++ client/OnlineAccountsClient/setup.cpp 2014-08-13 14:43:55 +0000
54@@ -20,9 +20,9 @@
55 * <http://www.gnu.org/licenses/>.
56 */
57
58+#include "online-accounts-ui/globals.h"
59 #include "onlineaccountsui_interface.h"
60 #include "setup.h"
61-#include "src/globals.h"
62
63 #include <QDBusConnection>
64 #include <QDBusPendingCallWatcher>
65
66=== modified file 'common-project-config.pri'
67--- common-project-config.pri 2013-08-06 15:06:54 +0000
68+++ common-project-config.pri 2014-08-13 14:43:55 +0000
69@@ -47,3 +47,6 @@
70 PLUGIN_MODULE_DIR = $$system("pkg-config --define-variable=prefix=$${INSTALL_PREFIX} --variable plugin_module_dir SystemSettings")
71 PLUGIN_QML_DIR = $$system("pkg-config --define-variable=prefix=$${INSTALL_PREFIX} --variable plugin_qml_dir SystemSettings")
72 PLUGIN_PRIVATE_MODULE_DIR = $$system("pkg-config --define-variable=prefix=$${INSTALL_PREFIX} --variable plugin_private_module_dir SystemSettings")
73+
74+I18N_DOMAIN="ubuntu-system-settings-online-accounts"
75+SIGNONUI_I18N_DOMAIN="signon-ui"
76
77=== modified file 'debian/ubuntu-system-settings-online-accounts.install'
78--- debian/ubuntu-system-settings-online-accounts.install 2014-06-04 09:59:37 +0000
79+++ debian/ubuntu-system-settings-online-accounts.install 2014-08-13 14:43:55 +0000
80@@ -1,4 +1,5 @@
81 usr/bin/online-accounts-hooks
82+usr/bin/online-accounts-service
83 usr/bin/online-accounts-ui
84 usr/lib/*/pkgconfig/OnlineAccountsPlugin.pc
85 usr/lib/*/ubuntu-system-settings
86
87=== added directory 'online-accounts-service'
88=== renamed file 'src/com.canonical.indicators.webcredentials.xml' => 'online-accounts-service/com.canonical.indicators.webcredentials.xml'
89=== renamed file 'src/com.ubuntu.OnlineAccountsUi.service.in' => 'online-accounts-service/com.ubuntu.OnlineAccountsUi.service.in'
90--- src/com.ubuntu.OnlineAccountsUi.service.in 2013-11-21 12:26:22 +0000
91+++ online-accounts-service/com.ubuntu.OnlineAccountsUi.service.in 2014-08-13 14:43:55 +0000
92@@ -1,3 +1,3 @@
93 [D-BUS Service]
94 Name=com.ubuntu.OnlineAccountsUi
95-Exec=$${INSTALL_PREFIX}/bin/$${TARGET} --desktop_file_hint=$${desktop.path}/$${TARGET}.desktop
96+Exec=$${INSTALL_PREFIX}/bin/$${TARGET}
97
98=== renamed file 'src/com.ubuntu.OnlineAccountsUi.xml' => 'online-accounts-service/com.ubuntu.OnlineAccountsUi.xml'
99=== renamed file 'src/inactivity-timer.cpp' => 'online-accounts-service/inactivity-timer.cpp'
100=== renamed file 'src/inactivity-timer.h' => 'online-accounts-service/inactivity-timer.h'
101=== renamed file 'src/indicator-service.cpp' => 'online-accounts-service/indicator-service.cpp'
102=== renamed file 'src/indicator-service.h' => 'online-accounts-service/indicator-service.h'
103=== added file 'online-accounts-service/main.cpp'
104--- online-accounts-service/main.cpp 1970-01-01 00:00:00 +0000
105+++ online-accounts-service/main.cpp 2014-08-13 14:43:55 +0000
106@@ -0,0 +1,109 @@
107+/*
108+ * Copyright (C) 2013 Canonical Ltd.
109+ *
110+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
111+ *
112+ * This file is part of online-accounts-ui
113+ *
114+ * This program is free software: you can redistribute it and/or modify it
115+ * under the terms of the GNU General Public License version 3, as published
116+ * by the Free Software Foundation.
117+ *
118+ * This program is distributed in the hope that it will be useful, but
119+ * WITHOUT ANY WARRANTY; without even the implied warranties of
120+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
121+ * PURPOSE. See the GNU General Public License for more details.
122+ *
123+ * You should have received a copy of the GNU General Public License along
124+ * with this program. If not, see <http://www.gnu.org/licenses/>.
125+ */
126+
127+#include "debug.h"
128+#include "globals.h"
129+#include "inactivity-timer.h"
130+#include "indicator-service.h"
131+#include "request-manager.h"
132+#include "service.h"
133+#include "signonui-service.h"
134+
135+#include <QCoreApplication>
136+#include <QDBusConnection>
137+#include <QProcessEnvironment>
138+
139+using namespace OnlineAccountsUi;
140+
141+int main(int argc, char **argv)
142+{
143+ QCoreApplication app(argc, argv);
144+
145+ /* read environment variables */
146+ QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
147+ if (environment.contains(QLatin1String("OAU_LOGGING_LEVEL"))) {
148+ bool isOk;
149+ int value = environment.value(
150+ QLatin1String("OAU_LOGGING_LEVEL")).toInt(&isOk);
151+ if (isOk)
152+ setLoggingLevel(value);
153+ }
154+
155+ /* default daemonTimeout to 5 seconds */
156+ int daemonTimeout = 5;
157+
158+ /* override daemonTimeout if OAU_DAEMON_TIMEOUT is set */
159+ if (environment.contains(QLatin1String("OAU_DAEMON_TIMEOUT"))) {
160+ bool isOk;
161+ int value = environment.value(
162+ QLatin1String("OAU_DAEMON_TIMEOUT")).toInt(&isOk);
163+ if (isOk)
164+ daemonTimeout = value;
165+ }
166+
167+ RequestManager *requestManager = new RequestManager();
168+
169+ Service *service = new Service();
170+ QDBusConnection connection = QDBusConnection::sessionBus();
171+ connection.registerService(OAU_SERVICE_NAME);
172+ connection.registerObject(OAU_OBJECT_PATH, service);
173+
174+ SignOnUi::Service *signonuiService = new SignOnUi::Service();
175+ connection.registerService(SIGNONUI_SERVICE_NAME);
176+ connection.registerObject(SIGNONUI_OBJECT_PATH, signonuiService,
177+ QDBusConnection::ExportAllContents);
178+
179+ SignOnUi::IndicatorService *indicatorService =
180+ new SignOnUi::IndicatorService();
181+ connection.registerService(WEBCREDENTIALS_BUS_NAME);
182+ connection.registerObject(WEBCREDENTIALS_OBJECT_PATH,
183+ indicatorService->serviceObject());
184+
185+
186+ InactivityTimer *inactivityTimer = 0;
187+ if (daemonTimeout > 0) {
188+ inactivityTimer = new InactivityTimer(daemonTimeout * 1000);
189+ inactivityTimer->watchObject(requestManager);
190+ inactivityTimer->watchObject(indicatorService);
191+ QObject::connect(inactivityTimer, SIGNAL(timeout()),
192+ &app, SLOT(quit()));
193+ }
194+
195+ int ret = app.exec();
196+
197+ connection.unregisterService(WEBCREDENTIALS_BUS_NAME);
198+ connection.unregisterObject(WEBCREDENTIALS_OBJECT_PATH);
199+ delete indicatorService;
200+
201+ connection.unregisterService(SIGNONUI_SERVICE_NAME);
202+ connection.unregisterObject(SIGNONUI_OBJECT_PATH);
203+ delete signonuiService;
204+
205+ connection.unregisterService(OAU_SERVICE_NAME);
206+ connection.unregisterObject(OAU_OBJECT_PATH);
207+ delete service;
208+
209+ delete requestManager;
210+
211+ delete inactivityTimer;
212+
213+ return ret;
214+}
215+
216
217=== added file 'online-accounts-service/online-accounts-service.pro'
218--- online-accounts-service/online-accounts-service.pro 1970-01-01 00:00:00 +0000
219+++ online-accounts-service/online-accounts-service.pro 2014-08-13 14:43:55 +0000
220@@ -0,0 +1,73 @@
221+include(../common-project-config.pri)
222+include($${TOP_SRC_DIR}/common-vars.pri)
223+
224+TEMPLATE = app
225+TARGET = online-accounts-service
226+
227+CONFIG += \
228+ link_pkgconfig \
229+ no_keywords \
230+ qt
231+
232+QT += \
233+ dbus \
234+ network
235+
236+PKGCONFIG += \
237+ libnotify \
238+ libsignon-qt5 \
239+ signon-plugins-common
240+
241+DBUS_ADAPTORS += \
242+ com.ubuntu.OnlineAccountsUi.xml
243+
244+DEFINES += \
245+ DEBUG_ENABLED \
246+ SIGNONUI_I18N_DOMAIN=\\\"$${SIGNONUI_I18N_DOMAIN}\\\"
247+
248+COMMON_SRC = ../online-accounts-ui
249+
250+INCLUDEPATH += \
251+ $${COMMON_SRC}
252+
253+SOURCES += \
254+ $${COMMON_SRC}/debug.cpp \
255+ $${COMMON_SRC}/i18n.cpp \
256+ $${COMMON_SRC}/ipc.cpp \
257+ $${COMMON_SRC}/notification.cpp \
258+ inactivity-timer.cpp \
259+ indicator-service.cpp \
260+ main.cpp \
261+ reauthenticator.cpp \
262+ request.cpp \
263+ request-manager.cpp \
264+ service.cpp \
265+ signonui-service.cpp \
266+ ui-proxy.cpp
267+
268+HEADERS += \
269+ $${COMMON_SRC}/debug.h \
270+ $${COMMON_SRC}/i18n.h \
271+ $${COMMON_SRC}/ipc.h \
272+ $${COMMON_SRC}/notification.h \
273+ inactivity-timer.h \
274+ indicator-service.h \
275+ reauthenticator.h \
276+ request.h \
277+ request-manager.h \
278+ service.h \
279+ signonui-service.h \
280+ ui-proxy.h
281+
282+QMAKE_SUBSTITUTES += \
283+ com.ubuntu.OnlineAccountsUi.service.in
284+
285+DBUS_ADAPTORS += \
286+ com.canonical.indicators.webcredentials.xml
287+
288+service.path = $${INSTALL_PREFIX}/share/dbus-1/services
289+service.files = \
290+ com.ubuntu.OnlineAccountsUi.service
291+INSTALLS += service
292+
293+include($${TOP_SRC_DIR}/common-installs-config.pri)
294
295=== renamed file 'src/reauthenticator.cpp' => 'online-accounts-service/reauthenticator.cpp'
296=== renamed file 'src/reauthenticator.h' => 'online-accounts-service/reauthenticator.h'
297=== renamed file 'src/request-manager.cpp' => 'online-accounts-service/request-manager.cpp'
298--- src/request-manager.cpp 2014-04-29 12:11:55 +0000
299+++ online-accounts-service/request-manager.cpp 2014-08-13 14:43:55 +0000
300@@ -21,6 +21,7 @@
301 #include "debug.h"
302 #include "request.h"
303 #include "request-manager.h"
304+#include "ui-proxy.h"
305
306 #include <QQueue>
307
308@@ -41,17 +42,19 @@
309 RequestManagerPrivate(RequestManager *service);
310 ~RequestManagerPrivate();
311
312- RequestQueue &queueForWindowId(WId windowId);
313+ RequestQueue &queueForWindowId(quint64 windowId);
314 void enqueue(Request *request);
315 void runQueue(RequestQueue &queue);
316
317 private Q_SLOTS:
318 void onRequestCompleted();
319+ void onProxyFinished();
320
321 private:
322 mutable RequestManager *q_ptr;
323 /* each window Id has a different queue */
324- QMap<WId,RequestQueue> m_requests;
325+ QMap<quint64,RequestQueue> m_requests;
326+ QList<UiProxy*> m_proxies;
327 };
328
329 } // namespace
330@@ -66,7 +69,7 @@
331 {
332 }
333
334-RequestQueue &RequestManagerPrivate::queueForWindowId(WId windowId)
335+RequestQueue &RequestManagerPrivate::queueForWindowId(quint64 windowId)
336 {
337 if (!m_requests.contains(windowId)) {
338 RequestQueue queue;
339@@ -78,9 +81,20 @@
340 void RequestManagerPrivate::enqueue(Request *request)
341 {
342 Q_Q(RequestManager);
343+
344+ /* First, see if any of the existing proxies can handle this request */
345+ Q_FOREACH(UiProxy *proxy, m_proxies) {
346+ if (proxy->hasHandlerFor(request->parameters())) {
347+ QObject::connect(request, SIGNAL(completed()),
348+ request, SLOT(deleteLater()));
349+ proxy->handleRequest(request);
350+ return;
351+ }
352+ }
353+
354 bool wasIdle = q->isIdle();
355
356- WId windowId = request->windowId();
357+ quint64 windowId = request->windowId();
358
359 RequestQueue &queue = queueForWindowId(windowId);
360 queue.enqueue(request);
361@@ -102,9 +116,18 @@
362 return; // Nothing to do
363 }
364
365+ UiProxy *proxy = new UiProxy(this);
366+ if (Q_UNLIKELY(!proxy->init())) {
367+ qWarning() << "UiProxy initialization failed!";
368+ runQueue(queue);
369+ return;
370+ }
371 QObject::connect(request, SIGNAL(completed()),
372 this, SLOT(onRequestCompleted()));
373- request->start();
374+ QObject::connect(proxy, SIGNAL(finished()),
375+ this, SLOT(onProxyFinished()));
376+ m_proxies.append(proxy);
377+ proxy->handleRequest(request);
378 }
379
380 void RequestManagerPrivate::onRequestCompleted()
381@@ -112,7 +135,7 @@
382 Q_Q(RequestManager);
383
384 Request *request = qobject_cast<Request*>(sender());
385- WId windowId = request->windowId();
386+ quint64 windowId = request->windowId();
387
388 RequestQueue &queue = queueForWindowId(windowId);
389 if (request != queue.head()) {
390@@ -135,6 +158,16 @@
391 }
392 }
393
394+void RequestManagerPrivate::onProxyFinished()
395+{
396+ Q_Q(RequestManager);
397+
398+ UiProxy *proxy = qobject_cast<UiProxy*>(sender());
399+ m_proxies.removeOne(proxy);
400+
401+ proxy->deleteLater();
402+}
403+
404 RequestManager::RequestManager(QObject *parent):
405 QObject(parent),
406 d_ptr(new RequestManagerPrivate(this))
407
408=== renamed file 'src/request-manager.h' => 'online-accounts-service/request-manager.h'
409--- src/request-manager.h 2014-04-29 12:11:55 +0000
410+++ online-accounts-service/request-manager.h 2014-08-13 14:43:55 +0000
411@@ -27,8 +27,9 @@
412 namespace OnlineAccountsUi {
413
414 class Request;
415+class UiProxy;
416+
417 class RequestManagerPrivate;
418-
419 class RequestManager: public QObject
420 {
421 Q_OBJECT
422@@ -41,6 +42,7 @@
423 static RequestManager *instance();
424
425 void enqueue(Request *request);
426+ UiProxy *findMatching(const QVariantMap &parameters);
427
428 bool isIdle() const;
429
430
431=== added file 'online-accounts-service/request.cpp'
432--- online-accounts-service/request.cpp 1970-01-01 00:00:00 +0000
433+++ online-accounts-service/request.cpp 2014-08-13 14:43:55 +0000
434@@ -0,0 +1,214 @@
435+/*
436+ * Copyright (C) 2013 Canonical Ltd.
437+ *
438+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
439+ *
440+ * This file is part of online-accounts-ui
441+ *
442+ * This program is free software: you can redistribute it and/or modify it
443+ * under the terms of the GNU General Public License version 3, as published
444+ * by the Free Software Foundation.
445+ *
446+ * This program is distributed in the hope that it will be useful, but
447+ * WITHOUT ANY WARRANTY; without even the implied warranties of
448+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
449+ * PURPOSE. See the GNU General Public License for more details.
450+ *
451+ * You should have received a copy of the GNU General Public License along
452+ * with this program. If not, see <http://www.gnu.org/licenses/>.
453+ */
454+
455+#include "debug.h"
456+#include "globals.h"
457+#include "request.h"
458+
459+using namespace OnlineAccountsUi;
460+
461+static bool mapIsSuperset(const QVariantMap &test, const QVariantMap &set)
462+{
463+ QMapIterator<QString, QVariant> it(set);
464+ while (it.hasNext()) {
465+ it.next();
466+ if (test.value(it.key()) != it.value()) return false;
467+ }
468+
469+ return true;
470+}
471+
472+namespace OnlineAccountsUi {
473+
474+static QList<Request *> allRequests;
475+
476+class RequestPrivate: public QObject
477+{
478+ Q_OBJECT
479+ Q_DECLARE_PUBLIC(Request)
480+
481+public:
482+ RequestPrivate(const QDBusConnection &connection,
483+ const QDBusMessage &message,
484+ const QVariantMap &parameters,
485+ Request *request);
486+ ~RequestPrivate();
487+
488+ quint64 windowId() const {
489+ return m_parameters[OAU_KEY_WINDOW_ID].toUInt();
490+ }
491+
492+private:
493+ QString findClientApparmorProfile();
494+
495+private:
496+ mutable Request *q_ptr;
497+ QDBusConnection m_connection;
498+ QDBusMessage m_message;
499+ QVariantMap m_parameters;
500+ QString m_clientApparmorProfile;
501+ bool m_inProgress;
502+};
503+
504+} // namespace
505+
506+RequestPrivate::RequestPrivate(const QDBusConnection &connection,
507+ const QDBusMessage &message,
508+ const QVariantMap &parameters,
509+ Request *request):
510+ QObject(request),
511+ q_ptr(request),
512+ m_connection(connection),
513+ m_message(message),
514+ m_parameters(parameters),
515+ m_inProgress(false)
516+{
517+ m_clientApparmorProfile = findClientApparmorProfile();
518+}
519+
520+RequestPrivate::~RequestPrivate()
521+{
522+}
523+
524+QString RequestPrivate::findClientApparmorProfile()
525+{
526+ QString uniqueConnectionId = m_message.service();
527+ /* This is mainly for unit tests: real messages on the session bus always
528+ * have a service name. */
529+ if (uniqueConnectionId.isEmpty()) return QString();
530+
531+ QString appId;
532+
533+ QDBusMessage msg =
534+ QDBusMessage::createMethodCall("org.freedesktop.DBus",
535+ "/org/freedesktop/DBus",
536+ "org.freedesktop.DBus",
537+ "GetConnectionAppArmorSecurityContext");
538+ QVariantList args;
539+ args << uniqueConnectionId;
540+ msg.setArguments(args);
541+ QDBusMessage reply = QDBusConnection::sessionBus().call(msg, QDBus::Block);
542+ if (reply.type() == QDBusMessage::ReplyMessage) {
543+ appId = reply.arguments().value(0, QString()).toString();
544+ DEBUG() << "App ID:" << appId;
545+ } else {
546+ qWarning() << "Error getting app ID:" << reply.errorName() <<
547+ reply.errorMessage();
548+ }
549+ return appId;
550+}
551+
552+Request::Request(const QDBusConnection &connection,
553+ const QDBusMessage &message,
554+ const QVariantMap &parameters,
555+ QObject *parent):
556+ QObject(parent),
557+ d_ptr(new RequestPrivate(connection, message, parameters, this))
558+{
559+ allRequests.append(this);
560+}
561+
562+Request::~Request()
563+{
564+ allRequests.removeOne(this);
565+}
566+
567+Request *Request::find(const QVariantMap &match)
568+{
569+ Q_FOREACH(Request *r, allRequests) {
570+ if (mapIsSuperset(r->parameters(), match)) {
571+ return r;
572+ }
573+ }
574+
575+ return 0;
576+}
577+
578+quint64 Request::windowId() const
579+{
580+ Q_D(const Request);
581+ return d->windowId();
582+}
583+
584+void Request::setInProgress(bool inProgress)
585+{
586+ Q_D(Request);
587+ d->m_inProgress = inProgress;
588+}
589+
590+bool Request::isInProgress() const
591+{
592+ Q_D(const Request);
593+ return d->m_inProgress;
594+}
595+
596+const QVariantMap &Request::parameters() const
597+{
598+ Q_D(const Request);
599+ return d->m_parameters;
600+}
601+
602+QString Request::clientApparmorProfile() const
603+{
604+ Q_D(const Request);
605+ return d->m_clientApparmorProfile;
606+}
607+
608+QString Request::interface() const {
609+ Q_D(const Request);
610+ return d->m_message.interface();
611+}
612+
613+void Request::cancel()
614+{
615+ setCanceled();
616+}
617+
618+void Request::fail(const QString &name, const QString &message)
619+{
620+ Q_D(Request);
621+ QDBusMessage reply = d->m_message.createErrorReply(name, message);
622+ d->m_connection.send(reply);
623+
624+ Q_EMIT completed();
625+}
626+
627+void Request::setCanceled()
628+{
629+ Q_D(Request);
630+ if (d->m_inProgress) {
631+ fail(OAU_ERROR_USER_CANCELED, QStringLiteral("Canceled"));
632+ d->m_inProgress = false;
633+ }
634+}
635+
636+void Request::setResult(const QVariantMap &result)
637+{
638+ Q_D(Request);
639+ if (d->m_inProgress) {
640+ QDBusMessage reply = d->m_message.createReply(result);
641+ d->m_connection.send(reply);
642+
643+ Q_EMIT completed();
644+ d->m_inProgress = false;
645+ }
646+}
647+
648+#include "request.moc"
649
650=== added file 'online-accounts-service/request.h'
651--- online-accounts-service/request.h 1970-01-01 00:00:00 +0000
652+++ online-accounts-service/request.h 2014-08-13 14:43:55 +0000
653@@ -0,0 +1,70 @@
654+/*
655+ * Copyright (C) 2013 Canonical Ltd.
656+ *
657+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
658+ *
659+ * This file is part of online-accounts-ui
660+ *
661+ * This program is free software: you can redistribute it and/or modify it
662+ * under the terms of the GNU General Public License version 3, as published
663+ * by the Free Software Foundation.
664+ *
665+ * This program is distributed in the hope that it will be useful, but
666+ * WITHOUT ANY WARRANTY; without even the implied warranties of
667+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
668+ * PURPOSE. See the GNU General Public License for more details.
669+ *
670+ * You should have received a copy of the GNU General Public License along
671+ * with this program. If not, see <http://www.gnu.org/licenses/>.
672+ */
673+
674+#ifndef OAU_REQUEST_H
675+#define OAU_REQUEST_H
676+
677+#include <QDBusConnection>
678+#include <QDBusMessage>
679+#include <QObject>
680+#include <QVariantMap>
681+
682+namespace OnlineAccountsUi {
683+
684+class RequestPrivate;
685+class Request: public QObject
686+{
687+ Q_OBJECT
688+
689+public:
690+ explicit Request(const QDBusConnection &connection,
691+ const QDBusMessage &message,
692+ const QVariantMap &parameters,
693+ QObject *parent = 0);
694+ ~Request();
695+
696+ static Request *find(const QVariantMap &match);
697+
698+ quint64 windowId() const;
699+ void setInProgress(bool inProgress);
700+ bool isInProgress() const;
701+ const QVariantMap &parameters() const;
702+ QString clientApparmorProfile() const;
703+ QString interface() const;
704+
705+public Q_SLOTS:
706+ void cancel();
707+
708+Q_SIGNALS:
709+ void completed();
710+
711+public Q_SLOTS:
712+ void fail(const QString &name, const QString &message);
713+ void setCanceled();
714+ void setResult(const QVariantMap &result);
715+
716+private:
717+ RequestPrivate *d_ptr;
718+ Q_DECLARE_PRIVATE(Request)
719+};
720+
721+} // namespace
722+
723+#endif // OAU_REQUEST_H
724
725=== renamed file 'src/service.cpp' => 'online-accounts-service/service.cpp'
726--- src/service.cpp 2014-05-30 08:09:02 +0000
727+++ online-accounts-service/service.cpp 2014-08-13 14:43:55 +0000
728@@ -44,17 +44,9 @@
729 /* The following line tells QtDBus not to generate a reply now */
730 setDelayedReply(true);
731
732- Request *request = Request::newRequest(connection(),
733- message(),
734- options,
735- this);
736- if (request) {
737- RequestManager *manager = RequestManager::instance();
738- manager->enqueue(request);
739- } else {
740- sendErrorReply(OAU_ERROR_INVALID_PARAMETERS,
741- QStringLiteral("Invalid request"));
742- }
743+ Request *request = new Request(connection(), message(), options, this);
744+ RequestManager *manager = RequestManager::instance();
745+ manager->enqueue(request);
746
747 return QVariantMap();
748 }
749
750=== renamed file 'src/service.h' => 'online-accounts-service/service.h'
751=== renamed file 'src/signonui-service.cpp' => 'online-accounts-service/signonui-service.cpp'
752--- src/signonui-service.cpp 2014-04-29 14:34:44 +0000
753+++ online-accounts-service/signonui-service.cpp 2014-08-13 14:43:55 +0000
754@@ -20,14 +20,12 @@
755
756 #include "debug.h"
757 #include "request.h"
758-#include "request-handler.h"
759 #include "request-manager.h"
760-#include "signonui-request.h"
761 #include "signonui-service.h"
762-#include "browser-request.h"
763
764 #include <QDBusArgument>
765-#include <QtQml>
766+#include <QDir>
767+#include <QStandardPaths>
768 #include <SignOn/uisessiondata_priv.h>
769
770 using namespace SignOnUi;
771@@ -77,6 +75,8 @@
772 void cancelUiRequest(const QString &requestId);
773 void removeIdentityData(quint32 id);
774
775+ static QString rootDirForIdentity(quint32 id);
776+
777 private:
778 mutable Service *q_ptr;
779 };
780@@ -106,20 +106,24 @@
781 }
782 }
783
784+QString ServicePrivate::rootDirForIdentity(quint32 id)
785+{
786+ QString cachePath =
787+ QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
788+ return cachePath + QString("/id-%1").arg(id);
789+}
790+
791 void ServicePrivate::removeIdentityData(quint32 id)
792 {
793 /* Remove any data associated with the given identity. */
794-
795- /* The BrowserRequest class creates a directory to store the cookies */
796- BrowserRequest::removeIdentityData(id);
797+ QDir rootDir(ServicePrivate::rootDirForIdentity(id));
798+ rootDir.removeRecursively();
799 }
800
801 Service::Service(QObject *parent):
802 QObject(parent),
803 d_ptr(new ServicePrivate(this))
804 {
805- qmlRegisterType<SignOnUi::RequestHandler>("Ubuntu.OnlineAccounts.Plugin",
806- 1, 0, "RequestHandler");
807 }
808
809 Service::~Service()
810@@ -135,29 +139,12 @@
811 setDelayedReply(true);
812
813 OnlineAccountsUi::Request *request =
814- OnlineAccountsUi::Request::newRequest(connection(),
815- message(),
816- cleanParameters,
817- this);
818-
819- /* Check if a RequestHandler has been setup to handle this request. If
820- * so, bing the request object to the handler and start the request
821- * immediately. */
822- SignOnUi::Request *signonRequest =
823- qobject_cast<SignOnUi::Request*>(request);
824- Q_ASSERT(signonRequest != 0);
825-
826- RequestHandler *handler = RequestHandler::findMatching(cleanParameters);
827- if (handler != 0) {
828- DEBUG() << "Found RequestHandler!";
829- signonRequest->setHandler(handler);
830- QObject::connect(signonRequest, SIGNAL(completed()),
831- signonRequest, SLOT(deleteLater()));
832- signonRequest->start();
833- } else {
834- // proceed normally
835- OnlineAccountsUi::RequestManager::instance()->enqueue(request);
836- }
837+ new OnlineAccountsUi::Request(connection(),
838+ message(),
839+ cleanParameters,
840+ this);
841+
842+ OnlineAccountsUi::RequestManager::instance()->enqueue(request);
843
844 return QVariantMap();
845 }
846@@ -165,7 +152,6 @@
847 QVariantMap Service::refreshDialog(const QVariantMap &newParameters)
848 {
849 QVariantMap cleanParameters = expandDBusArguments(newParameters);
850- QString requestId = Request::id(cleanParameters);
851 // TODO find the request and update it
852
853 /* The following line tells QtDBus not to generate a reply now */
854
855=== renamed file 'src/signonui-service.h' => 'online-accounts-service/signonui-service.h'
856=== added file 'online-accounts-service/ui-proxy.cpp'
857--- online-accounts-service/ui-proxy.cpp 1970-01-01 00:00:00 +0000
858+++ online-accounts-service/ui-proxy.cpp 2014-08-13 14:43:55 +0000
859@@ -0,0 +1,250 @@
860+/*
861+ * Copyright (C) 2014 Canonical Ltd.
862+ *
863+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
864+ *
865+ * This file is part of online-accounts-ui
866+ *
867+ * This program is free software: you can redistribute it and/or modify it
868+ * under the terms of the GNU General Public License version 3, as published
869+ * by the Free Software Foundation.
870+ *
871+ * This program is distributed in the hope that it will be useful, but
872+ * WITHOUT ANY WARRANTY; without even the implied warranties of
873+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
874+ * PURPOSE. See the GNU General Public License for more details.
875+ *
876+ * You should have received a copy of the GNU General Public License along
877+ * with this program. If not, see <http://www.gnu.org/licenses/>.
878+ */
879+
880+#include "debug.h"
881+#include "ipc.h"
882+#include "request.h"
883+#include "ui-proxy.h"
884+
885+#include <QDir>
886+#include <QFileInfo>
887+#include <QLocalServer>
888+#include <QLocalSocket>
889+#include <QProcess>
890+#include <QStandardPaths>
891+#include <SignOn/uisessiondata_priv.h>
892+
893+using namespace OnlineAccountsUi;
894+
895+static int socketCounter = 1;
896+
897+namespace OnlineAccountsUi {
898+
899+class UiProxyPrivate: public QObject
900+{
901+ Q_OBJECT
902+ Q_DECLARE_PUBLIC(UiProxy)
903+
904+public:
905+ inline UiProxyPrivate(UiProxy *pluginProxy);
906+ inline ~UiProxyPrivate();
907+
908+ bool setupSocket();
909+ bool init();
910+ void sendOperation(const QVariantMap &data);
911+ void sendRequest(int requestId, Request *request);
912+
913+private Q_SLOTS:
914+ void onNewConnection();
915+ void onDataReady(QByteArray &data);
916+
917+private:
918+ QProcess m_process;
919+ QLocalServer m_server;
920+ QLocalSocket *m_socket;
921+ OnlineAccountsUi::Ipc m_ipc;
922+ int m_nextRequestId;
923+ QMap<int,Request*> m_requests;
924+ QStringList m_handlers;
925+ mutable UiProxy *q_ptr;
926+};
927+
928+} // namespace
929+
930+UiProxyPrivate::UiProxyPrivate(UiProxy *uiProxy):
931+ QObject(uiProxy),
932+ m_socket(0),
933+ m_nextRequestId(0),
934+ q_ptr(uiProxy)
935+{
936+ QObject::connect(&m_server, SIGNAL(newConnection()),
937+ this, SLOT(onNewConnection()));
938+ QObject::connect(&m_ipc, SIGNAL(dataReady(QByteArray &)),
939+ this, SLOT(onDataReady(QByteArray &)));
940+ m_process.setProcessChannelMode(QProcess::ForwardedChannels);
941+}
942+
943+UiProxyPrivate::~UiProxyPrivate()
944+{
945+ if (m_socket) {
946+ m_socket->abort();
947+ delete m_socket;
948+ }
949+ m_server.close();
950+}
951+
952+void UiProxyPrivate::sendOperation(const QVariantMap &data)
953+{
954+ QByteArray ba;
955+ QDataStream stream(&ba, QIODevice::WriteOnly);
956+ stream << data;
957+ m_ipc.write(ba);
958+}
959+
960+void UiProxyPrivate::onNewConnection()
961+{
962+ Q_Q(UiProxy);
963+
964+ QLocalSocket *socket = m_server.nextPendingConnection();
965+ if (Q_UNLIKELY(socket == 0)) return;
966+
967+ if (Q_UNLIKELY(m_socket != 0)) {
968+ qWarning() << "A socket is already active!";
969+ socket->deleteLater();
970+ return;
971+ }
972+
973+ m_socket = socket;
974+ QObject::connect(socket, SIGNAL(disconnected()),
975+ q, SIGNAL(finished()));
976+ m_ipc.setChannels(socket, socket);
977+ m_server.close(); // stop listening
978+
979+ /* Execute any pending requests */
980+ QMapIterator<int, Request*> it(m_requests);
981+ while (it.hasNext()) {
982+ it.next();
983+ sendRequest(it.key(), it.value());
984+ }
985+}
986+
987+void UiProxyPrivate::onDataReady(QByteArray &data)
988+{
989+ Q_Q(UiProxy);
990+
991+ QVariantMap map;
992+ QDataStream stream(&data, QIODevice::ReadOnly);
993+ stream >> map;
994+
995+ DEBUG() << map;
996+
997+ int requestId = map.value(OAU_OPERATION_ID, -1).toInt();
998+ Request *request = m_requests.value(requestId, 0);
999+
1000+ QString code = map.value(OAU_OPERATION_CODE).toString();
1001+ if (code == OAU_OPERATION_CODE_REQUEST_FINISHED) {
1002+ Q_ASSERT(request);
1003+ request->setResult(map.value(OAU_OPERATION_DATA).toMap());
1004+ } else if (code == OAU_OPERATION_CODE_REQUEST_FAILED) {
1005+ Q_ASSERT(request);
1006+ request->fail(map.value(OAU_OPERATION_ERROR_NAME).toString(),
1007+ map.value(OAU_OPERATION_ERROR_MESSAGE).toString());
1008+ } else if (code == OAU_OPERATION_CODE_REGISTER_HANDLER) {
1009+ m_handlers.append(map.value(OAU_OPERATION_HANDLER_ID).toString());
1010+ } else {
1011+ qWarning() << "Invalid operation code: " << code;
1012+ }
1013+}
1014+
1015+bool UiProxyPrivate::setupSocket()
1016+{
1017+ QString runtimeDir =
1018+ QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
1019+ QDir socketDir(runtimeDir + "/online-accounts-ui");
1020+ if (!socketDir.exists()) socketDir.mkpath(".");
1021+
1022+ QString uniqueName = QString("ui-%1").arg(socketCounter++);
1023+
1024+ /* If the file exists, it's a stale file: online-accounts-ui is a single
1025+ * instance process, and the only one creating files in this directory. */
1026+ if (Q_UNLIKELY(socketDir.exists(uniqueName))) {
1027+ socketDir.remove(uniqueName);
1028+ }
1029+
1030+ /* Create the socket and set it into listen mode */
1031+ return m_server.listen(socketDir.filePath(uniqueName));
1032+}
1033+
1034+bool UiProxyPrivate::init()
1035+{
1036+ if (Q_UNLIKELY(!setupSocket())) return false;
1037+
1038+ QStringList arguments;
1039+ /* the first argument is required to be the desktop file */
1040+ arguments.append("--desktop_file_hint=/usr/share/applications/online-accounts-ui.desktop");
1041+ arguments.append("--socket");
1042+ arguments.append(m_server.fullServerName());
1043+
1044+ m_process.start("/usr/bin/online-accounts-ui", arguments);
1045+ return m_process.waitForStarted();
1046+}
1047+
1048+void UiProxyPrivate::sendRequest(int requestId, Request *request)
1049+{
1050+ QVariantMap operation;
1051+ operation.insert(OAU_OPERATION_CODE, OAU_OPERATION_CODE_PROCESS);
1052+ operation.insert(OAU_OPERATION_ID, requestId);
1053+ operation.insert(OAU_OPERATION_DATA, request->parameters());
1054+ operation.insert(OAU_OPERATION_INTERFACE, request->interface());
1055+ operation.insert(OAU_OPERATION_CLIENT_PROFILE,
1056+ request->clientApparmorProfile());
1057+ sendOperation(operation);
1058+}
1059+
1060+UiProxy::UiProxy(QObject *parent):
1061+ QObject(parent),
1062+ d_ptr(new UiProxyPrivate(this))
1063+{
1064+}
1065+
1066+UiProxy::~UiProxy()
1067+{
1068+}
1069+
1070+bool UiProxy::init()
1071+{
1072+ Q_D(UiProxy);
1073+ return d->init();
1074+}
1075+
1076+void UiProxy::handleRequest(Request *request)
1077+{
1078+ Q_D(UiProxy);
1079+
1080+ int requestId = d->m_nextRequestId++;
1081+ d->m_requests.insert(requestId, request);
1082+ request->setInProgress(true);
1083+
1084+ if (d->m_socket && d->m_socket->isValid()) {
1085+ d->sendRequest(requestId, request);
1086+ }
1087+}
1088+
1089+bool UiProxy::hasHandlerFor(const QVariantMap &parameters)
1090+{
1091+ Q_D(UiProxy);
1092+
1093+ /* Find if there's any handlers expecting to handle the SignOnUi
1094+ * request having "parameters" as parameters.
1095+ * This is simply done by matching on the X-RequestHandler key (aka
1096+ * matchKey()), if present. We expect that account plugins add that field
1097+ * to their AuthSession requests which they want to handle themselves.
1098+ */
1099+ DEBUG() << parameters;
1100+ if (!parameters.contains(SSOUI_KEY_CLIENT_DATA)) return false;
1101+ QVariant variant = parameters[SSOUI_KEY_CLIENT_DATA];
1102+ QVariantMap clientData = variant.toMap();
1103+ QString matchId = clientData.value(OAU_REQUEST_MATCH_KEY).toString();
1104+ if (matchId.isEmpty()) return false;
1105+
1106+ return d->m_handlers.contains(matchId);
1107+}
1108+
1109+#include "ui-proxy.moc"
1110
1111=== added file 'online-accounts-service/ui-proxy.h'
1112--- online-accounts-service/ui-proxy.h 1970-01-01 00:00:00 +0000
1113+++ online-accounts-service/ui-proxy.h 2014-08-13 14:43:55 +0000
1114@@ -0,0 +1,54 @@
1115+/*
1116+ * Copyright (C) 2014 Canonical Ltd.
1117+ *
1118+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
1119+ *
1120+ * This file is part of online-accounts-ui
1121+ *
1122+ * This program is free software: you can redistribute it and/or modify it
1123+ * under the terms of the GNU General Public License version 3, as published
1124+ * by the Free Software Foundation.
1125+ *
1126+ * This program is distributed in the hope that it will be useful, but
1127+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1128+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1129+ * PURPOSE. See the GNU General Public License for more details.
1130+ *
1131+ * You should have received a copy of the GNU General Public License along
1132+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1133+ */
1134+
1135+#ifndef OAU_UI_PROXY_H
1136+#define OAU_UI_PROXY_H
1137+
1138+#include <QObject>
1139+#include <QVariantMap>
1140+
1141+namespace OnlineAccountsUi {
1142+
1143+class Request;
1144+
1145+class UiProxyPrivate;
1146+class UiProxy: public QObject
1147+{
1148+ Q_OBJECT
1149+
1150+public:
1151+ explicit UiProxy(QObject *parent = 0);
1152+ ~UiProxy();
1153+
1154+ bool init();
1155+ void handleRequest(Request *request);
1156+ bool hasHandlerFor(const QVariantMap &parameters);
1157+
1158+Q_SIGNALS:
1159+ void finished();
1160+
1161+private:
1162+ UiProxyPrivate *d_ptr;
1163+ Q_DECLARE_PRIVATE(UiProxy)
1164+};
1165+
1166+} // namespace
1167+
1168+#endif // OAU_UI_PROXY_H
1169
1170=== renamed directory 'src' => 'online-accounts-ui'
1171=== modified file 'online-accounts-ui/browser-request.cpp'
1172--- src/browser-request.cpp 2014-06-10 14:48:22 +0000
1173+++ online-accounts-ui/browser-request.cpp 2014-08-13 14:43:55 +0000
1174@@ -102,6 +102,7 @@
1175
1176 BrowserRequestPrivate::~BrowserRequestPrivate()
1177 {
1178+ DEBUG();
1179 closeView();
1180 delete m_dialog;
1181 }
1182@@ -179,6 +180,7 @@
1183 m_dialog->accept();
1184 }
1185 } else {
1186+ DEBUG();
1187 onFinished();
1188 }
1189 }
1190@@ -267,6 +269,7 @@
1191 {
1192 Q_Q(BrowserRequest);
1193
1194+ DEBUG();
1195 if (q->hasHandler()) {
1196 q->handler()->setRequest(0);
1197 } else if (m_dialog) {
1198@@ -274,11 +277,11 @@
1199 }
1200 }
1201
1202-BrowserRequest::BrowserRequest(const QDBusConnection &connection,
1203- const QDBusMessage &message,
1204+BrowserRequest::BrowserRequest(int id,
1205+ const QString &clientProfile,
1206 const QVariantMap &parameters,
1207 QObject *parent):
1208- Request(connection, message, parameters, parent),
1209+ Request(id, clientProfile, parameters, parent),
1210 d_ptr(new BrowserRequestPrivate(this))
1211 {
1212 }
1213@@ -287,12 +290,6 @@
1214 {
1215 }
1216
1217-void BrowserRequest::removeIdentityData(quint32 id)
1218-{
1219- QDir rootDir(BrowserRequestPrivate::rootDirForIdentity(id));
1220- rootDir.removeRecursively();
1221-}
1222-
1223 void BrowserRequest::start()
1224 {
1225 Q_D(BrowserRequest);
1226
1227=== modified file 'online-accounts-ui/browser-request.h'
1228--- src/browser-request.h 2014-04-29 14:34:44 +0000
1229+++ online-accounts-ui/browser-request.h 2014-08-13 14:43:55 +0000
1230@@ -34,14 +34,12 @@
1231 Q_OBJECT
1232
1233 public:
1234- explicit BrowserRequest(const QDBusConnection &connection,
1235- const QDBusMessage &message,
1236+ explicit BrowserRequest(int id,
1237+ const QString &clientProfile,
1238 const QVariantMap &parameters,
1239 QObject *parent = 0);
1240 ~BrowserRequest();
1241
1242- static void removeIdentityData(quint32 id);
1243-
1244 // reimplemented virtual methods
1245 void start();
1246
1247
1248=== added file 'online-accounts-ui/ipc.cpp'
1249--- online-accounts-ui/ipc.cpp 1970-01-01 00:00:00 +0000
1250+++ online-accounts-ui/ipc.cpp 2014-08-13 14:43:55 +0000
1251@@ -0,0 +1,184 @@
1252+/*
1253+ * Copyright (C) 2014 Canonical Ltd.
1254+ *
1255+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
1256+ *
1257+ * This file is part of online-accounts-ui
1258+ *
1259+ * This program is free software: you can redistribute it and/or modify it
1260+ * under the terms of the GNU General Public License version 3, as published
1261+ * by the Free Software Foundation.
1262+ *
1263+ * This program is distributed in the hope that it will be useful, but
1264+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1265+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1266+ * PURPOSE. See the GNU General Public License for more details.
1267+ *
1268+ * You should have received a copy of the GNU General Public License along
1269+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1270+ */
1271+
1272+#include "ipc.h"
1273+
1274+#include <QByteArray>
1275+#include <QFile>
1276+#include <QIODevice>
1277+#include <QSocketNotifier>
1278+
1279+using namespace OnlineAccountsUi;
1280+
1281+static const QByteArray welcomeMessage = "OAUinitIPC";
1282+
1283+namespace OnlineAccountsUi {
1284+
1285+class IpcPrivate: public QObject
1286+{
1287+ Q_OBJECT
1288+ Q_DECLARE_PUBLIC(Ipc)
1289+
1290+public:
1291+ inline IpcPrivate(Ipc *ipc);
1292+ ~IpcPrivate() {};
1293+
1294+ void setChannels(QIODevice *readChannel, QIODevice *writeChannel);
1295+
1296+private Q_SLOTS:
1297+ void onReadyRead();
1298+
1299+private:
1300+ bool waitWelcomeMessage();
1301+
1302+private:
1303+ QIODevice *m_readChannel;
1304+ QIODevice *m_writeChannel;
1305+ int m_expectedLength;
1306+ bool m_gotWelcomeMessage;
1307+ QByteArray m_readBuffer;
1308+ mutable Ipc *q_ptr;
1309+};
1310+
1311+}; // namespace
1312+
1313+IpcPrivate::IpcPrivate(Ipc *ipc):
1314+ QObject(ipc),
1315+ m_readChannel(0),
1316+ m_writeChannel(0),
1317+ m_expectedLength(0),
1318+ m_gotWelcomeMessage(false),
1319+ q_ptr(ipc)
1320+{
1321+}
1322+
1323+void IpcPrivate::setChannels(QIODevice *readChannel, QIODevice *writeChannel)
1324+{
1325+ m_readChannel = readChannel;
1326+ m_writeChannel = writeChannel;
1327+ QObject::connect(m_readChannel, SIGNAL(readyRead()),
1328+ this, SLOT(onReadyRead()));
1329+ /* QFile need special handling */
1330+ QFile *file = qobject_cast<QFile*>(m_readChannel);
1331+ if (file != 0) {
1332+ QSocketNotifier *notifier = new QSocketNotifier(file->handle(),
1333+ QSocketNotifier::Read,
1334+ this);
1335+ QObject::connect(notifier, SIGNAL(activated(int)),
1336+ this, SLOT(onReadyRead()));
1337+ } else {
1338+ /* If the read channel is not a QFile, it means it's not the standard
1339+ * input, therefore we won't have the need to wait for the welcome
1340+ * message. */
1341+ m_gotWelcomeMessage = true;
1342+ }
1343+ onReadyRead();
1344+
1345+ file = qobject_cast<QFile*>(m_writeChannel);
1346+ if (file != 0) {
1347+ m_writeChannel->write(welcomeMessage);
1348+ }
1349+}
1350+
1351+void IpcPrivate::onReadyRead()
1352+{
1353+ Q_Q(Ipc);
1354+
1355+ while (true) {
1356+ if (m_expectedLength == 0) {
1357+ /* We are beginning a new read */
1358+
1359+ /* skip all noise */
1360+ if (!waitWelcomeMessage()) break;
1361+
1362+ int length;
1363+ int bytesRead = m_readChannel->read((char *)&length,
1364+ sizeof(length));
1365+ if (bytesRead < int(sizeof(length))) break;
1366+ m_expectedLength = length;
1367+ m_readBuffer.clear();
1368+ }
1369+
1370+ int neededBytes = m_expectedLength - m_readBuffer.length();
1371+ QByteArray buffer = m_readChannel->read(neededBytes);
1372+ m_readBuffer += buffer;
1373+ if (buffer.length() < neededBytes) break;
1374+ if (m_readBuffer.length() == m_expectedLength) {
1375+ Q_EMIT q->dataReady(m_readBuffer);
1376+ m_expectedLength = 0;
1377+ }
1378+ }
1379+}
1380+
1381+bool IpcPrivate::waitWelcomeMessage()
1382+{
1383+ if (m_gotWelcomeMessage) return true;
1384+
1385+ /* All Qt applications on the Nexus 4 write some dust to stdout when
1386+ * starting. So, skip all input until a well-defined welcome message is
1387+ * found */
1388+
1389+ QByteArray buffer;
1390+ int startCheckIndex = 0;
1391+ do {
1392+ buffer = m_readChannel->peek(40);
1393+ int found = buffer.indexOf(welcomeMessage, startCheckIndex);
1394+ int skip = (found >= 0) ? found : buffer.length() - welcomeMessage.length();
1395+ if (found >= 0) {
1396+ buffer = m_readChannel->read(skip + welcomeMessage.length());
1397+ m_gotWelcomeMessage = true;
1398+ return true;
1399+ }
1400+ if (skip > 0) {
1401+ buffer = m_readChannel->read(skip);
1402+ } else {
1403+ buffer.clear();
1404+ }
1405+ } while (!buffer.isEmpty());
1406+
1407+ return false;
1408+}
1409+
1410+Ipc::Ipc(QObject *parent):
1411+ QObject(parent),
1412+ d_ptr(new IpcPrivate(this))
1413+{
1414+}
1415+
1416+Ipc::~Ipc()
1417+{
1418+}
1419+
1420+void Ipc::setChannels(QIODevice *readChannel, QIODevice *writeChannel)
1421+{
1422+ Q_D(Ipc);
1423+ d->setChannels(readChannel, writeChannel);
1424+}
1425+
1426+void Ipc::write(const QByteArray &data)
1427+{
1428+ Q_D(Ipc);
1429+ int length = data.count();
1430+ d->m_writeChannel->write((char *)&length, sizeof(length));
1431+ d->m_writeChannel->write(data);
1432+ d->m_writeChannel->waitForBytesWritten(-1);
1433+}
1434+
1435+#include "ipc.moc"
1436
1437=== added file 'online-accounts-ui/ipc.h'
1438--- online-accounts-ui/ipc.h 1970-01-01 00:00:00 +0000
1439+++ online-accounts-ui/ipc.h 2014-08-13 14:43:55 +0000
1440@@ -0,0 +1,67 @@
1441+/*
1442+ * Copyright (C) 2014 Canonical Ltd.
1443+ *
1444+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
1445+ *
1446+ * This file is part of online-accounts-ui
1447+ *
1448+ * This program is free software: you can redistribute it and/or modify it
1449+ * under the terms of the GNU General Public License version 3, as published
1450+ * by the Free Software Foundation.
1451+ *
1452+ * This program is distributed in the hope that it will be useful, but
1453+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1454+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1455+ * PURPOSE. See the GNU General Public License for more details.
1456+ *
1457+ * You should have received a copy of the GNU General Public License along
1458+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1459+ */
1460+
1461+#ifndef OAU_IPC_H
1462+#define OAU_IPC_H
1463+
1464+#include <QObject>
1465+
1466+class QByteArray;
1467+class QIODevice;
1468+
1469+#define OAU_OPERATION_CODE "code"
1470+#define OAU_OPERATION_CODE_PROCESS "process"
1471+#define OAU_OPERATION_CODE_REGISTER_HANDLER "newHandler"
1472+#define OAU_OPERATION_CODE_REQUEST_FINISHED "finished"
1473+#define OAU_OPERATION_CODE_REQUEST_FAILED "failed"
1474+#define OAU_OPERATION_ID "id"
1475+#define OAU_OPERATION_DATA "data"
1476+#define OAU_OPERATION_INTERFACE "interface"
1477+#define OAU_OPERATION_CLIENT_PROFILE "profile"
1478+#define OAU_OPERATION_ERROR_NAME "errname"
1479+#define OAU_OPERATION_ERROR_MESSAGE "errmsg"
1480+#define OAU_OPERATION_HANDLER_ID "handlerId"
1481+#define OAU_REQUEST_MATCH_KEY "X-RequestHandler"
1482+
1483+namespace OnlineAccountsUi {
1484+
1485+class IpcPrivate;
1486+class Ipc: public QObject
1487+{
1488+ Q_OBJECT
1489+
1490+public:
1491+ Ipc(QObject *parent = 0);
1492+ ~Ipc();
1493+
1494+ void setChannels(QIODevice *readChannel, QIODevice *writeChannel);
1495+ void write(const QByteArray &data);
1496+
1497+Q_SIGNALS:
1498+ void dataReady(QByteArray &data);
1499+
1500+private:
1501+ IpcPrivate *d_ptr;
1502+ Q_DECLARE_PRIVATE(Ipc)
1503+};
1504+
1505+}; // namespace
1506+
1507+#endif // OAU_IPC_H
1508
1509=== modified file 'online-accounts-ui/main.cpp'
1510--- src/main.cpp 2014-04-29 12:11:55 +0000
1511+++ online-accounts-ui/main.cpp 2014-08-13 14:43:55 +0000
1512@@ -1,5 +1,5 @@
1513 /*
1514- * Copyright (C) 2013 Canonical Ltd.
1515+ * Copyright (C) 2013-2014 Canonical Ltd.
1516 *
1517 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
1518 *
1519@@ -21,14 +21,9 @@
1520 #include "debug.h"
1521 #include "globals.h"
1522 #include "i18n.h"
1523-#include "inactivity-timer.h"
1524-#include "indicator-service.h"
1525-#include "request-manager.h"
1526-#include "service.h"
1527-#include "signonui-service.h"
1528+#include "ui-server.h"
1529
1530 #include <QGuiApplication>
1531-#include <QDBusConnection>
1532 #include <QLibrary>
1533 #include <QProcessEnvironment>
1534
1535@@ -37,7 +32,6 @@
1536 int main(int argc, char **argv)
1537 {
1538 QGuiApplication app(argc, argv);
1539- app.setQuitOnLastWindowClosed(false);
1540
1541 /* The testability driver is only loaded by QApplication but not by
1542 * QGuiApplication. However, QApplication depends on QWidget which would
1543@@ -70,66 +64,22 @@
1544 setLoggingLevel(value);
1545 }
1546
1547- /* default daemonTimeout to 5 seconds */
1548- int daemonTimeout = 5;
1549-
1550- /* override daemonTimeout if OAU_DAEMON_TIMEOUT is set */
1551- if (environment.contains(QLatin1String("OAU_DAEMON_TIMEOUT"))) {
1552- bool isOk;
1553- int value = environment.value(
1554- QLatin1String("OAU_DAEMON_TIMEOUT")).toInt(&isOk);
1555- if (isOk)
1556- daemonTimeout = value;
1557- }
1558-
1559 initTr(I18N_DOMAIN, NULL);
1560
1561- RequestManager *requestManager = new RequestManager();
1562-
1563- Service *service = new Service();
1564- QDBusConnection connection = QDBusConnection::sessionBus();
1565- connection.registerService(OAU_SERVICE_NAME);
1566- connection.registerObject(OAU_OBJECT_PATH, service);
1567-
1568- SignOnUi::Service *signonuiService = new SignOnUi::Service();
1569- connection.registerService(SIGNONUI_SERVICE_NAME);
1570- connection.registerObject(SIGNONUI_OBJECT_PATH, signonuiService,
1571- QDBusConnection::ExportAllContents);
1572-
1573- SignOnUi::IndicatorService *indicatorService =
1574- new SignOnUi::IndicatorService();
1575- connection.registerService(WEBCREDENTIALS_BUS_NAME);
1576- connection.registerObject(WEBCREDENTIALS_OBJECT_PATH,
1577- indicatorService->serviceObject());
1578-
1579-
1580- InactivityTimer *inactivityTimer = 0;
1581- if (daemonTimeout > 0) {
1582- inactivityTimer = new InactivityTimer(daemonTimeout * 1000);
1583- inactivityTimer->watchObject(requestManager);
1584- inactivityTimer->watchObject(indicatorService);
1585- QObject::connect(inactivityTimer, SIGNAL(timeout()),
1586- &app, SLOT(quit()));
1587- }
1588-
1589- int ret = app.exec();
1590-
1591- connection.unregisterService(WEBCREDENTIALS_BUS_NAME);
1592- connection.unregisterObject(WEBCREDENTIALS_OBJECT_PATH);
1593- delete indicatorService;
1594-
1595- connection.unregisterService(SIGNONUI_SERVICE_NAME);
1596- connection.unregisterObject(SIGNONUI_OBJECT_PATH);
1597- delete signonuiService;
1598-
1599- connection.unregisterService(OAU_SERVICE_NAME);
1600- connection.unregisterObject(OAU_OBJECT_PATH);
1601- delete service;
1602-
1603- delete requestManager;
1604-
1605- delete inactivityTimer;
1606-
1607- return ret;
1608+ QStringList arguments = app.arguments();
1609+ int i = arguments.indexOf("--socket");
1610+ if (i < 0 || i + 1 >= arguments.count()) {
1611+ qWarning() << "Missing --socket argument";
1612+ return EXIT_FAILURE;
1613+ }
1614+
1615+ UiServer server(arguments[i + 1]);
1616+ QObject::connect(&server, SIGNAL(finished()),
1617+ &app, SLOT(quit()));
1618+ if (Q_UNLIKELY(!server.init())) {
1619+ qWarning() << "Could not connect to socket";
1620+ return EXIT_FAILURE;
1621+ }
1622+
1623+ return app.exec();
1624 }
1625-
1626
1627=== renamed file 'src/online-accounts-ui.pro' => 'online-accounts-ui/online-accounts-ui-helper.pro'
1628--- src/online-accounts-ui.pro 2014-06-10 14:48:22 +0000
1629+++ online-accounts-ui/online-accounts-ui-helper.pro 2014-08-13 14:43:55 +0000
1630@@ -21,16 +21,10 @@
1631 libsignon-qt5 \
1632 signon-plugins-common
1633
1634-I18N_DOMAIN="ubuntu-system-settings-online-accounts"
1635-SIGNONUI_I18N_DOMAIN="signon-ui"
1636-
1637 DEFINES += \
1638 I18N_DOMAIN=\\\"$${I18N_DOMAIN}\\\" \
1639 SIGNONUI_I18N_DOMAIN=\\\"$${SIGNONUI_I18N_DOMAIN}\\\"
1640
1641-DBUS_ADAPTORS += \
1642- com.ubuntu.OnlineAccountsUi.xml
1643-
1644 DEFINES += \
1645 DEBUG_ENABLED \
1646 OAU_PLUGIN_DIR=\\\"$${ONLINE_ACCOUNTS_PLUGIN_DIR}/\\\" \
1647@@ -44,19 +38,15 @@
1648 debug.cpp \
1649 dialog.cpp \
1650 i18n.cpp \
1651- inactivity-timer.cpp \
1652- indicator-service.cpp \
1653+ ipc.cpp \
1654 main.cpp \
1655 notification.cpp \
1656 panel-request.cpp \
1657 provider-request.cpp \
1658- reauthenticator.cpp \
1659 request.cpp \
1660 request-handler.cpp \
1661- request-manager.cpp \
1662- service.cpp \
1663 signonui-request.cpp \
1664- signonui-service.cpp
1665+ ui-server.cpp
1666
1667 HEADERS += \
1668 access-model.h \
1669@@ -66,18 +56,14 @@
1670 debug.h \
1671 dialog.h \
1672 i18n.h \
1673- inactivity-timer.h \
1674- indicator-service.h \
1675+ ipc.h \
1676 notification.h \
1677 panel-request.h \
1678 provider-request.h \
1679- reauthenticator.h \
1680 request.h \
1681 request-handler.h \
1682- request-manager.h \
1683- service.h \
1684 signonui-request.h \
1685- signonui-service.h
1686+ ui-server.h
1687
1688 QML_SOURCES = \
1689 qml/AccountCreationPage.qml \
1690@@ -103,17 +89,8 @@
1691 $${RESOURCES}
1692
1693 QMAKE_SUBSTITUTES += \
1694- com.ubuntu.OnlineAccountsUi.service.in \
1695 online-accounts-ui.desktop.in
1696
1697-DBUS_ADAPTORS += \
1698- com.canonical.indicators.webcredentials.xml
1699-
1700-service.path = $${INSTALL_PREFIX}/share/dbus-1/services
1701-service.files = \
1702- com.ubuntu.OnlineAccountsUi.service
1703-INSTALLS += service
1704-
1705 desktop.path = $${INSTALL_PREFIX}/share/applications
1706 desktop.files += online-accounts-ui.desktop
1707 INSTALLS += desktop
1708
1709=== renamed file 'src/src.pro' => 'online-accounts-ui/online-accounts-ui.pro'
1710--- src/src.pro 2014-04-29 12:11:55 +0000
1711+++ online-accounts-ui/online-accounts-ui.pro 2014-08-13 14:43:55 +0000
1712@@ -1,4 +1,4 @@
1713 TEMPLATE = subdirs
1714 SUBDIRS = \
1715 module \
1716- online-accounts-ui.pro
1717+ online-accounts-ui-helper.pro
1718
1719=== modified file 'online-accounts-ui/panel-request.cpp'
1720--- src/panel-request.cpp 2014-05-30 08:09:02 +0000
1721+++ online-accounts-ui/panel-request.cpp 2014-08-13 14:43:55 +0000
1722@@ -65,7 +65,9 @@
1723 PanelRequestPrivate::~PanelRequestPrivate()
1724 {
1725 DEBUG() << "view:" << m_view;
1726+ /* TODO Uncomment this once QTBUG-40766 is resolved:
1727 delete m_view;
1728+ */
1729 }
1730
1731 void PanelRequestPrivate::start()
1732@@ -103,18 +105,15 @@
1733
1734 if (!visible) {
1735 q->setResult(QVariantMap());
1736- /* FIXME HACK: remove when window reparenting is implemented */
1737- if (QGuiApplication::platformName().startsWith("ubuntu")) {
1738- QDesktopServices::openUrl(QUrl("application:///ubuntu-system-settings.desktop"));
1739- }
1740 }
1741 }
1742
1743-PanelRequest::PanelRequest(const QDBusConnection &connection,
1744- const QDBusMessage &message,
1745+PanelRequest::PanelRequest(const QString &interface,
1746+ int id,
1747+ const QString &clientProfile,
1748 const QVariantMap &parameters,
1749 QObject *parent):
1750- Request(connection, message, parameters, parent),
1751+ Request(interface, id, clientProfile, parameters, parent),
1752 d_ptr(new PanelRequestPrivate(this))
1753 {
1754 }
1755
1756=== modified file 'online-accounts-ui/panel-request.h'
1757--- src/panel-request.h 2014-05-30 08:09:02 +0000
1758+++ online-accounts-ui/panel-request.h 2014-08-13 14:43:55 +0000
1759@@ -1,5 +1,5 @@
1760 /*
1761- * Copyright (C) 2013 Canonical Ltd.
1762+ * Copyright (C) 2013-2014 Canonical Ltd.
1763 *
1764 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
1765 *
1766@@ -31,8 +31,9 @@
1767 Q_OBJECT
1768
1769 public:
1770- explicit PanelRequest(const QDBusConnection &connection,
1771- const QDBusMessage &message,
1772+ explicit PanelRequest(const QString &interface,
1773+ int id,
1774+ const QString &clientProfile,
1775 const QVariantMap &parameters,
1776 QObject *parent = 0);
1777 ~PanelRequest();
1778
1779=== modified file 'online-accounts-ui/provider-request.cpp'
1780--- src/provider-request.cpp 2014-05-30 09:28:43 +0000
1781+++ online-accounts-ui/provider-request.cpp 2014-08-13 14:43:55 +0000
1782@@ -164,11 +164,12 @@
1783 m_view->close();
1784 }
1785
1786-ProviderRequest::ProviderRequest(const QDBusConnection &connection,
1787- const QDBusMessage &message,
1788+ProviderRequest::ProviderRequest(const QString &interface,
1789+ int id,
1790+ const QString &clientProfile,
1791 const QVariantMap &parameters,
1792 QObject *parent):
1793- Request(connection, message, parameters, parent),
1794+ Request(interface, id, clientProfile, parameters, parent),
1795 d_ptr(new ProviderRequestPrivate(this))
1796 {
1797 }
1798
1799=== modified file 'online-accounts-ui/provider-request.h'
1800--- src/provider-request.h 2014-02-03 10:27:39 +0000
1801+++ online-accounts-ui/provider-request.h 2014-08-13 14:43:55 +0000
1802@@ -31,8 +31,9 @@
1803 Q_OBJECT
1804
1805 public:
1806- explicit ProviderRequest(const QDBusConnection &connection,
1807- const QDBusMessage &message,
1808+ explicit ProviderRequest(const QString &interface,
1809+ int id,
1810+ const QString &clientProfile,
1811 const QVariantMap &parameters,
1812 QObject *parent = 0);
1813 ~ProviderRequest();
1814
1815=== modified file 'online-accounts-ui/request-handler.cpp'
1816--- src/request-handler.cpp 2014-04-29 14:34:44 +0000
1817+++ online-accounts-ui/request-handler.cpp 2014-08-13 14:43:55 +0000
1818@@ -21,6 +21,7 @@
1819 #include "request-handler.h"
1820
1821 #include "debug.h"
1822+#include "ui-server.h"
1823
1824 #include <SignOn/uisessiondata_priv.h>
1825 #include <QDBusArgument>
1826@@ -66,6 +67,11 @@
1827 d_ptr(new RequestHandlerPrivate(this))
1828 {
1829 allRequestHandlers.append(this);
1830+
1831+ OnlineAccountsUi::UiServer *server =
1832+ OnlineAccountsUi::UiServer::instance();
1833+ Q_ASSERT(server);
1834+ server->registerHandler(this);
1835 }
1836
1837 RequestHandler::~RequestHandler()
1838
1839=== modified file 'online-accounts-ui/request.cpp'
1840--- src/request.cpp 2014-05-30 08:09:02 +0000
1841+++ online-accounts-ui/request.cpp 2014-08-13 14:43:55 +0000
1842@@ -51,8 +51,9 @@
1843 Q_DECLARE_PUBLIC(Request)
1844
1845 public:
1846- RequestPrivate(const QDBusConnection &connection,
1847- const QDBusMessage &message,
1848+ RequestPrivate(const QString &interface,
1849+ int id,
1850+ const QString &clientProfile,
1851 const QVariantMap &parameters,
1852 Request *request);
1853 ~RequestPrivate();
1854@@ -63,33 +64,36 @@
1855
1856 private:
1857 void setWindow(QWindow *window);
1858- QString findClientApparmorProfile();
1859
1860 private:
1861 mutable Request *q_ptr;
1862- QDBusConnection m_connection;
1863- QDBusMessage m_message;
1864+ QString m_interface;
1865+ int m_id;
1866 QVariantMap m_parameters;
1867 QString m_clientApparmorProfile;
1868 bool m_inProgress;
1869 QPointer<QWindow> m_window;
1870+ QString m_errorName;
1871+ QString m_errorMessage;
1872+ QVariantMap m_result;
1873 };
1874
1875 } // namespace
1876
1877-RequestPrivate::RequestPrivate(const QDBusConnection &connection,
1878- const QDBusMessage &message,
1879+RequestPrivate::RequestPrivate(const QString &interface,
1880+ int id,
1881+ const QString &clientProfile,
1882 const QVariantMap &parameters,
1883 Request *request):
1884 QObject(request),
1885 q_ptr(request),
1886- m_connection(connection),
1887- m_message(message),
1888+ m_interface(interface),
1889+ m_id(id),
1890 m_parameters(parameters),
1891+ m_clientApparmorProfile(clientProfile),
1892 m_inProgress(false),
1893 m_window(0)
1894 {
1895- m_clientApparmorProfile = findClientApparmorProfile();
1896 }
1897
1898 RequestPrivate::~RequestPrivate()
1899@@ -113,41 +117,14 @@
1900 window->show();
1901 }
1902
1903-QString RequestPrivate::findClientApparmorProfile()
1904-{
1905- QString uniqueConnectionId = m_message.service();
1906- /* This is mainly for unit tests: real messages on the session bus always
1907- * have a service name. */
1908- if (uniqueConnectionId.isEmpty()) return QString();
1909-
1910- QString appId;
1911-
1912- QDBusMessage msg =
1913- QDBusMessage::createMethodCall("org.freedesktop.DBus",
1914- "/org/freedesktop/DBus",
1915- "org.freedesktop.DBus",
1916- "GetConnectionAppArmorSecurityContext");
1917- QVariantList args;
1918- args << uniqueConnectionId;
1919- msg.setArguments(args);
1920- QDBusMessage reply = QDBusConnection::sessionBus().call(msg, QDBus::Block);
1921- if (reply.type() == QDBusMessage::ReplyMessage) {
1922- appId = reply.arguments().value(0, QString()).toString();
1923- DEBUG() << "App ID:" << appId;
1924- } else {
1925- qWarning() << "Error getting app ID:" << reply.errorName() <<
1926- reply.errorMessage();
1927- }
1928- return appId;
1929-}
1930-
1931 /* Some unit tests might need to provide a different implementation for the
1932 * Request::newRequest() factory method; for this reason, we allow the method
1933 * to be excluded from compilation.
1934 */
1935 #ifndef NO_REQUEST_FACTORY
1936-Request *Request::newRequest(const QDBusConnection &connection,
1937- const QDBusMessage &message,
1938+Request *Request::newRequest(const QString &interface,
1939+ int id,
1940+ const QString &clientProfile,
1941 const QVariantMap &parameters,
1942 QObject *parent)
1943 {
1944@@ -155,26 +132,29 @@
1945 * different subclasses for handling them, and in this method we examine
1946 * the @parameters argument to figure out which subclass is the most apt to
1947 * handle the request. */
1948- if (message.interface() == OAU_INTERFACE) {
1949+ if (interface == OAU_INTERFACE) {
1950 if (parameters.contains(OAU_KEY_PROVIDER)) {
1951- return new ProviderRequest(connection, message, parameters, parent);
1952+ return new ProviderRequest(interface, id, clientProfile,
1953+ parameters, parent);
1954 } else {
1955- return new PanelRequest(connection, message, parameters, parent);
1956+ return new PanelRequest(interface, id, clientProfile,
1957+ parameters, parent);
1958 }
1959 } else {
1960- Q_ASSERT(message.interface() == SIGNONUI_INTERFACE);
1961- return SignOnUi::Request::newRequest(connection, message,
1962+ Q_ASSERT(interface == SIGNONUI_INTERFACE);
1963+ return SignOnUi::Request::newRequest(id, clientProfile,
1964 parameters, parent);
1965 }
1966 }
1967 #endif
1968
1969-Request::Request(const QDBusConnection &connection,
1970- const QDBusMessage &message,
1971+Request::Request(const QString &interface,
1972+ int id,
1973+ const QString &clientProfile,
1974 const QVariantMap &parameters,
1975 QObject *parent):
1976 QObject(parent),
1977- d_ptr(new RequestPrivate(connection, message, parameters, this))
1978+ d_ptr(new RequestPrivate(interface, id, clientProfile, parameters, this))
1979 {
1980 allRequests.append(this);
1981 }
1982@@ -195,6 +175,18 @@
1983 return 0;
1984 }
1985
1986+QString Request::interface() const
1987+{
1988+ Q_D(const Request);
1989+ return d->m_interface;
1990+}
1991+
1992+int Request::id() const
1993+{
1994+ Q_D(const Request);
1995+ return d->m_id;
1996+}
1997+
1998 void Request::setWindow(QWindow *window)
1999 {
2000 Q_D(Request);
2001@@ -231,6 +223,24 @@
2002 return d->m_window;
2003 }
2004
2005+QVariantMap Request::result() const
2006+{
2007+ Q_D(const Request);
2008+ return d->m_result;
2009+}
2010+
2011+QString Request::errorName() const
2012+{
2013+ Q_D(const Request);
2014+ return d->m_errorName;
2015+}
2016+
2017+QString Request::errorMessage() const
2018+{
2019+ Q_D(const Request);
2020+ return d->m_errorMessage;
2021+}
2022+
2023 void Request::start()
2024 {
2025 Q_D(Request);
2026@@ -249,8 +259,11 @@
2027 void Request::fail(const QString &name, const QString &message)
2028 {
2029 Q_D(Request);
2030- QDBusMessage reply = d->m_message.createErrorReply(name, message);
2031- d->m_connection.send(reply);
2032+
2033+ DEBUG() << name << message;
2034+
2035+ d->m_errorName = name;
2036+ d->m_errorMessage = message;
2037
2038 Q_EMIT completed();
2039 }
2040@@ -268,8 +281,8 @@
2041 {
2042 Q_D(Request);
2043 if (d->m_inProgress) {
2044- QDBusMessage reply = d->m_message.createReply(result);
2045- d->m_connection.send(reply);
2046+ DEBUG() << result;
2047+ d->m_result = result;
2048
2049 Q_EMIT completed();
2050 d->m_inProgress = false;
2051
2052=== modified file 'online-accounts-ui/request.h'
2053--- src/request.h 2014-05-30 08:09:02 +0000
2054+++ online-accounts-ui/request.h 2014-08-13 14:43:55 +0000
2055@@ -21,8 +21,6 @@
2056 #ifndef OAU_REQUEST_H
2057 #define OAU_REQUEST_H
2058
2059-#include <QDBusConnection>
2060-#include <QDBusMessage>
2061 #include <QObject>
2062 #include <QVariantMap>
2063 #include <QWindow>
2064@@ -35,20 +33,27 @@
2065 Q_OBJECT
2066
2067 public:
2068- static Request *newRequest(const QDBusConnection &connection,
2069- const QDBusMessage &message,
2070+ static Request *newRequest(const QString &interface,
2071+ int id,
2072+ const QString &clientProfile,
2073 const QVariantMap &parameters,
2074 QObject *parent = 0);
2075 ~Request();
2076
2077 static Request *find(const QVariantMap &match);
2078
2079+ QString interface() const;
2080+ int id() const;
2081 WId windowId() const;
2082 bool isInProgress() const;
2083 const QVariantMap &parameters() const;
2084 QString clientApparmorProfile() const;
2085 QWindow *window() const;
2086
2087+ QVariantMap result() const;
2088+ QString errorName() const;
2089+ QString errorMessage() const;
2090+
2091 public Q_SLOTS:
2092 virtual void start();
2093 void cancel();
2094@@ -57,8 +62,9 @@
2095 void completed();
2096
2097 protected:
2098- explicit Request(const QDBusConnection &connection,
2099- const QDBusMessage &message,
2100+ explicit Request(const QString &interface,
2101+ int id,
2102+ const QString &clientProfile,
2103 const QVariantMap &parameters,
2104 QObject *parent = 0);
2105 virtual void setWindow(QWindow *window);
2106
2107=== modified file 'online-accounts-ui/signonui-request.cpp'
2108--- src/signonui-request.cpp 2014-06-12 11:53:00 +0000
2109+++ online-accounts-ui/signonui-request.cpp 2014-08-13 14:43:55 +0000
2110@@ -192,13 +192,13 @@
2111 }
2112
2113 #ifndef NO_REQUEST_FACTORY
2114-Request *Request::newRequest(const QDBusConnection &connection,
2115- const QDBusMessage &message,
2116+Request *Request::newRequest(int id,
2117+ const QString &clientProfile,
2118 const QVariantMap &parameters,
2119 QObject *parent)
2120 {
2121 if (parameters.contains(SSOUI_KEY_OPENURL)) {
2122- return new SignOnUi::BrowserRequest(connection, message,
2123+ return new SignOnUi::BrowserRequest(id, clientProfile,
2124 parameters, parent);
2125 } else {
2126 return 0; // TODO new DialogRequest(connection, message, parameters, parent);
2127@@ -206,11 +206,12 @@
2128 }
2129 #endif
2130
2131-Request::Request(const QDBusConnection &connection,
2132- const QDBusMessage &message,
2133+Request::Request(int id,
2134+ const QString &clientProfile,
2135 const QVariantMap &parameters,
2136 QObject *parent):
2137- OnlineAccountsUi::Request(connection, message, parameters, parent),
2138+ OnlineAccountsUi::Request(SIGNONUI_INTERFACE, id, clientProfile,
2139+ parameters, parent),
2140 d_ptr(new RequestPrivate(this))
2141 {
2142 }
2143@@ -219,14 +220,14 @@
2144 {
2145 }
2146
2147-QString Request::id(const QVariantMap &parameters)
2148+QString Request::ssoId(const QVariantMap &parameters)
2149 {
2150 return parameters[SSOUI_KEY_REQUESTID].toString();
2151 }
2152
2153-QString Request::id() const
2154+QString Request::ssoId() const
2155 {
2156- return Request::id(parameters());
2157+ return Request::ssoId(parameters());
2158 }
2159
2160 void Request::setWindow(QWindow *window)
2161
2162=== modified file 'online-accounts-ui/signonui-request.h'
2163--- src/signonui-request.h 2014-04-29 14:34:44 +0000
2164+++ online-accounts-ui/signonui-request.h 2014-08-13 14:43:55 +0000
2165@@ -33,14 +33,14 @@
2166 Q_OBJECT
2167
2168 public:
2169- static Request *newRequest(const QDBusConnection &connection,
2170- const QDBusMessage &message,
2171+ static Request *newRequest(int id,
2172+ const QString &clientProfile,
2173 const QVariantMap &parameters,
2174 QObject *parent = 0);
2175 ~Request();
2176
2177- static QString id(const QVariantMap &parameters);
2178- QString id() const;
2179+ static QString ssoId(const QVariantMap &parameters);
2180+ QString ssoId() const;
2181
2182 uint identity() const;
2183 QString method() const;
2184@@ -53,8 +53,8 @@
2185 bool hasHandler() const { return handler() != 0; }
2186
2187 protected:
2188- explicit Request(const QDBusConnection &connection,
2189- const QDBusMessage &message,
2190+ explicit Request(int id,
2191+ const QString &clientProfile,
2192 const QVariantMap &parameters,
2193 QObject *parent = 0);
2194 virtual void setWindow(QWindow *window) Q_DECL_OVERRIDE;
2195
2196=== added file 'online-accounts-ui/ui-server.cpp'
2197--- online-accounts-ui/ui-server.cpp 1970-01-01 00:00:00 +0000
2198+++ online-accounts-ui/ui-server.cpp 2014-08-13 14:43:55 +0000
2199@@ -0,0 +1,199 @@
2200+/*
2201+ * Copyright (C) 2014 Canonical Ltd.
2202+ *
2203+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
2204+ *
2205+ * This file is part of online-accounts-ui
2206+ *
2207+ * This program is free software: you can redistribute it and/or modify it
2208+ * under the terms of the GNU General Public License version 3, as published
2209+ * by the Free Software Foundation.
2210+ *
2211+ * This program is distributed in the hope that it will be useful, but
2212+ * WITHOUT ANY WARRANTY; without even the implied warranties of
2213+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
2214+ * PURPOSE. See the GNU General Public License for more details.
2215+ *
2216+ * You should have received a copy of the GNU General Public License along
2217+ * with this program. If not, see <http://www.gnu.org/licenses/>.
2218+ */
2219+
2220+#include "debug.h"
2221+#include "ipc.h"
2222+#include "request.h"
2223+#include "request-handler.h"
2224+#include "signonui-request.h"
2225+#include "ui-server.h"
2226+
2227+#include <QLocalSocket>
2228+#include <QtQml>
2229+#include <SignOn/uisessiondata_priv.h>
2230+
2231+using namespace OnlineAccountsUi;
2232+
2233+static UiServer *m_instance = 0;
2234+
2235+namespace OnlineAccountsUi {
2236+
2237+class UiServerPrivate: public QObject
2238+{
2239+ Q_OBJECT
2240+ Q_DECLARE_PUBLIC(UiServer)
2241+
2242+public:
2243+ inline UiServerPrivate(const QString &address, UiServer *pluginServer);
2244+ inline ~UiServerPrivate();
2245+
2246+ bool setupSocket();
2247+ bool init();
2248+ void sendOperation(const QVariantMap &data);
2249+
2250+private Q_SLOTS:
2251+ void onDataReady(QByteArray &data);
2252+ void onRequestCompleted();
2253+
2254+private:
2255+ QLocalSocket m_socket;
2256+ OnlineAccountsUi::Ipc m_ipc;
2257+ mutable UiServer *q_ptr;
2258+};
2259+
2260+} // namespace
2261+
2262+UiServerPrivate::UiServerPrivate(const QString &address,
2263+ UiServer *pluginServer):
2264+ QObject(pluginServer),
2265+ q_ptr(pluginServer)
2266+{
2267+ QObject::connect(&m_ipc, SIGNAL(dataReady(QByteArray &)),
2268+ this, SLOT(onDataReady(QByteArray &)));
2269+ QObject::connect(&m_socket, SIGNAL(disconnected()),
2270+ q_ptr, SIGNAL(finished()));
2271+ m_socket.connectToServer(address);
2272+}
2273+
2274+UiServerPrivate::~UiServerPrivate()
2275+{
2276+ DEBUG();
2277+}
2278+
2279+void UiServerPrivate::sendOperation(const QVariantMap &data)
2280+{
2281+ QByteArray ba;
2282+ QDataStream stream(&ba, QIODevice::WriteOnly);
2283+ stream << data;
2284+ m_ipc.write(ba);
2285+}
2286+
2287+void UiServerPrivate::onDataReady(QByteArray &data)
2288+{
2289+ Q_Q(UiServer);
2290+
2291+ QVariantMap map;
2292+ QDataStream stream(&data, QIODevice::ReadOnly);
2293+ stream >> map;
2294+
2295+ DEBUG() << map;
2296+
2297+ QString code = map.value(OAU_OPERATION_CODE).toString();
2298+ if (code == OAU_OPERATION_CODE_PROCESS) {
2299+ QVariantMap parameters = map[OAU_OPERATION_DATA].toMap();
2300+ Request *request =
2301+ Request::newRequest(map[OAU_OPERATION_INTERFACE].toString(),
2302+ map[OAU_OPERATION_ID].toInt(),
2303+ map[OAU_OPERATION_CLIENT_PROFILE].toString(),
2304+ parameters,
2305+ this);
2306+ QObject::connect(request, SIGNAL(completed()),
2307+ this, SLOT(onRequestCompleted()));
2308+
2309+ /* Check if a RequestHandler has been setup to handle this request. If
2310+ * so, bing the request object to the handler and start the request
2311+ * immediately. */
2312+ SignOnUi::Request *signonRequest =
2313+ qobject_cast<SignOnUi::Request*>(request);
2314+ if (signonRequest) {
2315+ SignOnUi::RequestHandler *handler =
2316+ SignOnUi::RequestHandler::findMatching(parameters);
2317+ if (handler) {
2318+ signonRequest->setHandler(handler);
2319+ }
2320+ }
2321+ request->start();
2322+ } else {
2323+ qWarning() << "Invalid operation code: " << code;
2324+ }
2325+}
2326+
2327+void UiServerPrivate::onRequestCompleted()
2328+{
2329+ Request *request = qobject_cast<Request*>(sender());
2330+ request->disconnect(this);
2331+ request->deleteLater();
2332+
2333+ if (request->errorName().isEmpty()) {
2334+ QVariantMap operation;
2335+ operation.insert(OAU_OPERATION_CODE,
2336+ OAU_OPERATION_CODE_REQUEST_FINISHED);
2337+ operation.insert(OAU_OPERATION_ID, request->id());
2338+ operation.insert(OAU_OPERATION_DATA, request->result());
2339+ operation.insert(OAU_OPERATION_INTERFACE, request->interface());
2340+ sendOperation(operation);
2341+ } else {
2342+ QVariantMap operation;
2343+ operation.insert(OAU_OPERATION_CODE,
2344+ OAU_OPERATION_CODE_REQUEST_FAILED);
2345+ operation.insert(OAU_OPERATION_ID, request->id());
2346+ operation.insert(OAU_OPERATION_INTERFACE, request->interface());
2347+ operation.insert(OAU_OPERATION_ERROR_NAME, request->errorName());
2348+ operation.insert(OAU_OPERATION_ERROR_MESSAGE, request->errorMessage());
2349+ sendOperation(operation);
2350+ }
2351+}
2352+
2353+bool UiServerPrivate::init()
2354+{
2355+ if (Q_UNLIKELY(!m_socket.waitForConnected())) return false;
2356+
2357+ m_ipc.setChannels(&m_socket, &m_socket);
2358+ return true;
2359+}
2360+
2361+UiServer::UiServer(const QString &address, QObject *parent):
2362+ QObject(parent),
2363+ d_ptr(new UiServerPrivate(address, this))
2364+{
2365+ m_instance = this;
2366+
2367+ qmlRegisterType<SignOnUi::RequestHandler>("Ubuntu.OnlineAccounts.Plugin",
2368+ 1, 0, "RequestHandler");
2369+}
2370+
2371+UiServer::~UiServer()
2372+{
2373+ m_instance = 0;
2374+}
2375+
2376+UiServer *UiServer::instance()
2377+{
2378+ return m_instance;
2379+}
2380+
2381+bool UiServer::init()
2382+{
2383+ Q_D(UiServer);
2384+ return d->init();
2385+}
2386+
2387+void UiServer::registerHandler(SignOnUi::RequestHandler *handler)
2388+{
2389+ Q_D(UiServer);
2390+
2391+ QVariantMap operation;
2392+ operation.insert(OAU_OPERATION_CODE,
2393+ OAU_OPERATION_CODE_REGISTER_HANDLER);
2394+ operation.insert(OAU_OPERATION_HANDLER_ID, handler->matchId());
2395+ d->sendOperation(operation);
2396+}
2397+
2398+#include "ui-server.moc"
2399
2400=== added file 'online-accounts-ui/ui-server.h'
2401--- online-accounts-ui/ui-server.h 1970-01-01 00:00:00 +0000
2402+++ online-accounts-ui/ui-server.h 2014-08-13 14:43:55 +0000
2403@@ -0,0 +1,57 @@
2404+/*
2405+ * Copyright (C) 2014 Canonical Ltd.
2406+ *
2407+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
2408+ *
2409+ * This file is part of online-accounts-ui
2410+ *
2411+ * This program is free software: you can redistribute it and/or modify it
2412+ * under the terms of the GNU General Public License version 3, as published
2413+ * by the Free Software Foundation.
2414+ *
2415+ * This program is distributed in the hope that it will be useful, but
2416+ * WITHOUT ANY WARRANTY; without even the implied warranties of
2417+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
2418+ * PURPOSE. See the GNU General Public License for more details.
2419+ *
2420+ * You should have received a copy of the GNU General Public License along
2421+ * with this program. If not, see <http://www.gnu.org/licenses/>.
2422+ */
2423+
2424+#ifndef OAU_UI_SERVER_H
2425+#define OAU_UI_SERVER_H
2426+
2427+#include <QObject>
2428+#include <QVariantMap>
2429+
2430+namespace SignOnUi {
2431+class RequestHandler;
2432+}
2433+
2434+namespace OnlineAccountsUi {
2435+
2436+class UiServerPrivate;
2437+class UiServer: public QObject
2438+{
2439+ Q_OBJECT
2440+
2441+public:
2442+ explicit UiServer(const QString &address, QObject *parent = 0);
2443+ ~UiServer();
2444+
2445+ static UiServer *instance();
2446+
2447+ bool init();
2448+ void registerHandler(SignOnUi::RequestHandler *handler);
2449+
2450+Q_SIGNALS:
2451+ void finished();
2452+
2453+private:
2454+ UiServerPrivate *d_ptr;
2455+ Q_DECLARE_PRIVATE(UiServer)
2456+};
2457+
2458+} // namespace
2459+
2460+#endif // OAU_UI_SERVER_H
2461
2462=== modified file 'tests/client/tst_client.cpp'
2463--- tests/client/tst_client.cpp 2014-03-19 12:14:14 +0000
2464+++ tests/client/tst_client.cpp 2014-08-13 14:43:55 +0000
2465@@ -20,7 +20,7 @@
2466 * <http://www.gnu.org/licenses/>.
2467 */
2468
2469-#include "src/globals.h"
2470+#include "online-accounts-ui/globals.h"
2471
2472 #include <OnlineAccountsClient/Setup>
2473 #include <QDBusConnection>
2474
2475=== modified file 'tests/client/tst_qml_client.cpp'
2476--- tests/client/tst_qml_client.cpp 2014-03-19 12:14:14 +0000
2477+++ tests/client/tst_qml_client.cpp 2014-08-13 14:43:55 +0000
2478@@ -20,7 +20,7 @@
2479 * <http://www.gnu.org/licenses/>.
2480 */
2481
2482-#include "src/globals.h"
2483+#include "online-accounts-ui/globals.h"
2484
2485 #include <QDBusConnection>
2486 #include <QDebug>
2487
2488=== added directory 'tests/online-accounts-service'
2489=== added file 'tests/online-accounts-service/online-accounts-service.pro'
2490--- tests/online-accounts-service/online-accounts-service.pro 1970-01-01 00:00:00 +0000
2491+++ tests/online-accounts-service/online-accounts-service.pro 2014-08-13 14:43:55 +0000
2492@@ -0,0 +1,4 @@
2493+TEMPLATE = subdirs
2494+SUBDIRS = \
2495+ tst_inactivity_timer.pro \
2496+ tst_service.pro
2497
2498=== renamed file 'tests/online-accounts-ui/tst_inactivity_timer.cpp' => 'tests/online-accounts-service/tst_inactivity_timer.cpp'
2499=== renamed file 'tests/online-accounts-ui/tst_inactivity_timer.pro' => 'tests/online-accounts-service/tst_inactivity_timer.pro'
2500--- tests/online-accounts-ui/tst_inactivity_timer.pro 2014-03-07 07:44:07 +0000
2501+++ tests/online-accounts-service/tst_inactivity_timer.pro 2014-08-13 14:43:55 +0000
2502@@ -9,15 +9,19 @@
2503 core \
2504 testlib
2505
2506+ONLINE_ACCOUNTS_SERVICE_DIR = $${TOP_SRC_DIR}/online-accounts-service
2507+COMMON_SRC_DIR = $${TOP_SRC_DIR}/online-accounts-ui
2508+
2509 SOURCES += \
2510- $${TOP_SRC_DIR}/src/inactivity-timer.cpp \
2511+ $${ONLINE_ACCOUNTS_SERVICE_DIR}/inactivity-timer.cpp \
2512 tst_inactivity_timer.cpp
2513
2514 HEADERS += \
2515- $${TOP_SRC_DIR}/src/inactivity-timer.h
2516+ $${ONLINE_ACCOUNTS_SERVICE_DIR}/inactivity-timer.h
2517
2518 INCLUDEPATH += \
2519- $${TOP_SRC_DIR}/src
2520+ $${COMMON_SRC_DIR} \
2521+ $${ONLINE_ACCOUNTS_SERVICE_DIR}
2522
2523 check.commands = "xvfb-run -s '-screen 0 640x480x24' -a ./$${TARGET}"
2524 check.depends = $${TARGET}
2525
2526=== renamed file 'tests/online-accounts-ui/tst_service.cpp' => 'tests/online-accounts-service/tst_service.cpp'
2527--- tests/online-accounts-ui/tst_service.cpp 2014-04-29 12:11:55 +0000
2528+++ tests/online-accounts-service/tst_service.cpp 2014-08-13 14:43:55 +0000
2529@@ -22,7 +22,7 @@
2530 #include "request.h"
2531 #include "request-manager.h"
2532 #include "service.h"
2533-#include "window-watcher.h"
2534+#include "ui-proxy.h"
2535
2536 #include <QDBusArgument>
2537 #include <QDBusConnection>
2538@@ -38,58 +38,12 @@
2539
2540 using namespace OnlineAccountsUi;
2541
2542-static const QString keyTimeout(QStringLiteral("timeout"));
2543-static const QString keyFail(QStringLiteral("fail"));
2544-
2545 #define P2P_SOCKET "unix:path=/tmp/tst_service_%1"
2546 #define TEST_SERVICE_NAME \
2547 QStringLiteral("com.ubuntu.OnlineAccountsUi.Test")
2548 #define TEST_OBJECT_PATH QStringLiteral("/")
2549
2550-class TestRequest: public Request
2551-{
2552- Q_OBJECT
2553-
2554-public:
2555- TestRequest(const QDBusConnection &connection,
2556- const QDBusMessage &message,
2557- const QVariantMap &parameters,
2558- QObject *parent = 0):
2559- Request(connection, message, parameters, parent)
2560- {
2561- m_timer.setSingleShot(true);
2562- m_timer.setInterval(parameters.value(keyTimeout).toInt());
2563- QObject::connect(&m_timer, SIGNAL(timeout()),
2564- this, SLOT(onTimeout()));
2565- }
2566-
2567- void start() Q_DECL_OVERRIDE {
2568- Request::start();
2569- QWindow *window = new QWindow;
2570- setWindow(window);
2571- m_timer.start();
2572- }
2573-
2574-private Q_SLOTS:
2575- void onTimeout() {
2576- if (parameters().contains(keyFail)) {
2577- fail(parameters().value(keyFail).toString(), "Request failed");
2578- } else {
2579- setResult(parameters());
2580- }
2581- }
2582-
2583-private:
2584- QTimer m_timer;
2585-};
2586-
2587-Request *Request::newRequest(const QDBusConnection &connection,
2588- const QDBusMessage &message,
2589- const QVariantMap &parameters,
2590- QObject *parent)
2591-{
2592- return new TestRequest(connection, message, parameters, parent);
2593-}
2594+QList<UiProxyPrivate *> m_uiProxies;
2595
2596 class RequestReply: public QDBusPendingCallWatcher
2597 {
2598@@ -107,6 +61,7 @@
2599 bool isError() const { return m_isError; }
2600 QVariantMap reply() const { return m_reply; }
2601 QString errorName() const { return m_errorName; }
2602+ QString errorMessage() const { return m_errorMessage; }
2603
2604 private Q_SLOTS:
2605 void onFinished() {
2606@@ -114,6 +69,7 @@
2607 if (reply.isError()) {
2608 m_isError = true;
2609 m_errorName = reply.error().name();
2610+ m_errorMessage = reply.error().message();
2611 } else {
2612 m_reply = qdbus_cast<QVariantMap>(reply.argumentAt(0).
2613 value<QDBusArgument>());
2614@@ -128,6 +84,7 @@
2615 bool m_isError;
2616 QVariantMap m_reply;
2617 QString m_errorName;
2618+ QString m_errorMessage;
2619 };
2620
2621 class ServiceTest: public QObject
2622@@ -154,8 +111,6 @@
2623 void testResults();
2624 void testFailure();
2625 void testIdle();
2626- void testWindow();
2627- void testWindowTransiency();
2628
2629 protected Q_SLOTS:
2630 void onNewConnection(const QDBusConnection &connection);
2631@@ -166,6 +121,73 @@
2632 QDBusConnection m_connection;
2633 };
2634
2635+/* Mocking UiProxy { */
2636+namespace OnlineAccountsUi {
2637+
2638+class UiProxyPrivate: public QObject
2639+{
2640+ Q_OBJECT
2641+ Q_DECLARE_PUBLIC(UiProxy)
2642+
2643+public:
2644+ UiProxyPrivate(UiProxy *uiProxy):
2645+ QObject(uiProxy),
2646+ m_initCount(0),
2647+ m_initReply(true),
2648+ q_ptr(uiProxy)
2649+ {
2650+ }
2651+ ~UiProxyPrivate() {};
2652+
2653+ void emitFinished() { Q_EMIT q_ptr->finished(); }
2654+
2655+Q_SIGNALS:
2656+ void handleRequestCalled();
2657+
2658+public:
2659+ int m_initCount;
2660+ bool m_initReply;
2661+ QList<Request*> m_requests;
2662+ QVariantMap m_expectedHasHandlerFor;
2663+ mutable UiProxy *q_ptr;
2664+};
2665+
2666+} // namespace
2667+
2668+UiProxy::UiProxy(QObject *parent):
2669+ QObject(parent),
2670+ d_ptr(new UiProxyPrivate(this))
2671+{
2672+ m_uiProxies.append(d_ptr);
2673+}
2674+
2675+UiProxy::~UiProxy()
2676+{
2677+ m_uiProxies.removeOne(d_ptr);
2678+}
2679+
2680+bool UiProxy::init()
2681+{
2682+ Q_D(UiProxy);
2683+ d->m_initCount++;
2684+ return d->m_initReply;
2685+}
2686+
2687+void UiProxy::handleRequest(Request *request)
2688+{
2689+ Q_D(UiProxy);
2690+ d->m_requests.append(request);
2691+ Q_EMIT d->handleRequestCalled();
2692+}
2693+
2694+bool UiProxy::hasHandlerFor(const QVariantMap &parameters)
2695+{
2696+ Q_D(UiProxy);
2697+ return parameters == d->m_expectedHasHandlerFor;
2698+}
2699+
2700+/* } mocking UiProxy */
2701+
2702 ServiceTest::ServiceTest():
2703 QObject(0),
2704 m_connection(QStringLiteral("uninitialized"))
2705@@ -205,30 +227,60 @@
2706 void ServiceTest::testResults()
2707 {
2708 QVariantMap parameters;
2709- parameters.insert(keyTimeout, 10);
2710 parameters.insert("hello", QString("world"));
2711 RequestReply *call = sendRequest(parameters);
2712 QSignalSpy callFinished(call, SIGNAL(finished()));
2713
2714+ QTRY_COMPARE(m_uiProxies.count(), 1);
2715+
2716+ UiProxyPrivate *proxy = m_uiProxies[0];
2717+ QCOMPARE(proxy->m_initCount, 1);
2718+ QCOMPARE(proxy->m_requests.count(), 1);
2719+
2720+ Request *request = proxy->m_requests.last();
2721+ QCOMPARE(request->parameters(), parameters);
2722+
2723+ request->setInProgress(true);
2724+ request->setResult(parameters);
2725+
2726 QVERIFY(callFinished.wait());
2727 QCOMPARE(call->isError(), false);
2728 QCOMPARE(call->reply(), parameters);
2729 delete call;
2730+
2731+ proxy->emitFinished();
2732+ QTRY_COMPARE(m_uiProxies.count(), 0);
2733 }
2734
2735 void ServiceTest::testFailure()
2736 {
2737+ QVariantMap parameters;
2738+ parameters.insert("hi", "there");
2739+ RequestReply *call = sendRequest(parameters);
2740+ QSignalSpy callFinished(call, SIGNAL(finished()));
2741+
2742+ QTRY_COMPARE(m_uiProxies.count(), 1);
2743+
2744+ UiProxyPrivate *proxy = m_uiProxies[0];
2745+ QCOMPARE(proxy->m_initCount, 1);
2746+ QCOMPARE(proxy->m_requests.count(), 1);
2747+
2748+ Request *request = proxy->m_requests.last();
2749+ QCOMPARE(request->parameters(), parameters);
2750+
2751+ request->setInProgress(true);
2752 QString errorName("com.ubuntu.OnlineAccountsUi.BadLuck");
2753- QVariantMap parameters;
2754- parameters.insert(keyTimeout, 10);
2755- parameters.insert("fail", errorName);
2756- RequestReply *call = sendRequest(parameters);
2757- QSignalSpy callFinished(call, SIGNAL(finished()));
2758+ QString errorMessage("really unlucky");
2759+ request->fail(errorName, errorMessage);
2760
2761 QVERIFY(callFinished.wait());
2762 QCOMPARE(call->isError(), true);
2763 QCOMPARE(call->errorName(), errorName);
2764+ QCOMPARE(call->errorMessage(), errorMessage);
2765 delete call;
2766+
2767+ proxy->emitFinished();
2768+ QTRY_COMPARE(m_uiProxies.count(), 0);
2769 }
2770
2771 void ServiceTest::testIdle()
2772@@ -238,65 +290,37 @@
2773 QSignalSpy isIdleChanged(&m_requestManager, SIGNAL(isIdleChanged()));
2774
2775 QVariantMap parameters;
2776- parameters.insert(keyTimeout, 10);
2777+ parameters.insert("time", "out");
2778 RequestReply *call = sendRequest(parameters);
2779 QSignalSpy callFinished(call, SIGNAL(finished()));
2780
2781 QVERIFY(isIdleChanged.wait());
2782 QCOMPARE(m_requestManager.isIdle(), false);
2783-
2784- /* the request will terminate after 10 milliseconds, so expect the service
2785+ isIdleChanged.clear();
2786+
2787+ QTRY_COMPARE(m_uiProxies.count(), 1);
2788+
2789+ UiProxyPrivate *proxy = m_uiProxies[0];
2790+ QCOMPARE(proxy->m_initCount, 1);
2791+ QCOMPARE(proxy->m_requests.count(), 1);
2792+
2793+ Request *request = proxy->m_requests.last();
2794+ QCOMPARE(request->parameters(), parameters);
2795+
2796+ request->setInProgress(true);
2797+ request->setResult(parameters);
2798+
2799+ /* the request will terminate, so expect the service
2800 * to be idle again */
2801- QVERIFY(isIdleChanged.wait());
2802+ QTRY_COMPARE(isIdleChanged.count(), 1);
2803 QCOMPARE(m_requestManager.isIdle(), true);
2804
2805 QVERIFY(callFinished.wait());
2806 QCOMPARE(call->isError(), false);
2807 delete call;
2808-}
2809-
2810-void ServiceTest::testWindow()
2811-{
2812- QVariantMap parameters;
2813- parameters.insert(keyTimeout, 10);
2814- RequestReply *call = sendRequest(parameters);
2815- QSignalSpy callFinished(call, SIGNAL(finished()));
2816- QSignalSpy windowShown(WindowWatcher::instance(),
2817- SIGNAL(windowShown(QObject*)));
2818-
2819- QVERIFY(windowShown.wait());
2820- QWindow *window =
2821- qobject_cast<QWindow*>(windowShown.at(0).at(0).value<QObject*>());
2822- QVERIFY(window->property("transientParent").isNull());
2823- QVERIFY(callFinished.wait());
2824- QCOMPARE(call->isError(), false);
2825- delete call;
2826-
2827- QCOMPARE(windowShown.count(), 1);
2828-}
2829-
2830-void ServiceTest::testWindowTransiency()
2831-{
2832- QVariantMap parameters;
2833- parameters.insert(keyTimeout, 10);
2834- parameters.insert(OAU_KEY_WINDOW_ID, 371);
2835- RequestReply *call = sendRequest(parameters);
2836- QSignalSpy callFinished(call, SIGNAL(finished()));
2837- QSignalSpy windowShown(WindowWatcher::instance(),
2838- SIGNAL(windowShown(QObject*)));
2839-
2840- QVERIFY(windowShown.wait());
2841- QWindow *window =
2842- qobject_cast<QWindow*>(windowShown.at(0).at(0).value<QObject*>());
2843- QObject *transientParentObject =
2844- window->property("transientParent").value<QObject*>();
2845- QWindow *transientParent = qobject_cast<QWindow*>(transientParentObject);
2846- QCOMPARE(transientParent->property("winId").toUInt(), uint(371));
2847- QVERIFY(callFinished.wait());
2848- QCOMPARE(call->isError(), false);
2849- delete call;
2850-
2851- QCOMPARE(windowShown.count(), 1);
2852+
2853+ proxy->emitFinished();
2854+ QTRY_COMPARE(m_uiProxies.count(), 0);
2855 }
2856
2857 QTEST_MAIN(ServiceTest);
2858
2859=== renamed file 'tests/online-accounts-ui/tst_service.pro' => 'tests/online-accounts-service/tst_service.pro'
2860--- tests/online-accounts-ui/tst_service.pro 2014-04-29 12:11:55 +0000
2861+++ tests/online-accounts-service/tst_service.pro 2014-08-13 14:43:55 +0000
2862@@ -13,23 +13,26 @@
2863 DEFINES += \
2864 NO_REQUEST_FACTORY
2865
2866+ONLINE_ACCOUNTS_SERVICE_DIR = $${TOP_SRC_DIR}/online-accounts-service
2867+COMMON_SRC_DIR = $${TOP_SRC_DIR}/online-accounts-ui
2868+
2869 SOURCES += \
2870- $${TOP_BUILD_DIR}/src/onlineaccountsui_adaptor.cpp \
2871- $${TOP_SRC_DIR}/src/request.cpp \
2872- $${TOP_SRC_DIR}/src/request-manager.cpp \
2873- $${TOP_SRC_DIR}/src/service.cpp \
2874- mock/qwindow.cpp \
2875+ $${TOP_BUILD_DIR}/online-accounts-service/onlineaccountsui_adaptor.cpp \
2876+ $${ONLINE_ACCOUNTS_SERVICE_DIR}/request.cpp \
2877+ $${ONLINE_ACCOUNTS_SERVICE_DIR}/request-manager.cpp \
2878+ $${ONLINE_ACCOUNTS_SERVICE_DIR}/service.cpp \
2879 tst_service.cpp
2880
2881 HEADERS += \
2882- $${TOP_BUILD_DIR}/src/onlineaccountsui_adaptor.h \
2883- $${TOP_SRC_DIR}/src/request.h \
2884- $${TOP_SRC_DIR}/src/request-manager.h \
2885- $${TOP_SRC_DIR}/src/service.h \
2886- window-watcher.h
2887+ $${TOP_BUILD_DIR}/online-accounts-service/onlineaccountsui_adaptor.h \
2888+ $${ONLINE_ACCOUNTS_SERVICE_DIR}/request.h \
2889+ $${ONLINE_ACCOUNTS_SERVICE_DIR}/request-manager.h \
2890+ $${ONLINE_ACCOUNTS_SERVICE_DIR}/service.h \
2891+ $${ONLINE_ACCOUNTS_SERVICE_DIR}/ui-proxy.h \
2892
2893 INCLUDEPATH += \
2894- $${TOP_SRC_DIR}/src
2895+ $${ONLINE_ACCOUNTS_SERVICE_DIR} \
2896+ $${COMMON_SRC_DIR}
2897
2898 check.commands = "xvfb-run -s '-screen 0 640x480x24' -a dbus-test-runner -t ./$${TARGET}"
2899 check.depends = $${TARGET}
2900
2901=== modified file 'tests/online-accounts-ui/mock/request-mock.cpp'
2902--- tests/online-accounts-ui/mock/request-mock.cpp 2014-06-09 13:57:32 +0000
2903+++ tests/online-accounts-ui/mock/request-mock.cpp 2014-08-13 14:43:55 +0000
2904@@ -25,30 +25,33 @@
2905
2906 using namespace OnlineAccountsUi;
2907
2908-RequestPrivate::RequestPrivate(const QDBusConnection &connection,
2909- const QDBusMessage &message,
2910+RequestPrivate::RequestPrivate(const QString &interface,
2911+ int id,
2912+ const QString &clientProfile,
2913 const QVariantMap &parameters,
2914 Request *request):
2915 QObject(request),
2916 q_ptr(request),
2917 m_parameters(parameters),
2918+ m_clientApparmorProfile(clientProfile),
2919 m_window(0),
2920 m_inProgress(false)
2921 {
2922- Q_UNUSED(connection);
2923- Q_UNUSED(message);
2924+ Q_UNUSED(interface);
2925+ Q_UNUSED(id);
2926 }
2927
2928 RequestPrivate::~RequestPrivate()
2929 {
2930 }
2931
2932-Request::Request(const QDBusConnection &connection,
2933- const QDBusMessage &message,
2934+Request::Request(const QString &interface,
2935+ int id,
2936+ const QString &clientProfile,
2937 const QVariantMap &parameters,
2938 QObject *parent):
2939 QObject(parent),
2940- d_ptr(new RequestPrivate(connection, message, parameters, this))
2941+ d_ptr(new RequestPrivate(interface, id, clientProfile, parameters, this))
2942 {
2943 }
2944
2945
2946=== modified file 'tests/online-accounts-ui/mock/request-mock.h'
2947--- tests/online-accounts-ui/mock/request-mock.h 2014-06-09 13:57:32 +0000
2948+++ tests/online-accounts-ui/mock/request-mock.h 2014-08-13 14:43:55 +0000
2949@@ -35,17 +35,14 @@
2950 Q_DECLARE_PUBLIC(Request)
2951
2952 public:
2953- RequestPrivate(const QDBusConnection &connection,
2954- const QDBusMessage &message,
2955+ RequestPrivate(const QString &interface,
2956+ int id,
2957+ const QString &clientProfile,
2958 const QVariantMap &parameters,
2959 Request *request);
2960 ~RequestPrivate();
2961 static RequestPrivate *mocked(Request *r) { return r->d_ptr; }
2962
2963- void setClientApparmorProfile(const QString &profile) {
2964- m_clientApparmorProfile = profile;
2965- }
2966-
2967 Q_SIGNALS:
2968 void setWindowCalled(QWindow *);
2969 void failCalled(const QString &name, const QString &message);
2970
2971=== added file 'tests/online-accounts-ui/mock/ui-server-mock.cpp'
2972--- tests/online-accounts-ui/mock/ui-server-mock.cpp 1970-01-01 00:00:00 +0000
2973+++ tests/online-accounts-ui/mock/ui-server-mock.cpp 2014-08-13 14:43:55 +0000
2974@@ -0,0 +1,68 @@
2975+/*
2976+ * Copyright (C) 2014 Canonical Ltd.
2977+ *
2978+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
2979+ *
2980+ * This file is part of online-accounts-ui
2981+ *
2982+ * This program is free software: you can redistribute it and/or modify it
2983+ * under the terms of the GNU General Public License version 3, as published
2984+ * by the Free Software Foundation.
2985+ *
2986+ * This program is distributed in the hope that it will be useful, but
2987+ * WITHOUT ANY WARRANTY; without even the implied warranties of
2988+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
2989+ * PURPOSE. See the GNU General Public License for more details.
2990+ *
2991+ * You should have received a copy of the GNU General Public License along
2992+ * with this program. If not, see <http://www.gnu.org/licenses/>.
2993+ */
2994+
2995+#include "ui-server-mock.h"
2996+
2997+#include <QDebug>
2998+
2999+using namespace OnlineAccountsUi;
3000+
3001+static UiServer *m_instance = 0;
3002+
3003+UiServerPrivate::UiServerPrivate(const QString &address,
3004+ UiServer *server):
3005+ QObject(server),
3006+ q_ptr(server),
3007+ m_address(address)
3008+{
3009+}
3010+
3011+UiServerPrivate::~UiServerPrivate()
3012+{
3013+}
3014+
3015+UiServer::UiServer(const QString &address,
3016+ QObject *parent):
3017+ QObject(parent),
3018+ d_ptr(new UiServerPrivate(address, this))
3019+{
3020+ m_instance = this;
3021+}
3022+
3023+UiServer::~UiServer()
3024+{
3025+ m_instance = 0;
3026+}
3027+
3028+UiServer *UiServer::instance()
3029+{
3030+ return m_instance;
3031+}
3032+
3033+bool UiServer::init()
3034+{
3035+ return true;
3036+}
3037+
3038+void UiServer::registerHandler(SignOnUi::RequestHandler *handler)
3039+{
3040+ Q_D(UiServer);
3041+ Q_EMIT d->registerHandlerCalled(handler);
3042+}
3043
3044=== added file 'tests/online-accounts-ui/mock/ui-server-mock.h'
3045--- tests/online-accounts-ui/mock/ui-server-mock.h 1970-01-01 00:00:00 +0000
3046+++ tests/online-accounts-ui/mock/ui-server-mock.h 2014-08-13 14:43:55 +0000
3047@@ -0,0 +1,53 @@
3048+/*
3049+ * Copyright (C) 2014 Canonical Ltd.
3050+ *
3051+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
3052+ *
3053+ * This file is part of online-accounts-ui
3054+ *
3055+ * This program is free software: you can redistribute it and/or modify it
3056+ * under the terms of the GNU General Public License version 3, as published
3057+ * by the Free Software Foundation.
3058+ *
3059+ * This program is distributed in the hope that it will be useful, but
3060+ * WITHOUT ANY WARRANTY; without even the implied warranties of
3061+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
3062+ * PURPOSE. See the GNU General Public License for more details.
3063+ *
3064+ * You should have received a copy of the GNU General Public License along
3065+ * with this program. If not, see <http://www.gnu.org/licenses/>.
3066+ */
3067+
3068+#ifndef MOCK_UI_SERVER_H
3069+#define MOCK_UI_SERVER_H
3070+
3071+#include "ui-server.h"
3072+
3073+#include <QObject>
3074+#include <QString>
3075+
3076+namespace OnlineAccountsUi {
3077+
3078+class UiServerPrivate: public QObject
3079+{
3080+ Q_OBJECT
3081+ Q_DECLARE_PUBLIC(UiServer)
3082+
3083+public:
3084+ UiServerPrivate(const QString &address, UiServer *pluginServer);
3085+ ~UiServerPrivate();
3086+ static UiServerPrivate *mocked(UiServer *r) { return r->d_ptr; }
3087+
3088+ void emitFinished() { Q_EMIT q_ptr->finished(); }
3089+
3090+Q_SIGNALS:
3091+ void registerHandlerCalled(SignOnUi::RequestHandler *handler);
3092+
3093+public:
3094+ mutable UiServer *q_ptr;
3095+ QString m_address;
3096+};
3097+
3098+} // namespace
3099+
3100+#endif // MOCK_UI_SERVER_H
3101
3102=== added file 'tests/online-accounts-ui/online-accounts-ui.pri'
3103--- tests/online-accounts-ui/online-accounts-ui.pri 1970-01-01 00:00:00 +0000
3104+++ tests/online-accounts-ui/online-accounts-ui.pri 2014-08-13 14:43:55 +0000
3105@@ -0,0 +1,18 @@
3106+include(../../common-project-config.pri)
3107+
3108+CONFIG += \
3109+ debug
3110+
3111+QT += \
3112+ core \
3113+ testlib
3114+
3115+DEFINES += \
3116+ DEBUG_ENABLED
3117+
3118+ONLINE_ACCOUNTS_UI_DIR = $${TOP_SRC_DIR}/online-accounts-ui
3119+COMMON_SRC_DIR = $${TOP_SRC_DIR}/online-accounts-ui
3120+
3121+INCLUDEPATH += \
3122+ $${ONLINE_ACCOUNTS_SERVICE_DIR} \
3123+ $${COMMON_SRC_DIR}
3124
3125=== modified file 'tests/online-accounts-ui/online-accounts-ui.pro'
3126--- tests/online-accounts-ui/online-accounts-ui.pro 2014-06-09 13:57:32 +0000
3127+++ tests/online-accounts-ui/online-accounts-ui.pro 2014-08-13 14:43:55 +0000
3128@@ -3,7 +3,5 @@
3129 qml \
3130 tst_access_model.pro \
3131 tst_application_manager.pro \
3132- tst_inactivity_timer.pro \
3133 tst_notification.pro \
3134- tst_service.pro \
3135 tst_signonui_request.pro
3136
3137=== modified file 'tests/online-accounts-ui/qml/Source/qmldir'
3138--- tests/online-accounts-ui/qml/Source/qmldir 2013-09-18 08:35:43 +0000
3139+++ tests/online-accounts-ui/qml/Source/qmldir 2014-08-13 14:43:55 +0000
3140@@ -1,2 +1,2 @@
3141 module Source
3142-AccountCreationPage 1.0 ../../../../src/qml/AccountCreationPage.qml
3143+AccountCreationPage 1.0 ../../../../online-accounts-ui/qml/AccountCreationPage.qml
3144
3145=== modified file 'tests/online-accounts-ui/tst_access_model.pro'
3146--- tests/online-accounts-ui/tst_access_model.pro 2014-02-03 10:27:39 +0000
3147+++ tests/online-accounts-ui/tst_access_model.pro 2014-08-13 14:43:55 +0000
3148@@ -1,37 +1,30 @@
3149-include(../../common-project-config.pri)
3150+include(online-accounts-ui.pri)
3151
3152 TARGET = tst_access_model
3153
3154 CONFIG += \
3155- debug \
3156 link_pkgconfig
3157
3158 QT += \
3159- core \
3160 dbus \
3161- qml \
3162- testlib
3163+ qml
3164
3165 PKGCONFIG += \
3166 accounts-qt5
3167
3168 DEFINES += \
3169- DEBUG_ENABLED \
3170 TEST_DATA_DIR=\\\"$${PWD}/data\\\"
3171
3172 SOURCES += \
3173- $${TOP_SRC_DIR}/src/access-model.cpp \
3174- $${TOP_SRC_DIR}/src/account-manager.cpp \
3175- $${TOP_SRC_DIR}/src/debug.cpp \
3176+ $${ONLINE_ACCOUNTS_UI_DIR}/access-model.cpp \
3177+ $${ONLINE_ACCOUNTS_UI_DIR}/account-manager.cpp \
3178+ $${ONLINE_ACCOUNTS_UI_DIR}/debug.cpp \
3179 tst_access_model.cpp
3180
3181 HEADERS += \
3182- $${TOP_SRC_DIR}/src/access-model.h \
3183- $${TOP_SRC_DIR}/src/account-manager.h \
3184- $${TOP_SRC_DIR}/src/debug.h
3185-
3186-INCLUDEPATH += \
3187- $${TOP_SRC_DIR}/src
3188+ $${ONLINE_ACCOUNTS_UI_DIR}/access-model.h \
3189+ $${ONLINE_ACCOUNTS_UI_DIR}/account-manager.h \
3190+ $${ONLINE_ACCOUNTS_UI_DIR}/debug.h
3191
3192 check.commands = "xvfb-run -a dbus-test-runner -t ./$${TARGET}"
3193 check.depends = $${TARGET}
3194
3195=== modified file 'tests/online-accounts-ui/tst_application_manager.pro'
3196--- tests/online-accounts-ui/tst_application_manager.pro 2014-05-14 13:31:42 +0000
3197+++ tests/online-accounts-ui/tst_application_manager.pro 2014-08-13 14:43:55 +0000
3198@@ -1,37 +1,30 @@
3199-include(../../common-project-config.pri)
3200+include(online-accounts-ui.pri)
3201
3202 TARGET = tst_application_manager
3203
3204 CONFIG += \
3205- debug \
3206 link_pkgconfig
3207
3208 QT += \
3209- core \
3210 dbus \
3211- qml \
3212- testlib
3213+ qml
3214
3215 PKGCONFIG += \
3216 accounts-qt5
3217
3218 DEFINES += \
3219- DEBUG_ENABLED \
3220 TEST_DATA_DIR=\\\"$${PWD}/data\\\"
3221
3222 SOURCES += \
3223- $${TOP_SRC_DIR}/src/application-manager.cpp \
3224- $${TOP_SRC_DIR}/src/account-manager.cpp \
3225- $${TOP_SRC_DIR}/src/debug.cpp \
3226+ $${ONLINE_ACCOUNTS_UI_DIR}/application-manager.cpp \
3227+ $${ONLINE_ACCOUNTS_UI_DIR}/account-manager.cpp \
3228+ $${ONLINE_ACCOUNTS_UI_DIR}/debug.cpp \
3229 tst_application_manager.cpp
3230
3231 HEADERS += \
3232- $${TOP_SRC_DIR}/src/application-manager.h \
3233- $${TOP_SRC_DIR}/src/account-manager.h \
3234- $${TOP_SRC_DIR}/src/debug.h
3235-
3236-INCLUDEPATH += \
3237- $${TOP_SRC_DIR}/src
3238+ $${ONLINE_ACCOUNTS_UI_DIR}/application-manager.h \
3239+ $${ONLINE_ACCOUNTS_UI_DIR}/account-manager.h \
3240+ $${ONLINE_ACCOUNTS_UI_DIR}/debug.h
3241
3242 check.commands = "xvfb-run -a dbus-test-runner -t ./$${TARGET}"
3243 check.depends = $${TARGET}
3244
3245=== modified file 'tests/online-accounts-ui/tst_notification.pro'
3246--- tests/online-accounts-ui/tst_notification.pro 2014-06-05 13:28:30 +0000
3247+++ tests/online-accounts-ui/tst_notification.pro 2014-08-13 14:43:55 +0000
3248@@ -1,28 +1,20 @@
3249-include(../../common-project-config.pri)
3250+include(online-accounts-ui.pri)
3251
3252 TARGET = tst_notification
3253
3254 CONFIG += \
3255- debug \
3256 link_pkgconfig \
3257 no_keywords
3258
3259-QT += \
3260- core \
3261- testlib
3262-
3263 PKGCONFIG += \
3264 libnotify
3265
3266 SOURCES += \
3267- $${TOP_SRC_DIR}/src/notification.cpp \
3268+ $${COMMON_SRC_DIR}/notification.cpp \
3269 tst_notification.cpp
3270
3271 HEADERS += \
3272- $${TOP_SRC_DIR}/src/notification.h
3273-
3274-INCLUDEPATH += \
3275- $${TOP_SRC_DIR}/src
3276+ $${COMMON_SRC_DIR}/notification.h
3277
3278 check.commands = "xvfb-run -s '-screen 0 640x480x24' -a ./$${TARGET}"
3279 check.depends = $${TARGET}
3280
3281=== modified file 'tests/online-accounts-ui/tst_signonui_request.cpp'
3282--- tests/online-accounts-ui/tst_signonui_request.cpp 2014-06-12 11:53:00 +0000
3283+++ tests/online-accounts-ui/tst_signonui_request.cpp 2014-08-13 14:43:55 +0000
3284@@ -23,6 +23,7 @@
3285 #include "signonui-request.h"
3286 #include "mock/notification-mock.h"
3287 #include "mock/request-mock.h"
3288+#include "mock/ui-server-mock.h"
3289
3290 #include <Accounts/Account>
3291 #include <Accounts/Manager>
3292@@ -42,11 +43,10 @@
3293 Q_OBJECT
3294
3295 public:
3296- TestRequest(const QDBusConnection &connection,
3297- const QDBusMessage &message,
3298+ TestRequest(const QString &clientProfile,
3299 const QVariantMap &parameters,
3300 QObject *parent = 0):
3301- Request(connection, message, parameters, parent)
3302+ Request(0, clientProfile, parameters, parent)
3303 {
3304 }
3305
3306@@ -74,14 +74,13 @@
3307 bool mustCreateAccount(uint credentialsId) { return credentialsId > 10; }
3308
3309 private:
3310- QDBusConnection m_connection;
3311- QDBusMessage m_message;
3312 QTemporaryDir m_accountsDir;
3313+ UiServer m_uiServer;
3314 };
3315
3316 SignonuiRequestTest::SignonuiRequestTest():
3317 QObject(),
3318- m_connection(QStringLiteral("uninitialized"))
3319+ m_uiServer("fake")
3320 {
3321 }
3322
3323@@ -102,7 +101,7 @@
3324 QTest::addColumn<uint>("identity");
3325 QTest::addColumn<QString>("method");
3326 QTest::addColumn<QString>("mechanism");
3327- QTest::addColumn<QString>("id");
3328+ QTest::addColumn<QString>("ssoId");
3329 QTest::addColumn<QVariantMap>("clientData");
3330
3331 QTest::newRow("empty") <<
3332@@ -138,20 +137,20 @@
3333 QFETCH(QVariantMap, parameters);
3334 QFETCH(QString, method);
3335 QFETCH(QString, mechanism);
3336- QFETCH(QString, id);
3337+ QFETCH(QString, ssoId);
3338 QFETCH(QVariantMap, clientData);
3339
3340- TestRequest request(m_connection, m_message, parameters);
3341+ TestRequest request("unconfined", parameters);
3342 QCOMPARE(request.method(), method);
3343 QCOMPARE(request.mechanism(), mechanism);
3344- QCOMPARE(request.id(), id);
3345+ QCOMPARE(request.ssoId(), ssoId);
3346 QCOMPARE(request.clientData(), clientData);
3347 }
3348
3349 void SignonuiRequestTest::testHandler()
3350 {
3351 QVariantMap parameters;
3352- TestRequest request(m_connection, m_message, parameters);
3353+ TestRequest request("unconfined", parameters);
3354 QVERIFY(request.handler() == 0);
3355
3356 SignOnUi::RequestHandler *handler = new SignOnUi::RequestHandler;
3357@@ -263,14 +262,13 @@
3358 parameters.insert(SSOUI_KEY_IDENTITY, credentialsId);
3359 parameters.insert(SSOUI_KEY_METHOD, "funnyMethod");
3360 parameters.insert(SSOUI_KEY_MECHANISM, "funnyMechanism");
3361- TestRequest request(m_connection, m_message, parameters);
3362+ TestRequest request(clientProfile, parameters);
3363 OnlineAccountsUi::RequestPrivate *mockRequest =
3364 OnlineAccountsUi::RequestPrivate::mocked(&request);
3365 QSignalSpy failCalled(mockRequest,
3366 SIGNAL(failCalled(const QString&, const QString&)));
3367 QSignalSpy setResultCalled(mockRequest,
3368 SIGNAL(setResultCalled(const QVariantMap &)));
3369- mockRequest->setClientApparmorProfile(clientProfile);
3370 request.start();
3371
3372 /* Request to show a window; a snap decision should appear instead */
3373
3374=== modified file 'tests/online-accounts-ui/tst_signonui_request.pro'
3375--- tests/online-accounts-ui/tst_signonui_request.pro 2014-06-10 08:07:57 +0000
3376+++ tests/online-accounts-ui/tst_signonui_request.pro 2014-08-13 14:43:55 +0000
3377@@ -1,15 +1,12 @@
3378-include(../../common-project-config.pri)
3379+include(online-accounts-ui.pri)
3380
3381 TARGET = tst_signonui_request
3382
3383 CONFIG += \
3384- debug \
3385 link_pkgconfig
3386
3387 QT += \
3388- core \
3389- dbus \
3390- testlib
3391+ dbus
3392
3393 PKGCONFIG += \
3394 accounts-qt5 \
3395@@ -17,37 +14,35 @@
3396 signon-plugins-common
3397
3398 DEFINES += \
3399- DEBUG_ENABLED \
3400 NO_REQUEST_FACTORY \
3401 TEST_DATA_DIR=\\\"$${PWD}/data\\\"
3402
3403-SRCDIR = $${TOP_SRC_DIR}/src
3404
3405 SOURCES += \
3406- $${SRCDIR}/account-manager.cpp \
3407- $${SRCDIR}/application-manager.cpp \
3408- $${SRCDIR}/debug.cpp \
3409- $${SRCDIR}/request-handler.cpp \
3410- $${SRCDIR}/signonui-request.cpp \
3411+ $${ONLINE_ACCOUNTS_UI_DIR}/account-manager.cpp \
3412+ $${ONLINE_ACCOUNTS_UI_DIR}/application-manager.cpp \
3413+ $${ONLINE_ACCOUNTS_UI_DIR}/debug.cpp \
3414+ $${ONLINE_ACCOUNTS_UI_DIR}/request-handler.cpp \
3415+ $${ONLINE_ACCOUNTS_UI_DIR}/signonui-request.cpp \
3416 mock/notification-mock.cpp \
3417 mock/request-mock.cpp \
3418 mock/qwindow.cpp \
3419+ mock/ui-server-mock.cpp \
3420 tst_signonui_request.cpp
3421
3422 HEADERS += \
3423- $${SRCDIR}/account-manager.h \
3424- $${SRCDIR}/application-manager.h \
3425- $${SRCDIR}/notification.h \
3426- $${SRCDIR}/request.h \
3427- $${SRCDIR}/request-handler.h \
3428- $${SRCDIR}/signonui-request.h \
3429+ $${ONLINE_ACCOUNTS_UI_DIR}/account-manager.h \
3430+ $${ONLINE_ACCOUNTS_UI_DIR}/application-manager.h \
3431+ $${ONLINE_ACCOUNTS_UI_DIR}/notification.h \
3432+ $${ONLINE_ACCOUNTS_UI_DIR}/request.h \
3433+ $${ONLINE_ACCOUNTS_UI_DIR}/request-handler.h \
3434+ $${ONLINE_ACCOUNTS_UI_DIR}/signonui-request.h \
3435+ $${ONLINE_ACCOUNTS_UI_DIR}/ui-server.h \
3436 mock/notification-mock.h \
3437 mock/request-mock.h \
3438+ mock/ui-server-mock.h \
3439 window-watcher.h
3440
3441-INCLUDEPATH += \
3442- $${SRCDIR}
3443-
3444 check.commands = "xvfb-run -s '-screen 0 640x480x24' -a dbus-test-runner -t ./$${TARGET}"
3445 check.depends = $${TARGET}
3446 QMAKE_EXTRA_TARGETS += check
3447
3448=== modified file 'tests/tests.pro'
3449--- tests/tests.pro 2014-05-06 11:29:32 +0000
3450+++ tests/tests.pro 2014-08-13 14:43:55 +0000
3451@@ -3,4 +3,5 @@
3452 autopilot \
3453 click-hooks \
3454 client \
3455+ online-accounts-service \
3456 online-accounts-ui
3457
3458=== modified file 'ubuntu-system-settings-online-accounts.pro'
3459--- ubuntu-system-settings-online-accounts.pro 2014-03-19 12:14:14 +0000
3460+++ ubuntu-system-settings-online-accounts.pro 2014-08-13 14:43:55 +0000
3461@@ -4,7 +4,8 @@
3462 TEMPLATE = subdirs
3463 SUBDIRS = \
3464 po \
3465- src \
3466+ online-accounts-service \
3467+ online-accounts-ui \
3468 click-hooks \
3469 client \
3470 system-settings-plugin \
3471@@ -12,8 +13,8 @@
3472 tests
3473
3474 system-settings-plugin.depends = client
3475-plugins.depends = src
3476-tests.depends = src client
3477+plugins.depends = online-accounts-ui
3478+tests.depends = online-accounts-service online-accounts-ui client
3479
3480 include(common-installs-config.pri)
3481

Subscribers

People subscribed via source and target branches

to all changes: