Merge lp:~michihenning/thumbnailer/config-access into lp:thumbnailer/devel

Proposed by Michi Henning
Status: Merged
Approved by: James Henstridge
Approved revision: 335
Merged at revision: 339
Proposed branch: lp:~michihenning/thumbnailer/config-access
Merge into: lp:thumbnailer/devel
Diff against target: 357 lines (+94/-19)
15 files modified
data/com.canonical.Unity.Thumbnailer.gschema.xml (+1/-1)
debian/changelog (+1/-0)
include/internal/settings.h (+5/-0)
man/thumbnailer-settings.5 (+1/-1)
plugins/Ubuntu/Thumbnailer.0.1/plugin.cpp (+0/-1)
plugins/Ubuntu/Thumbnailer.0.1/thumbnailgenerator.cpp (+0/-1)
src/libthumbnailer-qt/CMakeLists.txt (+2/-0)
src/libthumbnailer-qt/libthumbnailer-qt.cpp (+47/-6)
src/service/dbusinterface.cpp (+13/-3)
src/service/dbusinterface.h (+9/-2)
src/service/dbusinterface.xml (+6/-0)
src/settings.cpp (+6/-1)
src/thumbnailer.cpp (+1/-1)
src/ubuntuserverdownloader.cpp (+1/-1)
tests/settings/settings_test.cpp (+1/-1)
To merge this branch: bzr merge lp:~michihenning/thumbnailer/config-access
Reviewer Review Type Date Requested Status
James Henstridge Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+281580@code.launchpad.net

Commit message

Made client-side config settings available from the server.

Description of the change

Made client-side config settings available from the server. That's because we can't access gsettings from the client-side API when under confinement. Because the Settings class is no longer used on the client side, I moved that back into the internal namespace.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michi Henning (michihenning) wrote :

Related branch for the apparmor profile update:

https://code.launchpad.net/~michihenning/apparmor-easyprof-ubuntu/new-thumbnailer-methods/+merge/281712

Note that this change can land regardless. If apparmor denies access, we use the defaults, so it'll magically work once apparmor catches up.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
James Henstridge (jamesh) wrote :

I've left some inline comments. There are a few things to fix surrounding the use of the new D-Bus calls.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
James Henstridge (jamesh) wrote :

Looks better. I've left one more small note inline.

Revision history for this message
Michi Henning (michihenning) wrote :

Thanks for that!

It's also broken in another way: the number of CPUs really is irrelevant here. I wasn't thinking straight. What we want is 10 if max-downloads is set to 0, and whatever max-downloads is set to, otherwise, regardless of the number of CPUs. (As is, we are too low for a 2-core or 4-core machine because we need max-downloads at 10, even when there are fewer than 8 cores.)

I'll fix it.

Revision history for this message
Michi Henning (michihenning) wrote :

OK, should be good now. Default backlog is 10 now, regardless of CPU cores. I also fixed the QDBusReply thing. The explicit definition is needed because template deduction can't be used for the type returned by the invocation stub.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
335. By Michi Henning

Simplified dbus invocation.

Revision history for this message
James Henstridge (jamesh) :
Revision history for this message
James Henstridge (jamesh) wrote :

