[epiphany/wip/sync: 22/31] sync-service: Discard _send_next_storage_request()
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/sync: 22/31] sync-service: Discard _send_next_storage_request()
- Date: Fri, 14 Apr 2017 15:53:24 +0000 (UTC)
commit e0d4060071cce4221494120f659a010cab07b1cf
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date: Thu Apr 13 10:45:33 2017 +0300
sync-service: Discard _send_next_storage_request()
src/sync/ephy-sync-service.c | 175 +++++++++++++++++++-----------------------
1 files changed, 79 insertions(+), 96 deletions(-)
---
diff --git a/src/sync/ephy-sync-service.c b/src/sync/ephy-sync-service.c
index 3d87281..5a91f36 100644
--- a/src/sync/ephy-sync-service.c
+++ b/src/sync/ephy-sync-service.c
@@ -121,8 +121,6 @@ typedef struct {
EphySynchronizable *synchronizable;
} SyncAsyncData;
-static void ephy_sync_service_send_next_storage_request (EphySyncService *self);
-
static StorageRequestAsyncData *
storage_request_async_data_new (const char *endpoint,
const char *method,
@@ -375,6 +373,61 @@ ephy_sync_service_fxa_hawk_get_async (EphySyncService *self,
ephy_sync_crypto_hawk_header_free (hheader);
}
+static void
+ephy_sync_service_send_storage_request (EphySyncService *self,
+ StorageRequestAsyncData *data)
+{
+ SyncCryptoHawkOptions *hoptions = NULL;
+ SyncCryptoHawkHeader *hheader;
+ SoupMessage *msg;
+ char *url;
+ char *if_modified_since = NULL;
+ char *if_unmodified_since = NULL;
+ const char *content_type = "application/json";
+
+ g_assert (EPHY_IS_SYNC_SERVICE (self));
+ g_assert (data);
+
+ url = g_strdup_printf ("%s/%s", self->storage_endpoint, data->endpoint);
+ msg = soup_message_new (data->method, url);
+
+ if (data->request_body) {
+ hoptions = ephy_sync_crypto_hawk_options_new (NULL, NULL, NULL, content_type,
+ NULL, NULL, NULL, data->request_body, NULL);
+ soup_message_set_request (msg, content_type, SOUP_MEMORY_COPY,
+ data->request_body, strlen (data->request_body));
+ }
+
+ if (!g_strcmp0 (data->method, SOUP_METHOD_POST))
+ soup_message_headers_append (msg->request_headers, "content-type", content_type);
+
+ if (data->modified_since >= 0) {
+ if_modified_since = g_strdup_printf ("%.2lf", data->modified_since);
+ soup_message_headers_append (msg->request_headers, "X-If-Modified-Since", if_modified_since);
+ }
+
+ if (data->unmodified_since >= 0) {
+ if_unmodified_since = g_strdup_printf ("%.2lf", data->unmodified_since);
+ soup_message_headers_append (msg->request_headers, "X-If-Unmodified-Since", if_unmodified_since);
+ }
+
+ hheader = ephy_sync_crypto_compute_hawk_header (url, data->method, self->storage_credentials_id,
+ (guint8 *)self->storage_credentials_key,
+ strlen (self->storage_credentials_key),
+ hoptions);
+ soup_message_headers_append (msg->request_headers, "authorization", hheader->header);
+ soup_session_queue_message (self->session, msg, data->callback, data->user_data);
+
+ if (hoptions)
+ ephy_sync_crypto_hawk_options_free (hoptions);
+
+ g_free (url);
+ g_free (if_modified_since);
+ g_free (if_unmodified_since);
+ ephy_sync_crypto_hawk_header_free (hheader);
+ storage_request_async_data_free (data);
+}
+
static gboolean
ephy_sync_service_certificate_is_valid (EphySyncService *self,
const char *certificate)
@@ -574,8 +627,10 @@ free_node:
json_node_unref (node);
out:
self->locked = FALSE;
- if (!is_internal_error)
- ephy_sync_service_send_next_storage_request (self);
+ if (!is_internal_error) {
+ while (!g_queue_is_empty (self->storage_queue))
+ ephy_sync_service_send_storage_request (self, g_queue_pop_head (self->storage_queue));
+ }
}
static char *
@@ -780,83 +835,6 @@ ephy_sync_service_obtain_signed_certificate (EphySyncService *self)
}
static void
-ephy_sync_service_send_storage_request (EphySyncService *self,
- StorageRequestAsyncData *data)
-{
- SyncCryptoHawkOptions *hoptions = NULL;
- SyncCryptoHawkHeader *hheader;
- SoupMessage *msg;
- char *url;
- char *if_modified_since = NULL;
- char *if_unmodified_since = NULL;
- const char *content_type = "application/json";
-
- g_assert (EPHY_IS_SYNC_SERVICE (self));
- g_assert (data);
-
- url = g_strdup_printf ("%s/%s", self->storage_endpoint, data->endpoint);
- msg = soup_message_new (data->method, url);
-
- if (data->request_body) {
- hoptions = ephy_sync_crypto_hawk_options_new (NULL, NULL, NULL, content_type,
- NULL, NULL, NULL, data->request_body, NULL);
- soup_message_set_request (msg, content_type, SOUP_MEMORY_COPY,
- data->request_body, strlen (data->request_body));
- }
-
- if (!g_strcmp0 (data->method, SOUP_METHOD_POST))
- soup_message_headers_append (msg->request_headers, "content-type", content_type);
-
- if (data->modified_since >= 0) {
- if_modified_since = g_strdup_printf ("%.2lf", data->modified_since);
- soup_message_headers_append (msg->request_headers, "X-If-Modified-Since", if_modified_since);
- }
-
- if (data->unmodified_since >= 0) {
- if_unmodified_since = g_strdup_printf ("%.2lf", data->unmodified_since);
- soup_message_headers_append (msg->request_headers, "X-If-Unmodified-Since", if_unmodified_since);
- }
-
- hheader = ephy_sync_crypto_compute_hawk_header (url, data->method, self->storage_credentials_id,
- (guint8 *)self->storage_credentials_key,
- strlen (self->storage_credentials_key),
- hoptions);
- soup_message_headers_append (msg->request_headers, "authorization", hheader->header);
- soup_session_queue_message (self->session, msg, data->callback, data->user_data);
-
- if (hoptions)
- ephy_sync_crypto_hawk_options_free (hoptions);
-
- g_free (url);
- g_free (if_modified_since);
- g_free (if_unmodified_since);
- ephy_sync_crypto_hawk_header_free (hheader);
- storage_request_async_data_free (data);
-}
-
-static void
-ephy_sync_service_send_next_storage_request (EphySyncService *self)
-{
- g_assert (EPHY_IS_SYNC_SERVICE (self));
-
- if (self->locked || g_queue_is_empty (self->storage_queue))
- return;
-
- /* If the storage credentials are valid, then directly send the request.
- * Otherwise, the request will remain queued and scheduled to be sent when
- * the new credentials are obtained. */
- if (!ephy_sync_service_storage_credentials_is_expired (self)) {
- ephy_sync_service_send_storage_request (self, g_queue_pop_head (self->storage_queue));
- } else {
- /* Mark as locked so other requests won't lead to conflicts while obtaining
- * new storage credentials. */
- self->locked = TRUE;
- ephy_sync_service_clear_storage_credentials (self);
- ephy_sync_service_obtain_signed_certificate (self);
- }
-}
-
-static void
ephy_sync_service_queue_storage_request (EphySyncService *self,
const char *endpoint,
const char *method,
@@ -866,16 +844,31 @@ ephy_sync_service_queue_storage_request (EphySyncService *self,
SoupSessionCallback callback,
gpointer user_data)
{
+ StorageRequestAsyncData *data;
+
g_assert (EPHY_IS_SYNC_SERVICE (self));
g_assert (endpoint);
g_assert (method);
- g_queue_push_tail (self->storage_queue,
- storage_request_async_data_new (endpoint, method, request_body,
- modified_since, unmodified_since,
- callback, user_data));
+ data = storage_request_async_data_new (endpoint, method, request_body,
+ modified_since, unmodified_since,
+ callback, user_data);
- ephy_sync_service_send_next_storage_request (self);
+ /* If the storage credentials are valid, then directly send the request.
+ * Otherwise, the request will remain queued and scheduled to be sent when
+ * the new credentials are obtained. */
+ if (!ephy_sync_service_storage_credentials_is_expired (self)) {
+ ephy_sync_service_send_storage_request (self, data);
+ } else {
+ g_queue_push_tail (self->storage_queue, data);
+ if (!self->locked) {
+ /* Mark as locked so other requests won't lead to conflicts while obtaining
+ * new storage credentials. */
+ self->locked = TRUE;
+ ephy_sync_service_clear_storage_credentials (self);
+ ephy_sync_service_obtain_signed_certificate (self);
+ }
+ }
}
static void
@@ -931,7 +924,6 @@ free_bundle:
json_node_unref (node);
out:
sync_async_data_free (data);
- ephy_sync_service_send_next_storage_request (self);
}
static void
@@ -989,7 +981,6 @@ upload_synchronizable_cb (SoupSession *session,
}
sync_async_data_free (data);
- ephy_sync_service_send_next_storage_request (self);
}
static void
@@ -1120,7 +1111,6 @@ out:
g_signal_emit (self, signals[SYNC_FINISHED], 0);
sync_collection_async_data_free (data);
- ephy_sync_service_send_next_storage_request (self);
}
static void
@@ -1553,7 +1543,6 @@ out:
ephy_sync_service_report_sign_in_error (self,
_("Failed to retrieve crypto keys."),
TRUE);
- ephy_sync_service_send_next_storage_request (self);
}
static void
@@ -1650,7 +1639,6 @@ out:
TRUE);
g_free (message);
}
- ephy_sync_service_send_next_storage_request (self);
}
static void
@@ -1843,17 +1831,12 @@ delete_synchronizable_cb (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- EphySyncService *self;
-
if (msg->status_code == 200) {
LOG ("Successfully deleted from server");
} else {
g_warning ("Failed to delete object. Status code: %u, response: %s",
msg->status_code, msg->response_body->data);
}
-
- self = ephy_shell_get_sync_service (ephy_shell_get_default ());
- ephy_sync_service_send_next_storage_request (self);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]