[evolution-data-server] Bug 750964 - Backend online state not updated before calling open()
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Bug 750964 - Backend online state not updated before calling open()
- Date: Thu, 3 Sep 2015 11:47:21 +0000 (UTC)
commit b5df9b2abe8a2f76176292dab853070946b7fdf6
Author: Milan Crha <mcrha redhat com>
Date: Thu Sep 3 13:45:41 2015 +0200
Bug 750964 - Backend online state not updated before calling open()
addressbook/libedata-book/e-book-backend.c | 4 ++
calendar/backends/caldav/e-cal-backend-caldav.c | 5 ++-
calendar/libedata-cal/e-cal-backend.c | 2 +
docs/reference/eds/eds-sections.txt | 1 +
libebackend/e-backend.c | 47 ++++++++++++++++++++++-
libebackend/e-backend.h | 3 +
6 files changed, 60 insertions(+), 2 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend.c b/addressbook/libedata-book/e-book-backend.c
index 962889f..dce04ce 100644
--- a/addressbook/libedata-book/e-book-backend.c
+++ b/addressbook/libedata-book/e-book-backend.c
@@ -1099,6 +1099,8 @@ book_backend_open_thread (GSimpleAsyncResult *simple,
if (!e_book_backend_is_opened (backend)) {
GError *error = NULL;
+ e_backend_ensure_online_state_updated (E_BACKEND (backend), cancellable);
+
class->open_sync (backend, cancellable, &error);
if (error != NULL)
@@ -1137,6 +1139,8 @@ book_backend_open_thread_old_style (GSimpleAsyncResult *simple,
opid = book_backend_stash_operation (backend, simple);
+ e_backend_ensure_online_state_updated (E_BACKEND (backend), cancellable);
+
class->open (backend, data_book, opid, cancellable, FALSE);
}
diff --git a/calendar/backends/caldav/e-cal-backend-caldav.c b/calendar/backends/caldav/e-cal-backend-caldav.c
index 9c77aef..51ec4ba 100644
--- a/calendar/backends/caldav/e-cal-backend-caldav.c
+++ b/calendar/backends/caldav/e-cal-backend-caldav.c
@@ -5551,7 +5551,10 @@ caldav_backend_initable_init (GInitable *initable,
auth_method = e_source_authentication_dup_method (extension);
}
- if (g_strcmp0 (auth_method, "OAuth2") == 0) {
+ e_backend_ensure_online_state_updated (E_BACKEND (initable), cancellable);
+
+ if (g_strcmp0 (auth_method, "OAuth2") == 0 &&
+ e_backend_get_online (E_BACKEND (initable))) {
ESourceWebdav *extension;
SoupAuth *soup_auth;
SoupURI *soup_uri;
diff --git a/calendar/libedata-cal/e-cal-backend.c b/calendar/libedata-cal/e-cal-backend.c
index 68febe7..53bd7ae 100644
--- a/calendar/libedata-cal/e-cal-backend.c
+++ b/calendar/libedata-cal/e-cal-backend.c
@@ -1555,6 +1555,8 @@ cal_backend_open_thread (GSimpleAsyncResult *simple,
opid = cal_backend_stash_operation (backend, simple);
+ e_backend_ensure_online_state_updated (E_BACKEND (backend), cancellable);
+
class->open (backend, data_cal, opid, cancellable, FALSE);
}
diff --git a/docs/reference/eds/eds-sections.txt b/docs/reference/eds/eds-sections.txt
index 8b79f37..077aa1d 100644
--- a/docs/reference/eds/eds-sections.txt
+++ b/docs/reference/eds/eds-sections.txt
@@ -19,6 +19,7 @@ EBackend
EBackendClass
e_backend_get_online
e_backend_set_online
+e_backend_ensure_online_state_updated
e_backend_get_source
e_backend_ref_connectable
e_backend_set_connectable
diff --git a/libebackend/e-backend.c b/libebackend/e-backend.c
index 57d4ec0..332b528 100644
--- a/libebackend/e-backend.c
+++ b/libebackend/e-backend.c
@@ -722,7 +722,6 @@ e_backend_init (EBackend *backend)
backend->priv = E_BACKEND_GET_PRIVATE (backend);
backend->priv->prompter = e_user_prompter_new ();
backend->priv->main_context = g_main_context_ref_thread_default ();
- backend->priv->online = TRUE;
g_mutex_init (&backend->priv->property_lock);
g_mutex_init (&backend->priv->update_online_state_lock);
@@ -735,6 +734,7 @@ e_backend_init (EBackend *backend)
network_monitor = g_network_monitor_get_default ();
backend->priv->network_monitor = g_object_ref (network_monitor);
+ backend->priv->online = g_network_monitor_get_network_available (network_monitor);
handler_id = g_signal_connect (
backend->priv->network_monitor, "network-changed",
@@ -805,6 +805,51 @@ e_backend_set_online (EBackend *backend,
}
/**
+ * e_backend_ensure_online_state_updated:
+ * @backend: an #EBackend
+ * @cancellable: optional #GCancellable object, or %NULL
+ *
+ * Makes sure that the "online" property is updated, that is, if there
+ * is any destination reachability test pending, it'll be done immediately
+ * and the only state will be updated as well.
+ *
+ * Since: 3.18
+ **/
+void
+e_backend_ensure_online_state_updated (EBackend *backend,
+ GCancellable *cancellable)
+{
+ gboolean needs_update = FALSE;
+
+ g_return_if_fail (E_IS_BACKEND (backend));
+
+ g_object_ref (backend);
+
+ g_mutex_lock (&backend->priv->update_online_state_lock);
+
+ if (backend->priv->update_online_state) {
+ g_source_destroy (backend->priv->update_online_state);
+ g_source_unref (backend->priv->update_online_state);
+ backend->priv->update_online_state = NULL;
+
+ needs_update = TRUE;
+ }
+
+ g_mutex_unlock (&backend->priv->update_online_state_lock);
+
+ if (!needs_update) {
+ g_mutex_lock (&backend->priv->network_monitor_cancellable_lock);
+ needs_update = backend->priv->network_monitor_cancellable != NULL;
+ g_mutex_unlock (&backend->priv->network_monitor_cancellable_lock);
+ }
+
+ if (needs_update)
+ e_backend_set_online (backend, e_backend_is_destination_reachable (backend, cancellable,
NULL));
+
+ g_object_unref (backend);
+}
+
+/**
* e_backend_get_source:
* @backend: an #EBackend
*
diff --git a/libebackend/e-backend.h b/libebackend/e-backend.h
index 0014379..85130bb 100644
--- a/libebackend/e-backend.h
+++ b/libebackend/e-backend.h
@@ -104,6 +104,9 @@ GType e_backend_get_type (void) G_GNUC_CONST;
gboolean e_backend_get_online (EBackend *backend);
void e_backend_set_online (EBackend *backend,
gboolean online);
+void e_backend_ensure_online_state_updated
+ (EBackend *backend,
+ GCancellable *cancellable);
ESource * e_backend_get_source (EBackend *backend);
GSocketConnectable *
e_backend_ref_connectable (EBackend *backend);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]