Merge lp:~jamesh/mediascanner/respect-privacy-setting into lp:mediascanner

Proposed by James Henstridge
Status: Needs review
Proposed branch: lp:~jamesh/mediascanner/respect-privacy-setting
Merge into: lp:mediascanner
Diff against target: 194 lines (+48/-9)
5 files modified
src/mediascanner/mediaartdownloader.cpp (+5/-0)
src/mediascanner/metadataresolver.cpp (+4/-1)
src/mediascanner/settings.cpp (+29/-6)
src/mediascanner/settings.h (+6/-2)
tests/auto/filesystemscannertest.cpp (+4/-0)
To merge this branch: bzr merge lp:~jamesh/mediascanner/respect-privacy-setting
Reviewer Review Type Date Requested Status
Jussi Pakkanen (community) Needs Fixing
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+191159@code.launchpad.net

Commit message

Respect the Unity dash "remote-content-search" privacy setting within the media scanner by disabling additional metadata resolvers and album art download.

Description of the change

Respect the Unity dash "remote-content-search" privacy setting within the media scanner by disabling additional metadata resolvers and album art download.

I know that creating additional instances of the Settings class inside those two bits of code isn't the cleanest solution, but the code base isn't really set up to provide access to the one set up by mediascanner-service's main routine, and we want to make sure this code reacts to changes in the setting (something that isn't hooked up for any of the media scanner's other settings).

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
399. By James Henstridge

Ignore warnings about missing com.canonical.Unity.Lenses schema in the
file system scanner tests: it is not a hard dependency, and the package
it belongs to is not a build dependency.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

remote_content_search is a bit ambiguous. Could it be renamed should_search_remote or something like that?

The lookup function has this:

if (not settings)
 return T();

but its return value is checked like this:

lookup(unity_lens_settings_, kRemoteContentSearch) != "none";

So if settings evaluates to false, empty string is returned and this comparison returns true. Is this what should happen?

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

The intent is to search remote content by default, and only disable it if the Unity GSettings schema exists and the key has been toggled. Here's the definition of the key that is being checked here:

    <key type="s" name="remote-content-search">
      <default>'all'</default>
      <choices><choice value='all'/><choice value='none'/></choices>
      <summary>Content fetching from remote source preference.</summary>
      <description>"all" is to enable the supported default lens to search from remote and commercial sources. "none" will indicate the lenses to not perform that remote search at all.</description>
    </key>

So I think the '!= "none"` check is appropriate, treating "all" and "" as equivalent.

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

That's all right then. What about the renaming? I'm not super strict about it, so if you feel it does not need to be done, then we can just merge this.

Unmerged revisions

399. By James Henstridge

Ignore warnings about missing com.canonical.Unity.Lenses schema in the
file system scanner tests: it is not a hard dependency, and the package
it belongs to is not a build dependency.

398. By James Henstridge

Disable metadata resolvers and album art download when remote content
search has been disabled.

397. By James Henstridge