Looks good now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/com.canonical.Unity.Thumbnailer.gschema.xml'
2--- data/com.canonical.Unity.Thumbnailer.gschema.xml 2016-01-07 01:21:03 +0000
3+++ data/com.canonical.Unity.Thumbnailer.gschema.xml 2016-01-13 07:08:16 +0000
4@@ -77,7 +77,7 @@
5 <default>10</default>
6 <summary>Maximum number of pending DBus requests before the thumbnailer starts queuing them.</summary>
7 <description>
8- This parameter limits the number of pending DBus requests to the thumbnailer service. If there are more requests than this currently in progress, additional requests are queued and sent once the backlog drops below the limit.
9+ This parameter limits the number of pending DBus requests to the thumbnailer service. If the number of concurrent requests exceeds the backlog, additional requests are queued and sent once the backlog drops below the limit.
10 </description>
11 </key>
12
13
14=== modified file 'debian/changelog'
15--- debian/changelog 2016-01-09 03:22:11 +0000
16+++ debian/changelog 2016-01-13 07:08:16 +0000
17@@ -10,6 +10,7 @@
18 [ Michi Henning ]
19 * Fixed incorrect display of cache policy by "thumbnailer-admin stats".
20 * Limit GIF file size to 2 MB (LP: #1527315).
21+ * Fix non-working config settings for client-side API (LP: #1528058).
22
23 [ CI Train Bot ]
24 * No-change rebuild.
25
26=== renamed file 'include/settings.h' => 'include/internal/settings.h'
27--- include/settings.h 2016-01-04 06:09:41 +0000
28+++ include/internal/settings.h 2016-01-13 07:08:16 +0000
29@@ -32,6 +32,9 @@
30 namespace thumbnailer
31 {
32
33+namespace internal
34+{
35+
36 class Settings
37 {
38 public:
39@@ -66,6 +69,8 @@
40 internal::gobj_ptr<GSettings> settings_;
41 };
42
43+} // namespace internal
44+
45 } // namespace thumbnailer
46
47 } // namespace unity
48
49=== modified file 'man/thumbnailer-settings.5'
50--- man/thumbnailer-settings.5 2016-01-07 01:21:03 +0000
51+++ man/thumbnailer-settings.5 2016-01-13 07:08:16 +0000
52@@ -59,7 +59,7 @@
53 .TP
54 .B max\-backlog \fR(int)\fP
55 Controls the number of DBus requests that will be sent before queueing the requests internally.
56-The default is 10 requests.
57+The default is 10.
58 .TP
59 .B trace\-client \fR(bool)\fP
60 If true, thumbnail and cancel requests are logged. Log messages are written to the calling application's log
61
62=== modified file 'plugins/Ubuntu/Thumbnailer.0.1/plugin.cpp'
63--- plugins/Ubuntu/Thumbnailer.0.1/plugin.cpp 2015-09-30 10:08:20 +0000
64+++ plugins/Ubuntu/Thumbnailer.0.1/plugin.cpp 2016-01-13 07:08:16 +0000
65@@ -18,7 +18,6 @@
66
67 #include "plugin.h"
68
69-#include <settings.h>
70 #include "albumartgenerator.h"
71 #include "artistartgenerator.h"
72 #include "thumbnailgenerator.h"
73
74=== modified file 'plugins/Ubuntu/Thumbnailer.0.1/thumbnailgenerator.cpp'
75--- plugins/Ubuntu/Thumbnailer.0.1/thumbnailgenerator.cpp 2015-11-04 07:16:12 +0000
76+++ plugins/Ubuntu/Thumbnailer.0.1/thumbnailgenerator.cpp 2016-01-13 07:08:16 +0000
77@@ -22,7 +22,6 @@
78 #include <QMimeDatabase>
79 #include <QUrl>
80
81-#include <settings.h>
82 #include "thumbnailerimageresponse.h"
83
84 namespace
85
86=== modified file 'src/libthumbnailer-qt/CMakeLists.txt'
87--- src/libthumbnailer-qt/CMakeLists.txt 2015-11-30 06:36:53 +0000
88+++ src/libthumbnailer-qt/CMakeLists.txt 2016-01-13 07:08:16 +0000
89@@ -9,6 +9,8 @@
90 ${interface_files}
91 )
92
93+include_directories(${CMAKE_BINARY_DIR}/src)
94+
95 set_target_properties(${LIBTHUMBNAILER_QT} PROPERTIES
96 VERSION "${LIBTHUMBNAILER_QT_SO_VERSION_MAJOR}.${LIBTHUMBNAILER_QT_SO_VERSION_MINOR}.${LIBTHUMBNAILER_QT_SO_VERSION_MICRO}"
97 SOVERSION ${LIBTHUMBNAILER_QT_SO_VERSION}
98
99=== modified file 'src/libthumbnailer-qt/libthumbnailer-qt.cpp'
100--- src/libthumbnailer-qt/libthumbnailer-qt.cpp 2015-12-21 05:46:02 +0000
101+++ src/libthumbnailer-qt/libthumbnailer-qt.cpp 2016-01-13 07:08:16 +0000
102@@ -19,8 +19,8 @@
103
104 #include <unity/thumbnailer/qt/thumbnailer-qt.h>
105
106+#include <settings-defaults.h>
107 #include <ratelimiter.h>
108-#include <settings.h>
109 #include <thumbnailerinterface.h>
110 #include <service/dbus_names.h>
111
112@@ -132,8 +132,8 @@
113 QSize const& requested_size,
114 std::function<QDBusPendingReply<QByteArray>()> const& job);
115 std::unique_ptr<ThumbnailerInterface> iface_;
116- RateLimiter limiter_;
117 bool trace_client_;
118+ std::unique_ptr<RateLimiter> limiter_;
119 };
120
121 RequestImpl::RequestImpl(QString const& details,
122@@ -316,10 +316,51 @@
123 }
124
125 ThumbnailerImpl::ThumbnailerImpl(QDBusConnection const& connection)
126- : limiter_(Settings().max_backlog())
127- , trace_client_(Settings().trace_client())
128 {
129 iface_.reset(new ThumbnailerInterface(service::BUS_NAME, service::THUMBNAILER_BUS_PATH, connection));
130+
131+ // We need to retrieve config parameters from the server because, when an app runs confined,
132+ // it cannot read gsettings. We do this synchronously because we can't do anything else until
133+ // after we get the settings anyway.
134+
135+ auto trace_client_call = iface_->TraceClient();
136+ auto max_backlog_call = iface_->MaxBacklog();
137+
138+ {
139+ trace_client_call.waitForFinished();
140+ if (trace_client_call.isValid())
141+ {
142+ trace_client_ = trace_client_call.value();
143+ }
144+ // LCOV_EXCL_START
145+ else
146+ {
147+ bool const dflt = TRACE_CLIENT_DEFAULT;
148+ trace_client_ = dflt;
149+ qCritical().nospace() << "could not retrieve trace-client setting: " << trace_client_call.error().message()
150+ << " (using default value of " << dflt << ")";
151+
152+ }
153+ // LCOV_EXCL_STOP
154+ }
155+
156+ {
157+ int constexpr dflt_backlog = MAX_BACKLOG_DEFAULT;
158+ max_backlog_call.waitForFinished();
159+ if (max_backlog_call.isValid())
160+ {
161+ int backlog = max_backlog_call.value();
162+ limiter_.reset(new RateLimiter(backlog));
163+ }
164+ // LCOV_EXCL_START
165+ else
166+ {
167+ limiter_.reset(new RateLimiter(dflt_backlog));
168+ qCritical().nospace() << "could not retrieve max-backlog setting: " << max_backlog_call.error().message()
169+ << " (using default value of " << dflt_backlog << ")";
170+ }
171+ // LCOV_EXCL_STOP
172+ }
173 }
174
175 QSharedPointer<Request> ThumbnailerImpl::getAlbumArt(QString const& artist,
176@@ -384,12 +425,12 @@
177
178 RateLimiter& ThumbnailerImpl::limiter()
179 {
180- return limiter_;
181+ return *limiter_;
182 }
183
184 void ThumbnailerImpl::pump_limiter()
185 {
186- return limiter_.done();
187+ return limiter_->done();
188 }
189
190 } // namespace internal
191
192=== modified file 'src/service/dbusinterface.cpp'
193--- src/service/dbusinterface.cpp 2016-01-10 07:00:47 +0000
194+++ src/service/dbusinterface.cpp 2016-01-13 07:08:16 +0000
195@@ -19,7 +19,6 @@
196 #include "dbusinterface.h"
197
198 #include <internal/file_io.h>
199-#include <settings.h>
200
201 #include <boost/algorithm/string.hpp>
202 #include <boost/regex.hpp>
203@@ -94,8 +93,9 @@
204
205 extraction_limiter_ = make_shared<RateLimiter>(limit);
206
207- Settings s;
208- log_level_ = s.log_level();
209+ log_level_ = settings_.log_level();
210+ trace_client_ = settings_.trace_client();
211+ max_backlog_ = settings_.max_backlog();
212 }
213
214 DBusInterface::~DBusInterface()
215@@ -305,6 +305,16 @@
216 }
217 }
218
219+bool DBusInterface::TraceClient()
220+{
221+ return trace_client_;
222+}
223+
224+int DBusInterface::MaxBacklog()
225+{
226+ return max_backlog_;
227+}
228+
229 } // namespace service
230
231 } // namespace thumbnailer
232
233=== modified file 'src/service/dbusinterface.h'
234--- src/service/dbusinterface.h 2015-12-14 04:43:11 +0000
235+++ src/service/dbusinterface.h 2016-01-13 07:08:16 +0000
236@@ -22,7 +22,7 @@
237 #include "handler.h"
238
239 #include <ratelimiter.h>
240-#include <settings.h>
241+#include <internal/settings.h>
242
243 #include <QDBusContext>
244 #include <QThreadPool>
245@@ -53,6 +53,11 @@
246 QByteArray GetArtistArt(QString const& artist, QString const& album, QSize const& requestedSize);
247 QByteArray GetThumbnail(QString const& filename, QSize const& requestedSize);
248
249+ // These methods return the value of the corresponding gsettings key. We need to do this on the server
250+ // side because the client-side API runs under confinement, which disallows access to gsettings.
251+ bool TraceClient();
252+ int MaxBacklog();
253+
254 private:
255 void queueRequest(Handler* handler);
256
257@@ -72,10 +77,12 @@
258 std::shared_ptr<QThreadPool> create_thread_pool_;
259 std::map<Handler*, std::unique_ptr<Handler>> requests_;
260 std::map<std::string, std::vector<Handler*>> request_keys_;
261- unity::thumbnailer::Settings settings_;
262+ unity::thumbnailer::internal::Settings settings_;
263 std::shared_ptr<RateLimiter> download_limiter_;
264 std::shared_ptr<RateLimiter> extraction_limiter_;
265 int log_level_;
266+ bool trace_client_;
267+ int max_backlog_;
268 };
269
270 } // namespace service
271
272=== modified file 'src/service/dbusinterface.xml'
273--- src/service/dbusinterface.xml 2015-12-03 02:01:47 +0000
274+++ src/service/dbusinterface.xml 2016-01-13 07:08:16 +0000
275@@ -20,5 +20,11 @@
276 <arg direction="out" type="ay" name="thumbnail" />
277 <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QSize" />
278 </method>
279+ <method name="TraceClient">
280+ <arg direction="out" type="b" name="traceClient" />
281+ </method>
282+ <method name="MaxBacklog">
283+ <arg direction="out" type="i" name="maxBacklog" />
284+ </method>
285 </interface>
286 </node>
287
288=== modified file 'src/settings.cpp'
289--- src/settings.cpp 2016-01-04 06:09:41 +0000
290+++ src/settings.cpp 2016-01-13 07:08:16 +0000
291@@ -16,7 +16,7 @@
292 * Authored by: James Henstridge <james.henstridge@canonical.com>
293 */
294
295-#include <settings.h>
296+#include <internal/settings.h>
297
298 #include <internal/env_vars.h>
299 #include "settings-defaults.h"
300@@ -39,6 +39,9 @@
301 namespace thumbnailer
302 {
303
304+namespace internal
305+{
306+
307 Settings::Settings()
308 : Settings("com.canonical.Unity.Thumbnailer")
309 {
310@@ -220,6 +223,8 @@
311 return g_settings_get_boolean(settings_.get(), key);
312 }
313
314+} // namespace internal
315+
316 } // namespace thumbnailer
317
318 } // namespace unity
319
320=== modified file 'src/thumbnailer.cpp'
321--- src/thumbnailer.cpp 2016-01-08 09:22:07 +0000
322+++ src/thumbnailer.cpp 2016-01-13 07:08:16 +0000
323@@ -28,8 +28,8 @@
324 #include <internal/make_directories.h>
325 #include <internal/raii.h>
326 #include <internal/safe_strerror.h>
327+#include <internal/settings.h>
328 #include <internal/ubuntuserverdownloader.h>
329-#include <settings.h>
330
331 #include <boost/filesystem.hpp>
332
333
334=== modified file 'src/ubuntuserverdownloader.cpp'
335--- src/ubuntuserverdownloader.cpp 2015-12-29 23:04:19 +0000
336+++ src/ubuntuserverdownloader.cpp 2016-01-13 07:08:16 +0000
337@@ -22,7 +22,7 @@
338
339 #include <internal/artreply.h>
340 #include <internal/env_vars.h>
341-#include <settings.h>
342+#include <internal/settings.h>
343
344 #include <QNetworkReply>
345 #include <QTimer>
346
347=== modified file 'tests/settings/settings_test.cpp'
348--- tests/settings/settings_test.cpp 2016-01-07 01:21:03 +0000
349+++ tests/settings/settings_test.cpp 2016-01-13 07:08:16 +0000
350@@ -18,7 +18,7 @@
351
352 #include <internal/env_vars.h>
353 #include <internal/gobj_memory.h>
354-#include <settings.h>
355+#include <internal/settings.h>
356 #include <testsetup.h>
357 #include <utils/env_var_guard.h>
358

Subscribers

People subscribed via source and target branches

to all changes: