Merge lp:~marcustomlinson/unity-scopes-api/fix_ui_policy into lp:unity-scopes-api
- fix_ui_policy
- Merge into trunk
Proposed by
Marcus Tomlinson
Status: | Superseded |
---|---|
Proposed branch: | lp:~marcustomlinson/unity-scopes-api/fix_ui_policy |
Merge into: | lp:unity-scopes-api |
Diff against target: |
867 lines (+426/-137) 9 files modified
CMakeLists.txt (+1/-1) HACKING (+22/-1) RELEASE_NOTES.md (+5/-0) debian/changelog (+7/-0) include/unity/scopes/OnlineAccountClient.h (+8/-9) include/unity/scopes/internal/OnlineAccountClientImpl.h (+23/-13) src/scopes/internal/OnlineAccountClientImpl.cpp (+347/-112) src/scopes/internal/RegistryObject.cpp (+11/-1) test/gtest/scopes/OnlineAccountClient/OnlineAccountClient_test.cpp (+2/-0) |
To merge this branch: | bzr merge lp:~marcustomlinson/unity-scopes-api/fix_ui_policy |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Paweł Stołowski (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+237216@code.launchpad.net |
This proposal has been superseded by a proposal from 2014-10-08.
Commit message
1. Depending on whether OnlineAccountClient is used by the shell or by a scope, set the SIGNON_
2. Inform scopes of successful user authentications via a pub/sub network.
3. Removed inc_logins() and dec_logins() as only one session can be active per service (now using info->session != nullptr).
4. Added better thread and exception safety.
5. Run the internal event loop within its own context to avoid clashing with external main loops.
Description of the change
To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Approve
(continuous-integration)
- 264. By Marcus Tomlinson
-
Merged devel
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2014-09-11 08:35:01 +0000 | |||
3 | +++ CMakeLists.txt 2014-10-08 10:59:41 +0000 | |||
4 | @@ -195,7 +195,7 @@ | |||
5 | 195 | # API version | 195 | # API version |
6 | 196 | set(UNITY_SCOPES_MAJOR 0) | 196 | set(UNITY_SCOPES_MAJOR 0) |
7 | 197 | set(UNITY_SCOPES_MINOR 6) | 197 | set(UNITY_SCOPES_MINOR 6) |
9 | 198 | set(UNITY_SCOPES_MICRO 6) | 198 | set(UNITY_SCOPES_MICRO 7) |
10 | 199 | set(UNITY_SCOPES_SOVERSION 3) | 199 | set(UNITY_SCOPES_SOVERSION 3) |
11 | 200 | 200 | ||
12 | 201 | # Version for testing, with all symbols visible | 201 | # Version for testing, with all symbols visible |
13 | 202 | 202 | ||
14 | === modified file 'HACKING' | |||
15 | --- HACKING 2014-09-08 22:15:40 +0000 | |||
16 | +++ HACKING 2014-10-08 10:59:41 +0000 | |||
17 | @@ -156,7 +156,28 @@ | |||
18 | 156 | This creates a diff of the symbols in /tmp/symbols.diff. | 156 | This creates a diff of the symbols in /tmp/symbols.diff. |
19 | 157 | (The demangled symbols from the debian build are in ./new_symbols.) | 157 | (The demangled symbols from the debian build are in ./new_symbols.) |
20 | 158 | 158 | ||
22 | 159 | Review any changes in /tmp/symbols.diff. If they are OK: | 159 | NOTE: We currently have one architecture-specific symbol: |
23 | 160 | |||
24 | 161 | (c++|arch=amd64)"unity::scopes::internal::RegistryObject::ScopeExecData::ScopeExecData(unity::scopes::internal::RegistryObject::ScopeExecData const&)@Base" 0.6.6+14.10.20140916 | ||
25 | 162 | |||
26 | 163 | We need this because the copy-constructor is inlined on i386 and armhf. | ||
27 | 164 | |||
28 | 165 | The above script can't cope with the arch tag at the moment. Until we get | ||
29 | 166 | around to fixing this, you need to delete the corresponding change from | ||
30 | 167 | the diff output before applying the diff as a patch. The offending diff | ||
31 | 168 | will look something like this: | ||
32 | 169 | |||
33 | 170 | @@ -377,7 +378,7 @@ | ||
34 | 171 | (c++)"unity::scopes::internal::RegistryObject::remove_desktop_file(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@Base" 0.6.6+14.10.20140916 | ||
35 | 172 | (c++)"unity::scopes::internal::RegistryObject::remove_local_scope(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@Base" 0.4.0+14.04.20140312.1 | ||
36 | 173 | (c++)"unity::scopes::internal::RegistryObject::ScopeExecData::~ScopeExecData()@Base" 0.4.2+14.04.20140404.2 | ||
37 | 174 | - (c++|arch=amd64)"unity::scopes::internal::RegistryObject::ScopeExecData::ScopeExecData(unity::scopes::internal::RegistryObject::ScopeExecData const&)@Base" 0.6.6+14.10.20140916 | ||
38 | 175 | + (c++)"unity::scopes::internal::RegistryObject::ScopeExecData::ScopeExecData(unity::scopes::internal::RegistryObject::ScopeExecData const&)@Base" 0replaceme | ||
39 | 176 | (c++)"unity::scopes::internal::RegistryObject::ScopeProcess::clear_handle_unlocked()@Base" 0.4.2+14.04.20140404.2 | ||
40 | 177 | (c++)"unity::scopes::internal::RegistryObject::ScopeProcess::exec(core::posix::ChildProcess::DeathObserver&, std::shared_ptr<unity::scopes::internal::Executor>)@Base" 0.4.3+14.10.20140428 | ||
41 | 178 | (c++)"unity::scopes::internal::RegistryObject::ScopeProcess::expand_custom_exec()@Base" 0.5.0+14.10.20140619 | ||
42 | 179 | |||
43 | 180 | Review any other changes in /tmp/symbols.diff. If they are OK: | ||
44 | 160 | 181 | ||
45 | 161 | $ cd - | 182 | $ cd - |
46 | 162 | $ patch -p0 < /tmp/symbols.diff | 183 | $ patch -p0 < /tmp/symbols.diff |
47 | 163 | 184 | ||
48 | === modified file 'RELEASE_NOTES.md' | |||
49 | --- RELEASE_NOTES.md 2014-09-11 08:42:38 +0000 | |||
50 | +++ RELEASE_NOTES.md 2014-10-08 10:59:41 +0000 | |||
51 | @@ -1,6 +1,11 @@ | |||
52 | 1 | Release notes | 1 | Release notes |
53 | 2 | ============= | 2 | ============= |
54 | 3 | 3 | ||
55 | 4 | Changes in version 0.6.7 | ||
56 | 5 | ======================== | ||
57 | 6 | - Added new RunInExternalUiMainLoop option to OnlineAccountClient::MainLoopSelect. | ||
58 | 7 | - OnlineAccountClient signon UI policy determined by main loop used (shell: show / scope: hide). | ||
59 | 8 | |||
60 | 4 | Changes in version 0.6.6 | 9 | Changes in version 0.6.6 |
61 | 5 | ======================== | 10 | ======================== |
62 | 6 | - Added support for online accounts (via new OnlineAccountClient class). | 11 | - Added support for online accounts (via new OnlineAccountClient class). |
63 | 7 | 12 | ||
64 | === modified file 'debian/changelog' | |||
65 | --- debian/changelog 2014-10-06 12:03:20 +0000 | |||
66 | +++ debian/changelog 2014-10-08 10:59:41 +0000 | |||
67 | @@ -1,3 +1,10 @@ | |||
68 | 1 | unity-scopes-api (0.6.7-0ubuntu1) UNRELEASED; urgency=medium | ||
69 | 2 | |||
70 | 3 | * Added new RunInExternalUiMainLoop option to OnlineAccountClient::MainLoopSelect. | ||
71 | 4 | * OnlineAccountClient signon UI policy determined by main loop used (shell: show / scope: hide). | ||
72 | 5 | |||
73 | 6 | -- Marcus Tomlinson <marcus.tomlinson@canonical.com> Wed, 01 Oct 2014 15:46:30 +0200 | ||
74 | 7 | |||
75 | 1 | unity-scopes-api (0.6.6+14.10.20141006-0ubuntu1) utopic; urgency=medium | 8 | unity-scopes-api (0.6.6+14.10.20141006-0ubuntu1) utopic; urgency=medium |
76 | 2 | 9 | ||
77 | 3 | [ Pawel Stolowski ] | 10 | [ Pawel Stolowski ] |
78 | 4 | 11 | ||
79 | === modified file 'include/unity/scopes/OnlineAccountClient.h' | |||
80 | --- include/unity/scopes/OnlineAccountClient.h 2014-09-15 05:10:17 +0000 | |||
81 | +++ include/unity/scopes/OnlineAccountClient.h 2014-10-08 10:59:41 +0000 | |||
82 | @@ -55,7 +55,7 @@ | |||
83 | 55 | */ | 55 | */ |
84 | 56 | struct ServiceStatus | 56 | struct ServiceStatus |
85 | 57 | { | 57 | { |
87 | 58 | uint account_id; ///< A unique ID of the online account parenting this service. | 58 | int account_id; ///< A unique ID of the online account parenting this service. |
88 | 59 | bool service_enabled; ///< True if this service is enabled. | 59 | bool service_enabled; ///< True if this service is enabled. |
89 | 60 | bool service_authenticated; ///< True if this service is authenticated. | 60 | bool service_authenticated; ///< True if this service is authenticated. |
90 | 61 | std::string client_id; ///< "ConsumerKey" / "ClientId" OAuth (1 / 2) parameter. | 61 | std::string client_id; ///< "ConsumerKey" / "ClientId" OAuth (1 / 2) parameter. |
91 | @@ -68,16 +68,15 @@ | |||
92 | 68 | /** | 68 | /** |
93 | 69 | \brief Indicates whether an external main loop already exists, or one should be created internally. | 69 | \brief Indicates whether an external main loop already exists, or one should be created internally. |
94 | 70 | 70 | ||
98 | 71 | A running main loop is essential in order to receive service update callbacks. When in doubt, set | 71 | A running main loop is essential in order to receive service updates from the online accounts |
99 | 72 | RunInExternalMainLoop and just use refresh_service_statuses() and get_service_statuses() to obtain | 72 | backend. When in doubt, set to CreateInternalMainLoop. |
97 | 73 | service statuses. | ||
100 | 74 | */ | 73 | */ |
101 | 75 | enum MainLoopSelect | 74 | enum MainLoopSelect |
102 | 76 | { | 75 | { |
107 | 77 | RunInExternalMainLoop, ///< An external main loop already exists or the service update | 76 | RunInExternalMainLoop, ///< An external main loop already exists and is running. |
108 | 78 | /// callback is not required. | 77 | CreateInternalMainLoop, ///< An external main loop does not exist. |
109 | 79 | CreateInternalMainLoop ///< An external main loop does not exist and the service update | 78 | RunInExternalUiMainLoop, ///< An external UI main loop exists and is running (Intended for |
110 | 80 | /// callback is required. | 79 | /// shell use only. A scope should not be running a UI main loop). |
111 | 81 | }; | 80 | }; |
112 | 82 | 81 | ||
113 | 83 | /** | 82 | /** |
114 | @@ -91,7 +90,7 @@ | |||
115 | 91 | OnlineAccountClient(std::string const& service_name, | 90 | OnlineAccountClient(std::string const& service_name, |
116 | 92 | std::string const& service_type, | 91 | std::string const& service_type, |
117 | 93 | std::string const& provider_name, | 92 | std::string const& provider_name, |
119 | 94 | MainLoopSelect main_loop_select = RunInExternalMainLoop); | 93 | MainLoopSelect main_loop_select = CreateInternalMainLoop); |
120 | 95 | 94 | ||
121 | 96 | /// @cond | 95 | /// @cond |
122 | 97 | ~OnlineAccountClient(); | 96 | ~OnlineAccountClient(); |
123 | 98 | 97 | ||
124 | === modified file 'include/unity/scopes/internal/OnlineAccountClientImpl.h' | |||
125 | --- include/unity/scopes/internal/OnlineAccountClientImpl.h 2014-09-11 11:29:29 +0000 | |||
126 | +++ include/unity/scopes/internal/OnlineAccountClientImpl.h 2014-10-08 10:59:41 +0000 | |||
127 | @@ -19,6 +19,7 @@ | |||
128 | 19 | #ifndef UNITY_SCOPES_INTERNAL_ONLINEACCOUNTCLIENTIMPL_H | 19 | #ifndef UNITY_SCOPES_INTERNAL_ONLINEACCOUNTCLIENTIMPL_H |
129 | 20 | #define UNITY_SCOPES_INTERNAL_ONLINEACCOUNTCLIENTIMPL_H | 20 | #define UNITY_SCOPES_INTERNAL_ONLINEACCOUNTCLIENTIMPL_H |
130 | 21 | 21 | ||
131 | 22 | #include <unity/scopes/internal/MiddlewareBase.h> | ||
132 | 22 | #include <unity/scopes/OnlineAccountClient.h> | 23 | #include <unity/scopes/OnlineAccountClient.h> |
133 | 23 | 24 | ||
134 | 24 | #include <libaccounts-glib/accounts-glib.h> | 25 | #include <libaccounts-glib/accounts-glib.h> |
135 | @@ -78,42 +79,51 @@ | |||
136 | 78 | OnlineAccountClient::PostLoginAction login_failed_action); | 79 | OnlineAccountClient::PostLoginAction login_failed_action); |
137 | 79 | 80 | ||
138 | 80 | // Methods used only by impl | 81 | // Methods used only by impl |
140 | 81 | void flush_pending_sessions(); | 82 | void construct(); |
141 | 83 | void tear_down(); | ||
142 | 84 | |||
143 | 85 | void flush_pending_session(AgAccountId const& account_id, std::unique_lock<std::mutex>& lock); | ||
144 | 82 | 86 | ||
145 | 83 | void main_loop_state_notify(bool is_running); | 87 | void main_loop_state_notify(bool is_running); |
146 | 84 | 88 | ||
147 | 89 | std::shared_ptr<AgManager> manager(); | ||
148 | 85 | std::string service_name(); | 90 | std::string service_name(); |
150 | 86 | void callback(OnlineAccountClient::ServiceStatus const& service_status); | 91 | OnlineAccountClient::MainLoopSelect main_loop_select(); |
151 | 92 | |||
152 | 93 | void callback(AccountInfo const* info, std::string const& error = ""); | ||
153 | 87 | 94 | ||
154 | 88 | bool has_account(AgAccountId const& account_id); | 95 | bool has_account(AgAccountId const& account_id); |
155 | 89 | void add_account(AgAccountId const& account_id, std::shared_ptr<AccountInfo> account_info); | 96 | void add_account(AgAccountId const& account_id, std::shared_ptr<AccountInfo> account_info); |
156 | 90 | void remove_account(AgAccountId const& account_id); | 97 | void remove_account(AgAccountId const& account_id); |
157 | 91 | 98 | ||
158 | 92 | bool inc_logins(); | ||
159 | 93 | void dec_logins(); | ||
160 | 94 | |||
161 | 95 | private: | 99 | private: |
165 | 96 | std::string service_name_; | 100 | std::string const service_name_; |
166 | 97 | std::string service_type_; | 101 | std::string const service_type_; |
167 | 98 | std::string provider_name_; | 102 | std::string const provider_name_; |
168 | 103 | OnlineAccountClient::MainLoopSelect const main_loop_select_; | ||
169 | 104 | |||
170 | 105 | std::mutex callback_mutex_; | ||
171 | 99 | OnlineAccountClient::ServiceUpdateCallback callback_; | 106 | OnlineAccountClient::ServiceUpdateCallback callback_; |
172 | 100 | bool use_external_main_loop_; | ||
173 | 101 | 107 | ||
174 | 102 | std::thread main_loop_thread_; | ||
175 | 103 | std::mutex callback_mutex_; | ||
176 | 104 | std::mutex mutex_; | 108 | std::mutex mutex_; |
177 | 105 | std::condition_variable cond_; | 109 | std::condition_variable cond_; |
178 | 110 | std::thread main_loop_thread_; | ||
179 | 106 | bool main_loop_is_running_; | 111 | bool main_loop_is_running_; |
182 | 107 | bool client_stopping_; | 112 | std::exception_ptr thread_exception_; |
181 | 108 | int logins_busy_; | ||
183 | 109 | gulong account_enabled_signal_id_; | 113 | gulong account_enabled_signal_id_; |
184 | 110 | gulong account_deleted_signal_id_; | 114 | gulong account_deleted_signal_id_; |
185 | 111 | 115 | ||
186 | 112 | std::shared_ptr<GMainLoop> main_loop_; | 116 | std::shared_ptr<GMainLoop> main_loop_; |
187 | 117 | std::shared_ptr<GMainContext> main_loop_context_; | ||
188 | 113 | std::shared_ptr<AgManager> manager_; | 118 | std::shared_ptr<AgManager> manager_; |
189 | 114 | std::map<AgAccountId, std::shared_ptr<AccountInfo>> accounts_; | 119 | std::map<AgAccountId, std::shared_ptr<AccountInfo>> accounts_; |
190 | 115 | 120 | ||
191 | 121 | MiddlewareBase::SPtr mw_; | ||
192 | 122 | MWPublisher::UPtr auth_publisher_; | ||
193 | 123 | MWSubscriber::UPtr auth_subscriber_; | ||
194 | 124 | |||
195 | 116 | void main_loop_thread(); | 125 | void main_loop_thread(); |
196 | 126 | void auth_callback(std::string const& details_json); | ||
197 | 117 | }; | 127 | }; |
198 | 118 | 128 | ||
199 | 119 | } // namespace internal | 129 | } // namespace internal |
200 | 120 | 130 | ||
201 | === modified file 'src/scopes/internal/OnlineAccountClientImpl.cpp' | |||
202 | --- src/scopes/internal/OnlineAccountClientImpl.cpp 2014-09-15 07:06:51 +0000 | |||
203 | +++ src/scopes/internal/OnlineAccountClientImpl.cpp 2014-10-08 10:59:41 +0000 | |||
204 | @@ -17,7 +17,12 @@ | |||
205 | 17 | */ | 17 | */ |
206 | 18 | 18 | ||
207 | 19 | #include <unity/scopes/internal/OnlineAccountClientImpl.h> | 19 | #include <unity/scopes/internal/OnlineAccountClientImpl.h> |
209 | 20 | #include <unity/util/ResourcePtr.h> | 20 | |
210 | 21 | #include <unity/scopes/internal/JsonCppNode.h> | ||
211 | 22 | #include <unity/scopes/internal/MiddlewareFactory.h> | ||
212 | 23 | #include <unity/scopes/internal/RuntimeConfig.h> | ||
213 | 24 | #include <unity/scopes/internal/RuntimeImpl.h> | ||
214 | 25 | #include <unity/UnityExceptions.h> | ||
215 | 21 | 26 | ||
216 | 22 | #include <iostream> | 27 | #include <iostream> |
217 | 23 | 28 | ||
218 | @@ -88,7 +93,41 @@ | |||
219 | 88 | return service_status; | 93 | return service_status; |
220 | 89 | } | 94 | } |
221 | 90 | 95 | ||
223 | 91 | static void clear_session_info(AccountInfo* info) | 96 | static std::string details_to_json(OnlineAccountClient::ServiceStatus const& details) |
224 | 97 | { | ||
225 | 98 | VariantMap vm; | ||
226 | 99 | vm["account_id"] = details.account_id; | ||
227 | 100 | vm["service_enabled"] = details.service_enabled; | ||
228 | 101 | vm["service_authenticated"] = details.service_authenticated; | ||
229 | 102 | vm["client_id"] = details.client_id; | ||
230 | 103 | vm["client_secret"] = details.client_secret; | ||
231 | 104 | vm["access_token"] = details.access_token; | ||
232 | 105 | vm["token_secret"] = details.token_secret; | ||
233 | 106 | vm["error"] = details.error; | ||
234 | 107 | |||
235 | 108 | Variant var(vm); | ||
236 | 109 | JsonCppNode node(var); | ||
237 | 110 | return node.to_json_string(); | ||
238 | 111 | } | ||
239 | 112 | |||
240 | 113 | static OnlineAccountClient::ServiceStatus json_to_details(std::string const& json) | ||
241 | 114 | { | ||
242 | 115 | OnlineAccountClient::ServiceStatus details; | ||
243 | 116 | JsonCppNode node(json); | ||
244 | 117 | |||
245 | 118 | details.account_id = node.get_node("account_id")->as_int(); | ||
246 | 119 | details.service_enabled = node.get_node("service_enabled")->as_bool(); | ||
247 | 120 | details.service_authenticated = node.get_node("service_authenticated")->as_bool(); | ||
248 | 121 | details.client_id = node.get_node("client_id")->as_string(); | ||
249 | 122 | details.client_secret = node.get_node("client_secret")->as_string(); | ||
250 | 123 | details.access_token = node.get_node("access_token")->as_string(); | ||
251 | 124 | details.token_secret = node.get_node("token_secret")->as_string(); | ||
252 | 125 | details.error = node.get_node("error")->as_string(); | ||
253 | 126 | |||
254 | 127 | return details; | ||
255 | 128 | } | ||
256 | 129 | |||
257 | 130 | static void clear_session(AccountInfo* info) | ||
258 | 92 | { | 131 | { |
259 | 93 | if (info->session) | 132 | if (info->session) |
260 | 94 | { | 133 | { |
261 | @@ -96,8 +135,6 @@ | |||
262 | 96 | signon_auth_session_cancel(info->session.get()); | 135 | signon_auth_session_cancel(info->session.get()); |
263 | 97 | } | 136 | } |
264 | 98 | info->session = nullptr; | 137 | info->session = nullptr; |
265 | 99 | info->auth_params = nullptr; | ||
266 | 100 | info->session_data = nullptr; | ||
267 | 101 | } | 138 | } |
268 | 102 | 139 | ||
269 | 103 | static gboolean main_loop_is_running_cb(void* user_data) | 140 | static gboolean main_loop_is_running_cb(void* user_data) |
270 | @@ -107,6 +144,13 @@ | |||
271 | 107 | return G_SOURCE_REMOVE; | 144 | return G_SOURCE_REMOVE; |
272 | 108 | } | 145 | } |
273 | 109 | 146 | ||
274 | 147 | static gboolean main_loop_is_stopping_cb(void* user_data) | ||
275 | 148 | { | ||
276 | 149 | OnlineAccountClientImpl* account_client = reinterpret_cast<OnlineAccountClientImpl*>(user_data); | ||
277 | 150 | account_client->main_loop_state_notify(false); | ||
278 | 151 | return G_SOURCE_REMOVE; | ||
279 | 152 | } | ||
280 | 153 | |||
281 | 110 | static gboolean wake_up_event_loop_cb(void* user_data) | 154 | static gboolean wake_up_event_loop_cb(void* user_data) |
282 | 111 | { | 155 | { |
283 | 112 | GMainLoop* event_loop = reinterpret_cast<GMainLoop*>(user_data); | 156 | GMainLoop* event_loop = reinterpret_cast<GMainLoop*>(user_data); |
284 | @@ -116,58 +160,75 @@ | |||
285 | 116 | 160 | ||
286 | 117 | static void service_login_cb(GObject* source, GAsyncResult* result, void* user_data) | 161 | static void service_login_cb(GObject* source, GAsyncResult* result, void* user_data) |
287 | 118 | { | 162 | { |
288 | 119 | GError* error = nullptr; | ||
289 | 120 | util::ResourcePtr<GError*, decltype(&g_error_free)> error_cleanup(error, free_error); | ||
290 | 121 | |||
291 | 122 | SignonAuthSession* session = reinterpret_cast<SignonAuthSession*>(source); | 163 | SignonAuthSession* session = reinterpret_cast<SignonAuthSession*>(source); |
292 | 123 | AccountInfo* info = reinterpret_cast<AccountInfo*>(user_data); | 164 | AccountInfo* info = reinterpret_cast<AccountInfo*>(user_data); |
293 | 124 | 165 | ||
294 | 125 | // Get session data then send a notification with the login result | 166 | // Get session data then send a notification with the login result |
295 | 167 | GError* error = nullptr; | ||
296 | 126 | info->session_data.reset(signon_auth_session_process_finish(session, result, &error), free_variant); | 168 | info->session_data.reset(signon_auth_session_process_finish(session, result, &error), free_variant); |
299 | 127 | info->account_client->callback(info_to_details(info, error ? error->message : "")); | 169 | std::shared_ptr<GError> error_cleanup(error, free_error); |
300 | 128 | info->account_client->dec_logins(); | 170 | |
301 | 171 | info->account_client->callback(info, error ? error->message : ""); | ||
302 | 172 | |||
303 | 173 | // Clear session info | ||
304 | 174 | clear_session(info); | ||
305 | 129 | } | 175 | } |
306 | 130 | 176 | ||
307 | 131 | static void service_update_cb(AgAccountService* account_service, gboolean enabled, AccountInfo* info) | 177 | static void service_update_cb(AgAccountService* account_service, gboolean enabled, AccountInfo* info) |
308 | 132 | { | 178 | { |
309 | 133 | GError* error = nullptr; | ||
310 | 134 | util::ResourcePtr<GError*, decltype(&g_error_free)> error_cleanup(error, free_error); | ||
311 | 135 | |||
312 | 136 | // Service state has updated, clear the old session data | 179 | // Service state has updated, clear the old session data |
313 | 137 | info->service_enabled = enabled; | 180 | info->service_enabled = enabled; |
315 | 138 | clear_session_info(info); | 181 | clear_session(info); |
316 | 139 | 182 | ||
317 | 140 | if (enabled) | 183 | if (enabled) |
318 | 141 | { | 184 | { |
319 | 142 | // Get authorization data then create a new authorization session | 185 | // Get authorization data then create a new authorization session |
320 | 143 | std::shared_ptr<AgAuthData> auth_data(ag_account_service_get_auth_data(account_service), ag_auth_data_unref); | 186 | std::shared_ptr<AgAuthData> auth_data(ag_account_service_get_auth_data(account_service), ag_auth_data_unref); |
321 | 187 | |||
322 | 188 | GError* error = nullptr; | ||
323 | 144 | info->session.reset(signon_auth_session_new( | 189 | info->session.reset(signon_auth_session_new( |
324 | 145 | ag_auth_data_get_credentials_id(auth_data.get()), ag_auth_data_get_method(auth_data.get()), &error), g_object_unref); | 190 | ag_auth_data_get_credentials_id(auth_data.get()), ag_auth_data_get_method(auth_data.get()), &error), g_object_unref); |
325 | 191 | std::shared_ptr<GError> error_cleanup(error, free_error); | ||
326 | 192 | |||
327 | 146 | if (error) | 193 | if (error) |
328 | 147 | { | 194 | { |
329 | 148 | // Send notification that the authorization session failed | 195 | // Send notification that the authorization session failed |
331 | 149 | info->account_client->callback(info_to_details(info, error->message)); | 196 | info->account_client->callback(info, error->message); |
332 | 150 | return; | 197 | return; |
333 | 151 | } | 198 | } |
334 | 152 | 199 | ||
335 | 153 | // Get authorization parameters then attempt to signon | 200 | // Get authorization parameters then attempt to signon |
336 | 201 | GVariantBuilder builder; | ||
337 | 202 | g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); | ||
338 | 203 | |||
339 | 204 | if (info->account_client->main_loop_select() == OnlineAccountClient::RunInExternalUiMainLoop) | ||
340 | 205 | { | ||
341 | 206 | g_variant_builder_add(&builder, "{sv}", | ||
342 | 207 | SIGNON_SESSION_DATA_UI_POLICY, | ||
343 | 208 | g_variant_new_int32(SIGNON_POLICY_DEFAULT)); | ||
344 | 209 | } | ||
345 | 210 | else | ||
346 | 211 | { | ||
347 | 212 | g_variant_builder_add(&builder, "{sv}", | ||
348 | 213 | SIGNON_SESSION_DATA_UI_POLICY, | ||
349 | 214 | g_variant_new_int32(SIGNON_POLICY_NO_USER_INTERACTION)); | ||
350 | 215 | } | ||
351 | 216 | |||
352 | 154 | info->auth_params.reset( | 217 | info->auth_params.reset( |
354 | 155 | g_variant_ref_sink(ag_auth_data_get_login_parameters(auth_data.get(), nullptr)), free_variant); | 218 | g_variant_ref_sink(ag_auth_data_get_login_parameters(auth_data.get(), g_variant_builder_end(&builder))), free_variant); |
355 | 156 | 219 | ||
365 | 157 | if (info->account_client->inc_logins()) | 220 | // Start signon process |
366 | 158 | { | 221 | signon_auth_session_process_async(info->session.get(), |
367 | 159 | signon_auth_session_process_async(info->session.get(), | 222 | info->auth_params.get(), |
368 | 160 | info->auth_params.get(), | 223 | ag_auth_data_get_mechanism(auth_data.get()), |
369 | 161 | ag_auth_data_get_mechanism(auth_data.get()), | 224 | nullptr, |
370 | 162 | nullptr, | 225 | service_login_cb, |
371 | 163 | service_login_cb, | 226 | info); |
363 | 164 | info); | ||
364 | 165 | } | ||
372 | 166 | } | 227 | } |
373 | 167 | else | 228 | else |
374 | 168 | { | 229 | { |
375 | 169 | // Send notification that account has been disabled | 230 | // Send notification that account has been disabled |
377 | 170 | info->account_client->callback(info_to_details(info)); | 231 | info->account_client->callback(info); |
378 | 171 | } | 232 | } |
379 | 172 | } | 233 | } |
380 | 173 | 234 | ||
381 | @@ -193,7 +254,7 @@ | |||
382 | 193 | if (account_client->service_name() == ag_service_get_name(service)) | 254 | if (account_client->service_name() == ag_service_get_name(service)) |
383 | 194 | { | 255 | { |
384 | 195 | std::shared_ptr<AgAccountService> account_service(ag_account_service_new(account.get(), service), g_object_unref); | 256 | std::shared_ptr<AgAccountService> account_service(ag_account_service_new(account.get(), service), g_object_unref); |
386 | 196 | std::shared_ptr<AccountInfo> info(new AccountInfo, [](AccountInfo* info){ info->account_client = nullptr; delete info; }); | 257 | std::shared_ptr<AccountInfo> info(new AccountInfo); |
387 | 197 | info->service_enabled = false; | 258 | info->service_enabled = false; |
388 | 198 | info->account_client = account_client; | 259 | info->account_client = account_client; |
389 | 199 | info->account_service.reset(reinterpret_cast<AgAccountService*>(g_object_ref(account_service.get())), g_object_unref); | 260 | info->account_service.reset(reinterpret_cast<AgAccountService*>(g_object_ref(account_service.get())), g_object_unref); |
390 | @@ -226,51 +287,95 @@ | |||
391 | 226 | : service_name_(service_name) | 287 | : service_name_(service_name) |
392 | 227 | , service_type_(service_type) | 288 | , service_type_(service_type) |
393 | 228 | , provider_name_(provider_name) | 289 | , provider_name_(provider_name) |
398 | 229 | , use_external_main_loop_(main_loop_select == OnlineAccountClient::RunInExternalMainLoop) | 290 | , main_loop_select_(main_loop_select) |
399 | 230 | , main_loop_is_running_(false) | 291 | , main_loop_is_running_(main_loop_select != OnlineAccountClient::CreateInternalMainLoop) |
396 | 231 | , client_stopping_(false) | ||
397 | 232 | , logins_busy_(0) | ||
400 | 233 | { | 292 | { |
401 | 293 | // Set up authentication pub/sub | ||
402 | 294 | std::string oa_id = provider_name + ":" + service_type + ":" + service_name; | ||
403 | 295 | RuntimeImpl::UPtr rt = RuntimeImpl::create(oa_id); | ||
404 | 296 | MiddlewareFactory mw_factory(rt.get()); | ||
405 | 297 | RuntimeConfig rt_config(""); | ||
406 | 298 | |||
407 | 299 | mw_ = mw_factory.create(oa_id, rt_config.default_middleware(), rt_config.default_middleware_configfile()); | ||
408 | 300 | if (main_loop_select == OnlineAccountClient::RunInExternalUiMainLoop) | ||
409 | 301 | { | ||
410 | 302 | // If this client was created by the shell, set up as the publisher | ||
411 | 303 | auth_publisher_ = mw_->create_publisher(oa_id); | ||
412 | 304 | } | ||
413 | 305 | else | ||
414 | 306 | { | ||
415 | 307 | // If this client was created by a scope, set up as a subscriber | ||
416 | 308 | auth_subscriber_ = mw_->create_subscriber(oa_id); | ||
417 | 309 | auth_subscriber_->message_received().connect(std::bind(&OnlineAccountClientImpl::auth_callback, this, std::placeholders::_1)); | ||
418 | 310 | } | ||
419 | 311 | |||
420 | 234 | // If we are responsible for the main loop | 312 | // If we are responsible for the main loop |
422 | 235 | if (!use_external_main_loop_) | 313 | if (main_loop_select_ == OnlineAccountClient::CreateInternalMainLoop) |
423 | 236 | { | 314 | { |
424 | 237 | // Wait here until either the main loop begins running, or the thread exits | 315 | // Wait here until either the main loop begins running, or the thread exits |
438 | 238 | std::unique_lock<std::mutex> lock(mutex_); | 316 | { |
439 | 239 | main_loop_thread_ = std::thread(&OnlineAccountClientImpl::main_loop_thread, this); | 317 | std::unique_lock<std::mutex> lock(mutex_); |
440 | 240 | cond_.wait(lock, [this] { return main_loop_is_running_; }); | 318 | main_loop_thread_ = std::thread(&OnlineAccountClientImpl::main_loop_thread, this); |
441 | 241 | } | 319 | cond_.wait_for(lock, std::chrono::seconds(5), [this] { return main_loop_is_running_; }); |
442 | 242 | 320 | } | |
443 | 243 | manager_.reset(ag_manager_new_for_service_type(service_type_.c_str()), g_object_unref); | 321 | if (!main_loop_is_running_) |
444 | 244 | 322 | { | |
445 | 245 | // Watch for changes to accounts | 323 | if (main_loop_) |
446 | 246 | account_enabled_signal_id_ = g_signal_connect(manager_.get(), "enabled-event", G_CALLBACK(account_enabled_cb), this); | 324 | { |
447 | 247 | account_deleted_signal_id_ = g_signal_connect(manager_.get(), "account-deleted", G_CALLBACK(account_deleted_cb), this); | 325 | // Quit the main loop, causing the thread to exit |
448 | 248 | 326 | g_main_loop_quit(main_loop_.get()); | |
449 | 249 | // Now check initial state | 327 | if (main_loop_thread_.joinable()) |
450 | 250 | refresh_service_statuses(); | 328 | { |
451 | 329 | main_loop_thread_.join(); | ||
452 | 330 | } | ||
453 | 331 | } | ||
454 | 332 | if (thread_exception_) | ||
455 | 333 | { | ||
456 | 334 | std::rethrow_exception(thread_exception_); | ||
457 | 335 | } | ||
458 | 336 | else | ||
459 | 337 | { | ||
460 | 338 | throw unity::ResourceException("OnlineAccountClientImpl(): main_loop_thread failed to start."); | ||
461 | 339 | } | ||
462 | 340 | } | ||
463 | 341 | } | ||
464 | 342 | else | ||
465 | 343 | { | ||
466 | 344 | construct(); | ||
467 | 345 | } | ||
468 | 251 | } | 346 | } |
469 | 252 | 347 | ||
470 | 253 | OnlineAccountClientImpl::~OnlineAccountClientImpl() | 348 | OnlineAccountClientImpl::~OnlineAccountClientImpl() |
471 | 254 | { | 349 | { |
491 | 255 | // Disconnect all signal handlers | 350 | { |
492 | 256 | g_signal_handler_disconnect(manager_.get(), account_enabled_signal_id_); | 351 | std::lock_guard<std::mutex> lock(mutex_); |
493 | 257 | g_signal_handler_disconnect(manager_.get(), account_deleted_signal_id_); | 352 | if (thread_exception_) |
494 | 258 | 353 | { | |
495 | 259 | for (auto info : accounts_) | 354 | try |
496 | 260 | { | 355 | { |
497 | 261 | g_signal_handler_disconnect(info.second->account_service.get(), info.second->service_update_signal_id_); | 356 | std::rethrow_exception(thread_exception_); |
498 | 262 | } | 357 | } |
499 | 263 | 358 | catch (std::exception const& e) | |
500 | 264 | // Wait until all currently running login sessions are done | 359 | { |
501 | 265 | { | 360 | std::cerr << "~OnlineAccountClientImpl(): main_loop_thread threw an exception: " << e.what() << std::endl; |
502 | 266 | std::unique_lock<std::mutex> lock(mutex_); | 361 | } |
503 | 267 | client_stopping_ = true; | 362 | catch (...) |
504 | 268 | } | 363 | { |
505 | 269 | flush_pending_sessions(); | 364 | std::cerr << "~OnlineAccountClientImpl(): main_loop_thread threw an unknown exception" << std::endl; |
506 | 270 | 365 | } | |
507 | 271 | // If we are responsible for the main loop, quit it on destruction | 366 | } |
508 | 272 | if (main_loop_) | 367 | } |
509 | 273 | { | 368 | |
510 | 369 | // If we are responsible for the main loop | ||
511 | 370 | if (main_loop_select_ == OnlineAccountClient::CreateInternalMainLoop) | ||
512 | 371 | { | ||
513 | 372 | // Invoke tear_down() from within the main loop | ||
514 | 373 | { | ||
515 | 374 | std::unique_lock<std::mutex> lock(mutex_); | ||
516 | 375 | g_main_context_invoke(main_loop_context_.get(), main_loop_is_stopping_cb, this); | ||
517 | 376 | cond_.wait(lock, [this] { return !main_loop_is_running_; }); | ||
518 | 377 | } | ||
519 | 378 | |||
520 | 274 | // Quit the main loop, causing the thread to exit | 379 | // Quit the main loop, causing the thread to exit |
521 | 275 | g_main_loop_quit(main_loop_.get()); | 380 | g_main_loop_quit(main_loop_.get()); |
522 | 276 | if (main_loop_thread_.joinable()) | 381 | if (main_loop_thread_.joinable()) |
523 | @@ -278,16 +383,32 @@ | |||
524 | 278 | main_loop_thread_.join(); | 383 | main_loop_thread_.join(); |
525 | 279 | } | 384 | } |
526 | 280 | } | 385 | } |
527 | 386 | else | ||
528 | 387 | { | ||
529 | 388 | tear_down(); | ||
530 | 389 | } | ||
531 | 281 | } | 390 | } |
532 | 282 | 391 | ||
533 | 283 | void OnlineAccountClientImpl::set_service_update_callback(OnlineAccountClient::ServiceUpdateCallback callback) | 392 | void OnlineAccountClientImpl::set_service_update_callback(OnlineAccountClient::ServiceUpdateCallback callback) |
534 | 284 | { | 393 | { |
536 | 285 | std::lock_guard<std::mutex> lock(callback_mutex_); | 394 | std::lock_guard<std::mutex> lock(mutex_); |
537 | 395 | if (thread_exception_) | ||
538 | 396 | { | ||
539 | 397 | std::rethrow_exception(thread_exception_); | ||
540 | 398 | } | ||
541 | 399 | |||
542 | 400 | std::lock_guard<std::mutex> callback_lock(callback_mutex_); | ||
543 | 286 | callback_ = callback; | 401 | callback_ = callback; |
544 | 287 | } | 402 | } |
545 | 288 | 403 | ||
546 | 289 | void OnlineAccountClientImpl::refresh_service_statuses() | 404 | void OnlineAccountClientImpl::refresh_service_statuses() |
547 | 290 | { | 405 | { |
548 | 406 | std::unique_lock<std::mutex> lock(mutex_); | ||
549 | 407 | if (thread_exception_) | ||
550 | 408 | { | ||
551 | 409 | std::rethrow_exception(thread_exception_); | ||
552 | 410 | } | ||
553 | 411 | |||
554 | 291 | std::shared_ptr<GList> enabled_accounts(ag_manager_list(manager_.get()), ag_manager_list_free); | 412 | std::shared_ptr<GList> enabled_accounts(ag_manager_list(manager_.get()), ag_manager_list_free); |
555 | 292 | GList* it; | 413 | GList* it; |
556 | 293 | for (it = enabled_accounts.get(); it; it = it->next) | 414 | for (it = enabled_accounts.get(); it; it = it->next) |
557 | @@ -297,19 +418,25 @@ | |||
558 | 297 | std::string provider_name = ag_account_get_provider_name(account.get()); | 418 | std::string provider_name = ag_account_get_provider_name(account.get()); |
559 | 298 | if (provider_name == provider_name_) | 419 | if (provider_name == provider_name_) |
560 | 299 | { | 420 | { |
561 | 421 | lock.unlock(); | ||
562 | 300 | account_enabled_cb(manager_.get(), account_id, this); | 422 | account_enabled_cb(manager_.get(), account_id, this); |
563 | 423 | lock.lock(); | ||
564 | 301 | } | 424 | } |
565 | 425 | flush_pending_session(account_id, lock); | ||
566 | 302 | } | 426 | } |
567 | 303 | flush_pending_sessions(); | ||
568 | 304 | } | 427 | } |
569 | 305 | 428 | ||
570 | 306 | std::vector<OnlineAccountClient::ServiceStatus> OnlineAccountClientImpl::get_service_statuses() | 429 | std::vector<OnlineAccountClient::ServiceStatus> OnlineAccountClientImpl::get_service_statuses() |
571 | 307 | { | 430 | { |
572 | 308 | std::lock_guard<std::mutex> lock(mutex_); | 431 | std::lock_guard<std::mutex> lock(mutex_); |
573 | 432 | if (thread_exception_) | ||
574 | 433 | { | ||
575 | 434 | std::rethrow_exception(thread_exception_); | ||
576 | 435 | } | ||
577 | 309 | 436 | ||
578 | 310 | // Return all service statuses | 437 | // Return all service statuses |
579 | 311 | std::vector<OnlineAccountClient::ServiceStatus> service_statuses; | 438 | std::vector<OnlineAccountClient::ServiceStatus> service_statuses; |
581 | 312 | for (auto const info : accounts_) | 439 | for (auto const& info : accounts_) |
582 | 313 | { | 440 | { |
583 | 314 | service_statuses.push_back(info_to_details(info.second.get())); | 441 | service_statuses.push_back(info_to_details(info.second.get())); |
584 | 315 | } | 442 | } |
585 | @@ -352,42 +479,112 @@ | |||
586 | 352 | widget.add_attribute_value("online_account_details", Variant(account_details_map)); | 479 | widget.add_attribute_value("online_account_details", Variant(account_details_map)); |
587 | 353 | } | 480 | } |
588 | 354 | 481 | ||
591 | 355 | void OnlineAccountClientImpl::flush_pending_sessions() | 482 | void OnlineAccountClientImpl::construct() |
592 | 356 | { | 483 | { |
593 | 484 | manager_.reset(ag_manager_new_for_service_type(service_type_.c_str()), g_object_unref); | ||
594 | 485 | |||
595 | 486 | // Watch for changes to accounts | ||
596 | 487 | account_enabled_signal_id_ = g_signal_connect(manager_.get(), "enabled-event", G_CALLBACK(account_enabled_cb), this); | ||
597 | 488 | account_deleted_signal_id_ = g_signal_connect(manager_.get(), "account-deleted", G_CALLBACK(account_deleted_cb), this); | ||
598 | 489 | |||
599 | 490 | // Now check initial state | ||
600 | 491 | refresh_service_statuses(); | ||
601 | 492 | } | ||
602 | 493 | |||
603 | 494 | void OnlineAccountClientImpl::tear_down() | ||
604 | 495 | { | ||
605 | 496 | // Disconnect signal handlers | ||
606 | 497 | g_signal_handler_disconnect(manager_.get(), account_enabled_signal_id_); | ||
607 | 498 | g_signal_handler_disconnect(manager_.get(), account_deleted_signal_id_); | ||
608 | 499 | |||
609 | 500 | // Remove all accounts | ||
610 | 501 | { | ||
611 | 502 | std::unique_lock<std::mutex> lock(mutex_); | ||
612 | 503 | for (auto const& info : accounts_) | ||
613 | 504 | { | ||
614 | 505 | // Before we nuke the map, ensure that any pending sessions are done | ||
615 | 506 | g_signal_handler_disconnect(info.second->account_service.get(), info.second->service_update_signal_id_); | ||
616 | 507 | clear_session(info.second.get()); | ||
617 | 508 | flush_pending_session(info.second->account_id, lock); | ||
618 | 509 | } | ||
619 | 510 | accounts_.clear(); | ||
620 | 511 | } | ||
621 | 512 | } | ||
622 | 513 | |||
623 | 514 | void OnlineAccountClientImpl::flush_pending_session(AgAccountId const& account_id, std::unique_lock<std::mutex>& lock) | ||
624 | 515 | { | ||
625 | 516 | // Get account info | ||
626 | 517 | auto info_it = accounts_.find(account_id); | ||
627 | 518 | if (info_it == accounts_.end()) | ||
628 | 519 | { | ||
629 | 520 | return; | ||
630 | 521 | } | ||
631 | 522 | auto info = info_it->second; | ||
632 | 523 | |||
633 | 357 | // Wait until all currently running login sessions are done | 524 | // Wait until all currently running login sessions are done |
634 | 358 | // (ensures that accounts_ is up to date) | 525 | // (ensures that accounts_ is up to date) |
636 | 359 | std::unique_lock<std::mutex> lock(mutex_); | 526 | std::shared_ptr<GMainLoop> event_loop; |
637 | 527 | event_loop.reset(g_main_loop_new(g_main_context_get_thread_default(), true), g_main_loop_unref); | ||
638 | 528 | while(info->session) | ||
639 | 360 | { | 529 | { |
651 | 361 | std::shared_ptr<GMainLoop> event_loop; | 530 | // We need to wait inside an event loop to allow for the main application loop to |
652 | 362 | event_loop.reset(g_main_loop_new(nullptr, true), g_main_loop_unref); | 531 | // process its pending events |
653 | 363 | while(logins_busy_ > 0) | 532 | std::shared_ptr<GSource> source; |
654 | 364 | { | 533 | source.reset(g_timeout_source_new(10), g_source_unref); |
655 | 365 | // We need to wait inside an event loop to allow for the main application loop to | 534 | g_source_set_callback(source.get(), wake_up_event_loop_cb, event_loop.get(), NULL); |
656 | 366 | // process its pending events | 535 | g_source_attach(source.get(), g_main_context_get_thread_default()); |
657 | 367 | g_timeout_add(100, wake_up_event_loop_cb, event_loop.get()); | 536 | |
658 | 368 | lock.unlock(); | 537 | lock.unlock(); |
659 | 369 | g_main_loop_run(event_loop.get()); | 538 | g_main_loop_run(event_loop.get()); |
660 | 370 | lock.lock(); | 539 | lock.lock(); |
650 | 371 | } | ||
661 | 372 | } | 540 | } |
662 | 373 | } | 541 | } |
663 | 374 | 542 | ||
664 | 375 | void OnlineAccountClientImpl::main_loop_state_notify(bool is_running) | 543 | void OnlineAccountClientImpl::main_loop_state_notify(bool is_running) |
665 | 376 | { | 544 | { |
666 | 545 | bool was_running = false; | ||
667 | 546 | { | ||
668 | 547 | std::lock_guard<std::mutex> lock(mutex_); | ||
669 | 548 | was_running = main_loop_is_running_; | ||
670 | 549 | } | ||
671 | 550 | if (!was_running && is_running) | ||
672 | 551 | { | ||
673 | 552 | construct(); | ||
674 | 553 | } | ||
675 | 554 | else if (was_running && !is_running) | ||
676 | 555 | { | ||
677 | 556 | tear_down(); | ||
678 | 557 | } | ||
679 | 558 | |||
680 | 377 | std::lock_guard<std::mutex> lock(mutex_); | 559 | std::lock_guard<std::mutex> lock(mutex_); |
681 | 378 | main_loop_is_running_ = is_running; | 560 | main_loop_is_running_ = is_running; |
682 | 379 | cond_.notify_all(); | 561 | cond_.notify_all(); |
683 | 380 | } | 562 | } |
684 | 381 | 563 | ||
685 | 564 | std::shared_ptr<AgManager> OnlineAccountClientImpl::manager() | ||
686 | 565 | { | ||
687 | 566 | return manager_; | ||
688 | 567 | } | ||
689 | 568 | |||
690 | 382 | std::string OnlineAccountClientImpl::service_name() | 569 | std::string OnlineAccountClientImpl::service_name() |
691 | 383 | { | 570 | { |
692 | 384 | std::lock_guard<std::mutex> lock(mutex_); | 571 | std::lock_guard<std::mutex> lock(mutex_); |
693 | 385 | return service_name_; | 572 | return service_name_; |
694 | 386 | } | 573 | } |
695 | 387 | 574 | ||
697 | 388 | void OnlineAccountClientImpl::callback(OnlineAccountClient::ServiceStatus const& service_status) | 575 | OnlineAccountClient::MainLoopSelect OnlineAccountClientImpl::main_loop_select() |
698 | 576 | { | ||
699 | 577 | return main_loop_select_; | ||
700 | 578 | } | ||
701 | 579 | |||
702 | 580 | void OnlineAccountClientImpl::callback(AccountInfo const* info, std::string const& error) | ||
703 | 389 | { | 581 | { |
704 | 390 | std::lock_guard<std::mutex> lock(callback_mutex_); | 582 | std::lock_guard<std::mutex> lock(callback_mutex_); |
705 | 583 | auto service_status = info_to_details(info, error); | ||
706 | 584 | if (service_status.service_authenticated && auth_publisher_) | ||
707 | 585 | { | ||
708 | 586 | auth_publisher_->send_message(details_to_json(service_status)); | ||
709 | 587 | } | ||
710 | 391 | if (callback_) | 588 | if (callback_) |
711 | 392 | { | 589 | { |
712 | 393 | callback_(service_status); | 590 | callback_(service_status); |
713 | @@ -408,42 +605,80 @@ | |||
714 | 408 | 605 | ||
715 | 409 | void OnlineAccountClientImpl::remove_account(AgAccountId const& account_id) | 606 | void OnlineAccountClientImpl::remove_account(AgAccountId const& account_id) |
716 | 410 | { | 607 | { |
718 | 411 | std::lock_guard<std::mutex> lock(mutex_); | 608 | std::unique_lock<std::mutex> lock(mutex_); |
719 | 609 | |||
720 | 610 | // Get account info | ||
721 | 611 | auto info_it = accounts_.find(account_id); | ||
722 | 612 | if (info_it == accounts_.end()) | ||
723 | 613 | { | ||
724 | 614 | return; | ||
725 | 615 | } | ||
726 | 616 | auto info = info_it->second; | ||
727 | 617 | |||
728 | 618 | // Before we nuke the pointer, ensure that any pending sessions are done | ||
729 | 619 | g_signal_handler_disconnect(info->account_service.get(), info->service_update_signal_id_); | ||
730 | 620 | clear_session(info.get()); | ||
731 | 621 | flush_pending_session(account_id, lock); | ||
732 | 622 | |||
733 | 623 | // Remove account info from accounts_ map | ||
734 | 412 | accounts_.erase(account_id); | 624 | accounts_.erase(account_id); |
735 | 413 | } | 625 | } |
736 | 414 | 626 | ||
737 | 415 | bool OnlineAccountClientImpl::inc_logins() | ||
738 | 416 | { | ||
739 | 417 | std::lock_guard<std::mutex> lock(mutex_); | ||
740 | 418 | if (!client_stopping_) | ||
741 | 419 | { | ||
742 | 420 | // Increment number of logins busy | ||
743 | 421 | ++logins_busy_; | ||
744 | 422 | return true; | ||
745 | 423 | } | ||
746 | 424 | // Client is stopping so don't increment | ||
747 | 425 | return false; | ||
748 | 426 | } | ||
749 | 427 | |||
750 | 428 | void OnlineAccountClientImpl::dec_logins() | ||
751 | 429 | { | ||
752 | 430 | // Decrement number of logins busy | ||
753 | 431 | std::lock_guard<std::mutex> lock(mutex_); | ||
754 | 432 | --logins_busy_; | ||
755 | 433 | } | ||
756 | 434 | |||
757 | 435 | void OnlineAccountClientImpl::main_loop_thread() | 627 | void OnlineAccountClientImpl::main_loop_thread() |
758 | 436 | { | 628 | { |
769 | 437 | // If something goes wrong causing the main loop not to run, the destruction of this pointer | 629 | // If something goes wrong causing the thread to abort, the destruction of this pointer update the |
770 | 438 | // will break the constructor from its wait | 630 | // main_loop_is_running_ state accordingly. |
771 | 439 | std::shared_ptr<void> thread_exit_notifier(nullptr, [this](void*){ main_loop_state_notify(true); }); | 631 | std::shared_ptr<void> thread_exit_notifier(nullptr, [this](void*){ main_loop_state_notify(false); }); |
772 | 440 | 632 | ||
773 | 441 | // Stick a method call into the main loop to notify the constructor when the main loop begins running | 633 | try |
774 | 442 | g_idle_add(main_loop_is_running_cb, this); | 634 | { |
775 | 443 | 635 | main_loop_context_.reset(g_main_context_new(), g_main_context_unref); | |
776 | 444 | // Run the main loop | 636 | g_main_context_push_thread_default(main_loop_context_.get()); |
777 | 445 | main_loop_.reset(g_main_loop_new(nullptr, true), g_main_loop_unref); | 637 | |
778 | 446 | g_main_loop_run(main_loop_.get()); | 638 | // Stick a method call into the main loop to notify the constructor when the main loop begins running |
779 | 639 | g_main_context_invoke(main_loop_context_.get(), main_loop_is_running_cb, this); | ||
780 | 640 | |||
781 | 641 | // Run the main loop | ||
782 | 642 | main_loop_.reset(g_main_loop_new(main_loop_context_.get(), true), g_main_loop_unref); | ||
783 | 643 | g_main_loop_run(main_loop_.get()); | ||
784 | 644 | } | ||
785 | 645 | catch (std::exception const& e) | ||
786 | 646 | { | ||
787 | 647 | std::cerr << "OnlineAccountClientImpl::main_loop_thread(): Thread aborted: " << e.what() << std::endl; | ||
788 | 648 | std::lock_guard<std::mutex> lock(mutex_); | ||
789 | 649 | thread_exception_ = std::current_exception(); | ||
790 | 650 | } | ||
791 | 651 | catch (...) | ||
792 | 652 | { | ||
793 | 653 | std::cerr << "OnlineAccountClientImpl::main_loop_thread(): Thread aborted: unknown exception" << std::endl; | ||
794 | 654 | std::lock_guard<std::mutex> lock(mutex_); | ||
795 | 655 | thread_exception_ = std::current_exception(); | ||
796 | 656 | } | ||
797 | 657 | } | ||
798 | 658 | |||
799 | 659 | void OnlineAccountClientImpl::auth_callback(std::string const& details_json) | ||
800 | 660 | { | ||
801 | 661 | OnlineAccountClient::ServiceStatus details = json_to_details(details_json); | ||
802 | 662 | |||
803 | 663 | // Update account info | ||
804 | 664 | { | ||
805 | 665 | std::lock_guard<std::mutex> lock(mutex_); | ||
806 | 666 | auto info_it = accounts_.find(details.account_id); | ||
807 | 667 | if (info_it == accounts_.end()) | ||
808 | 668 | { | ||
809 | 669 | return; | ||
810 | 670 | } | ||
811 | 671 | auto info = info_it->second; | ||
812 | 672 | |||
813 | 673 | GVariantDict dict; | ||
814 | 674 | g_variant_dict_init(&dict, nullptr); | ||
815 | 675 | g_variant_dict_insert(&dict, "AccessToken", "s", details.access_token.c_str()); | ||
816 | 676 | g_variant_dict_insert(&dict, "TokenSecret", "s", details.token_secret.c_str()); | ||
817 | 677 | info->session_data.reset(g_variant_ref_sink(g_variant_dict_end(&dict)), free_variant); | ||
818 | 678 | } | ||
819 | 679 | |||
820 | 680 | std::lock_guard<std::mutex> lock(callback_mutex_); | ||
821 | 681 | callback_(details); | ||
822 | 447 | } | 682 | } |
823 | 448 | 683 | ||
824 | 449 | } // namespace internal | 684 | } // namespace internal |
825 | 450 | 685 | ||
826 | === modified file 'src/scopes/internal/RegistryObject.cpp' | |||
827 | --- src/scopes/internal/RegistryObject.cpp 2014-09-15 18:33:08 +0000 | |||
828 | +++ src/scopes/internal/RegistryObject.cpp 2014-10-08 10:59:41 +0000 | |||
829 | @@ -33,6 +33,7 @@ | |||
830 | 33 | #include <cassert> | 33 | #include <cassert> |
831 | 34 | #include <fstream> | 34 | #include <fstream> |
832 | 35 | #include <wordexp.h> | 35 | #include <wordexp.h> |
833 | 36 | #include <iostream> | ||
834 | 36 | 37 | ||
835 | 37 | using namespace std; | 38 | using namespace std; |
836 | 38 | 39 | ||
837 | @@ -385,7 +386,16 @@ | |||
838 | 385 | desktop_file << "Type=Application" << std::endl; | 386 | desktop_file << "Type=Application" << std::endl; |
839 | 386 | desktop_file << "NoDisplay=true" << std::endl; | 387 | desktop_file << "NoDisplay=true" << std::endl; |
840 | 387 | desktop_file << "Name=" << metadata.display_name() << std::endl; | 388 | desktop_file << "Name=" << metadata.display_name() << std::endl; |
842 | 388 | desktop_file << "Icon=" << metadata.icon() << std::endl; | 389 | desktop_file << "Icon="; |
843 | 390 | try | ||
844 | 391 | { | ||
845 | 392 | desktop_file << metadata.icon(); | ||
846 | 393 | } | ||
847 | 394 | catch (NotFoundException const&) | ||
848 | 395 | { | ||
849 | 396 | // Icon is optional. | ||
850 | 397 | } | ||
851 | 398 | desktop_file << endl; | ||
852 | 389 | desktop_file.close(); | 399 | desktop_file.close(); |
853 | 390 | } | 400 | } |
854 | 391 | 401 | ||
855 | 392 | 402 | ||
856 | === modified file 'test/gtest/scopes/OnlineAccountClient/OnlineAccountClient_test.cpp' | |||
857 | --- test/gtest/scopes/OnlineAccountClient/OnlineAccountClient_test.cpp 2014-09-10 08:57:42 +0000 | |||
858 | +++ test/gtest/scopes/OnlineAccountClient/OnlineAccountClient_test.cpp 2014-10-08 10:59:41 +0000 | |||
859 | @@ -25,6 +25,8 @@ | |||
860 | 25 | 25 | ||
861 | 26 | TEST(OnlineAccountClient, basic) | 26 | TEST(OnlineAccountClient, basic) |
862 | 27 | { | 27 | { |
863 | 28 | setenv("XDG_RUNTIME_DIR", "/tmp", true); | ||
864 | 29 | |||
865 | 28 | OnlineAccountClient oa_client("com.ubuntu.scopes.youtube_youtube", "sharing", "google"); | 30 | OnlineAccountClient oa_client("com.ubuntu.scopes.youtube_youtube", "sharing", "google"); |
866 | 29 | auto service_statuses = oa_client.get_service_statuses(); | 31 | auto service_statuses = oa_client.get_service_statuses(); |
867 | 30 | } | 32 | } |
PASSED: Continuous integration, rev:263 jenkins. qa.ubuntu. com/job/ unity-scopes- api-ci/ 473/ jenkins. qa.ubuntu. com/job/ unity-scopes- api-utopic- amd64-ci/ 100 jenkins. qa.ubuntu. com/job/ unity-scopes- api-utopic- armhf-ci/ 100 jenkins. qa.ubuntu. com/job/ unity-scopes- api-utopic- armhf-ci/ 100/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ unity-scopes- api-utopic- i386-ci/ 100
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- scopes- api-ci/ 473/rebuild
http://