Add accessor for Unity remote-content-search setting.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/mediascanner/mediaartdownloader.cpp'
2--- src/mediascanner/mediaartdownloader.cpp 2013-10-08 14:44:18 +0000
3+++ src/mediascanner/mediaartdownloader.cpp 2013-10-15 13:14:24 +0000
4@@ -22,6 +22,7 @@
5 #include "mediascanner/glibutils.h"
6 #include "mediascanner/mediaartcache.h"
7 #include "mediascanner/mediaartdownloader.h"
8+#include "mediascanner/settings.h"
9
10 #define ALBUM_ART_PLUGIN "grl-lastfm-albumart"
11 #define ALBUM_ART_SOURCE "grl-lastfm-albumart"
12@@ -71,6 +72,7 @@
13 MediaArtCache cache;
14 Wrapper<GrlSource> art_resolver;
15 Wrapper<SoupSession> session;
16+ Settings settings;
17
18 std::vector<ResolveDataPtr> jobs;
19
20@@ -153,6 +155,9 @@
21 if (not d->art_resolver || not d->session)
22 return;
23
24+ if (not d->settings.remote_content_search())
25+ return;
26+
27 kInfo("Resolving art for {1} - {2}") % artist % album;
28
29 if (d->cache.has_art(artist, album)) {
30
31=== modified file 'src/mediascanner/metadataresolver.cpp'
32--- src/mediascanner/metadataresolver.cpp 2013-10-08 14:44:18 +0000
33+++ src/mediascanner/metadataresolver.cpp 2013-10-15 13:14:24 +0000
34@@ -35,6 +35,7 @@
35 #include "mediascanner/logging.h"
36 #include "mediascanner/mediautils.h"
37 #include "mediascanner/propertyschema.h"
38+#include "mediascanner/settings.h"
39 #include "mediascanner/utilities.h"
40
41 namespace mediascanner {
42@@ -157,6 +158,7 @@
43 GrlMedia *media, void *user_data,
44 const GError *error);
45
46+ Settings settings_;
47 std::vector<MetadataSource> available_sources_;
48 Wrapper<GrlOperationOptions> options_;
49 std::vector<unsigned> current_ops_;
50@@ -272,7 +274,8 @@
51
52 g_mutex_lock(&mutex_);
53
54- resolve_next(media.get(), data);
55+ if (settings_.remote_content_search())
56+ resolve_next(media.get(), data);
57
58 const size_t removals = pending_pushes_.erase(push_id);
59 BOOST_ASSERT(removals == 1);
60
61=== modified file 'src/mediascanner/settings.cpp'
62--- src/mediascanner/settings.cpp 2013-09-11 09:49:12 +0000
63+++ src/mediascanner/settings.cpp 2013-10-15 13:14:24 +0000
64@@ -33,6 +33,8 @@
65 #include "mediascanner/logging.h"
66 #include "mediascanner/utilities.h"
67
68+#define UNITY_LENS_SCHEMA "com.canonical.Unity.Lenses"
69+
70 namespace mediascanner {
71
72 // Boost C++
73@@ -50,6 +52,8 @@
74 Settings::kMetadataSources("metadata-sources");
75 const Settings::Key<Settings::StringList>
76 Settings::kMediaRoots("media-roots");
77+const Settings::Key<std::string>
78+Settings::kRemoteContentSearch("remote-content-search");
79
80 // FIXME(M5): Apparently "dbus" is not the proper namespace for this things
81 namespace dbus {
82@@ -89,12 +93,27 @@
83 // TODO(M4): Handle change notifications
84 Settings::Settings()
85 : settings_(take(g_settings_new(MEDIASCANNER_SETTINGS_ID))) {
86+ auto schemas = g_settings_list_schemas();
87+ if (schemas) {
88+ for (int i = 0; schemas[i]; i++) {
89+ if (g_strcmp0(schemas[i], UNITY_LENS_SCHEMA) == 0) {
90+ unity_lens_settings_ = g_settings_new(UNITY_LENS_SCHEMA);
91+ break;
92+ }
93+ }
94+ }
95+ if (not unity_lens_settings_) {
96+ kWarning("Missing {1} schema") % UNITY_LENS_SCHEMA;
97+ }
98 }
99
100 template<typename T>
101-T Settings::lookup(const Key<T> &key) const {
102+T Settings::lookup(Wrapper<GSettings> settings, const Key<T> &key) const {
103+ if (not settings)
104+ return T();
105+
106 if (const Wrapper<GVariant> settings_value =
107- take(g_settings_get_value(settings_.get(), key.name_.c_str())))
108+ take(g_settings_get_value(settings.get(), key.name_.c_str())))
109 return dbus::Type<T>::make_value(settings_value.get());
110
111 return T();
112@@ -117,19 +136,23 @@
113 }
114
115 Settings::MediaFormatList Settings::mandatory_containers() const {
116- return lookup(kMandatoryContainers);
117+ return lookup(settings_, kMandatoryContainers);
118 }
119
120 Settings::MediaFormatList Settings::mandatory_decoders() const {
121- return lookup(kMandatoryDecoders);
122+ return lookup(settings_, kMandatoryDecoders);
123 }
124
125 Settings::MetadataSourceList Settings::metadata_sources() const {
126- return lookup(kMetadataSources);
127+ return lookup(settings_, kMetadataSources);
128 }
129
130 Settings::StringList Settings::media_root_urls() const {
131- return lookup(kMediaRoots);
132+ return lookup(settings_, kMediaRoots);
133+}
134+
135+bool Settings::remote_content_search() const {
136+ return lookup(unity_lens_settings_, kRemoteContentSearch) != "none";
137 }
138
139 static std::string user_dir_url(GUserDirectory dir) {
140
141=== modified file 'src/mediascanner/settings.h'
142--- src/mediascanner/settings.h 2013-09-10 14:02:38 +0000
143+++ src/mediascanner/settings.h 2013-10-15 13:14:24 +0000
144@@ -99,6 +99,7 @@
145 static const Key<MediaFormatList> kMandatoryDecoders;
146 static const Key<MetadataSourceList> kMetadataSources;
147 static const Key<StringList> kMediaRoots;
148+ static const Key<std::string> kRemoteContentSearch;
149
150 Settings();
151
152@@ -108,8 +109,7 @@
153 StringList media_root_urls() const;
154 StringList media_root_paths() const;
155
156- template<typename T>
157- T lookup(const Key<T> &key) const;
158+ bool remote_content_search() const;
159
160 unsigned connect(const KeyName &key, const ChangeListener &listener) const;
161 void disconnect(unsigned handler_id) const;
162@@ -120,6 +120,10 @@
163
164 private:
165 Wrapper<GSettings> settings_;
166+ Wrapper<GSettings> unity_lens_settings_;
167+
168+ template<typename T>
169+ T lookup(Wrapper<GSettings> settings, const Key<T> &key) const;
170 };
171
172 } // namespace mediascanner
173
174=== modified file 'tests/auto/filesystemscannertest.cpp'
175--- tests/auto/filesystemscannertest.cpp 2013-10-14 07:51:05 +0000
176+++ tests/auto/filesystemscannertest.cpp 2013-10-15 13:14:24 +0000
177@@ -162,6 +162,8 @@
178 LoggingSink sink(logging::warning());
179 sink.ignore("warning/roots", "Cannot retrieve information about.*");
180 sink.ignore("warning/roots", "Cannot identify mount point.*");
181+ sink.ignore("warning/settings",
182+ "Missing com.canonical.Unity.Lenses schema");
183
184 const MediaRootManagerPtr root_manager(new MediaRootManager);
185 root_manager->set_enabled(false);
186@@ -276,6 +278,8 @@
187 LoggingSink sink(logging::warning());
188 sink.ignore("warning/roots", "Cannot retrieve information about.*");
189 sink.ignore("warning/roots", "Cannot identify mount point.*");
190+ sink.ignore("warning/settings",
191+ "Missing com.canonical.Unity.Lenses schema");
192
193 const MediaRootManagerPtr root_manager(new MediaRootManager);
194 root_manager->set_enabled(false);

Subscribers

People subscribed via source and target branches