[epiphany] password-manager: Delete old legacy functions



commit c9fb12239c5aaee6c30cfa8e06bef93c545aec36
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date:   Fri Sep 22 23:34:34 2017 +0300

    password-manager: Delete old legacy functions

 lib/sync/ephy-password-manager.c |  159 +++++++++++++++-----------------------
 lib/sync/ephy-password-manager.h |   11 ---
 2 files changed, 61 insertions(+), 109 deletions(-)
---
diff --git a/lib/sync/ephy-password-manager.c b/lib/sync/ephy-password-manager.c
index 437ee22..bf8b6f7 100644
--- a/lib/sync/ephy-password-manager.c
+++ b/lib/sync/ephy-password-manager.c
@@ -73,7 +73,7 @@ typedef struct {
 typedef struct {
   EphyPasswordManager *manager;
   EphyPasswordRecord  *record;
-} ReplaceRecordAsyncData;
+} ManageRecordAsyncData;
 
 typedef struct {
   EphyPasswordManager                    *manager;
@@ -158,13 +158,13 @@ merge_passwords_async_data_free (MergePasswordsAsyncData *data)
   g_slice_free (MergePasswordsAsyncData, data);
 }
 
-static ReplaceRecordAsyncData *
-replace_record_async_data_new (EphyPasswordManager *manager,
-                               EphyPasswordRecord  *record)
+static ManageRecordAsyncData *
+manage_record_async_data_new (EphyPasswordManager *manager,
+                              EphyPasswordRecord  *record)
 {
-  ReplaceRecordAsyncData *data;
+  ManageRecordAsyncData *data;
 
-  data = g_slice_new (ReplaceRecordAsyncData);
+  data = g_slice_new (ManageRecordAsyncData);
   data->manager = g_object_ref (manager);
   data->record = g_object_ref (record);
 
@@ -172,13 +172,13 @@ replace_record_async_data_new (EphyPasswordManager *manager,
 }
 
 static void
-replace_record_async_data_free (ReplaceRecordAsyncData *data)
+manage_record_async_data_free (ManageRecordAsyncData *data)
 {
   g_assert (data);
 
   g_object_unref (data->manager);
   g_object_unref (data->record);
-  g_slice_free (ReplaceRecordAsyncData, data);
+  g_slice_free (ManageRecordAsyncData, data);
 }
 
 static GHashTable *
@@ -350,40 +350,62 @@ ephy_password_manager_get_cached_users (EphyPasswordManager *self,
 }
 
 static void
-secret_service_store_cb (SecretService *service,
-                         GAsyncResult  *result,
-                         GTask         *task)
+secret_service_store_cb (SecretService         *service,
+                         GAsyncResult          *result,
+                         ManageRecordAsyncData *data)
 {
   GError *error = NULL;
+  const char *origin;
+  const char *username;
+
+  origin = ephy_password_record_get_origin (data->record);
+  username = ephy_password_record_get_username (data->record);
 
   secret_service_store_finish (service, result, &error);
-  if (error)
-    g_task_return_error (task, error);
-  else
-    g_task_return_boolean (task, TRUE);
+  if (error) {
+    g_warning ("Failed to store password record for (%s, %s, %s, %s, %s): %s",
+               origin,
+               ephy_password_record_get_target_origin (data->record),
+               username,
+               ephy_password_record_get_username_field (data->record),
+               ephy_password_record_get_password_field (data->record),
+               error->message);
+    g_error_free (error);
+  } else {
+    ephy_password_manager_cache_add (data->manager, origin, username);
+  }
 
-  g_object_unref (task);
+  manage_record_async_data_free (data);
 }
 
 static void
-store_internal (const char          *password,
-                GHashTable          *attributes,
-                GAsyncReadyCallback  callback,
-                gpointer             user_data)
+ephy_password_manager_store_record (EphyPasswordManager *self,
+                                    EphyPasswordRecord  *record)
 {
+  GHashTable *attributes;
   SecretValue *value;
-  GTask *task;
   const char *origin;
+  const char *target_origin;
   const char *username;
+  const char *password;
+  const char *username_field;
+  const char *password_field;
   char *label;
+  double modified;
 
-  g_assert (password);
-  g_assert (attributes);
+  g_assert (EPHY_IS_PASSWORD_MANAGER (self));
+  g_assert (EPHY_IS_PASSWORD_RECORD (record));
 
-  task = g_task_new (NULL, NULL, callback, user_data);
-  value = secret_value_new (password, -1, "text/plain");
-  origin = g_hash_table_lookup (attributes, ORIGIN_KEY);
-  username = g_hash_table_lookup (attributes, USERNAME_KEY);
+  origin = ephy_password_record_get_origin (record);
+  target_origin = ephy_password_record_get_target_origin (record);
+  username = ephy_password_record_get_username (record);
+  password = ephy_password_record_get_password (record);
+  username_field = ephy_password_record_get_username_field (record);
+  password_field = ephy_password_record_get_password_field (record);
+  modified = ephy_synchronizable_get_server_time_modified (EPHY_SYNCHRONIZABLE (record));
+
+  LOG ("Storing password record for (%s, %s, %s, %s, %s)",
+       origin, target_origin, username, username_field, password_field);
 
   if (username) {
     /* Translators: The first %s is the username and the second one is the
@@ -396,45 +418,19 @@ store_internal (const char          *password,
     label = g_strdup_printf (_("Password in a form in %s"), origin);
   }
 
-  LOG ("Storing password record for (%s, %s, %s, %s)",
-       origin, username,
-       (char *)g_hash_table_lookup (attributes, USERNAME_FIELD_KEY),
-       (char *)g_hash_table_lookup (attributes, PASSWORD_FIELD_KEY));
+  attributes = get_attributes_table (ephy_password_record_get_id (record),
+                                     origin, target_origin, username,
+                                     username_field, password_field,
+                                     modified);
 
+  value = secret_value_new (password, -1, "text/plain");
   secret_service_store (NULL, EPHY_FORM_PASSWORD_SCHEMA,
                         attributes, NULL, label, value, NULL,
                         (GAsyncReadyCallback)secret_service_store_cb,
-                        g_object_ref (task));
+                        manage_record_async_data_new (self, record));
 
   g_free (label);
   secret_value_unref (value);
-  g_object_unref (task);
-}
-
-static void
-ephy_password_manager_store_record (EphyPasswordManager *self,
-                                    EphyPasswordRecord  *record)
-{
-  GHashTable *attributes;
-  const char *origin;
-  const char *username;
-
-  g_assert (EPHY_IS_PASSWORD_MANAGER (self));
-  g_assert (EPHY_IS_PASSWORD_RECORD (record));
-
-  origin = ephy_password_record_get_origin (record);
-  username = ephy_password_record_get_username (record);
-  attributes = get_attributes_table (ephy_password_record_get_id (record),
-                                     origin,
-                                     ephy_password_record_get_target_origin (record),
-                                     username,
-                                     ephy_password_record_get_username_field (record),
-                                     ephy_password_record_get_password_field (record),
-                                     ephy_synchronizable_get_server_time_modified (EPHY_SYNCHRONIZABLE 
(record)));
-  store_internal (ephy_password_record_get_password (record), attributes, NULL, NULL);
-
-  ephy_password_manager_cache_add (self, origin, username);
-
   g_hash_table_unref (attributes);
 }
 
@@ -600,39 +596,6 @@ ephy_password_manager_query (EphyPasswordManager              *self,
   g_hash_table_unref (attributes);
 }
 
-void
-ephy_password_manager_store_raw (const char          *origin,
-                                 const char          *username,
-                                 const char          *password,
-                                 const char          *username_field,
-                                 const char          *password_field,
-                                 GAsyncReadyCallback  callback,
-                                 gpointer             user_data)
-{
-  GHashTable *attributes;
-
-  g_assert (origin);
-  g_assert (password);
-  g_assert (!username_field || username);
-  g_assert (!password_field || password);
-
-  attributes = get_attributes_table (NULL, origin, origin, username,
-                                     username_field, password_field, -1);
-  store_internal (password, attributes, callback, user_data);
-
-  g_hash_table_unref (attributes);
-}
-
-gboolean
-ephy_password_manager_store_finish (GAsyncResult  *result,
-                                    GError       **error)
-{
-  g_assert (!error || !(*error));
-  g_assert (g_task_is_valid (result, NULL));
-
-  return g_task_propagate_boolean (G_TASK (result), error);
-}
-
 static void
 secret_service_clear_cb (SecretService *service,
                          GAsyncResult  *result,
@@ -648,9 +611,9 @@ secret_service_clear_cb (SecretService *service,
   }
 
   if (user_data) {
-    ReplaceRecordAsyncData *data = (ReplaceRecordAsyncData *)user_data;
+    ManageRecordAsyncData *data = (ManageRecordAsyncData *)user_data;
     ephy_password_manager_store_record (data->manager, data->record);
-    replace_record_async_data_free (data);
+    manage_record_async_data_free (data);
   }
 }
 
@@ -681,7 +644,7 @@ ephy_password_manager_forget_record (EphyPasswordManager *self,
 
   secret_service_clear (NULL, EPHY_FORM_PASSWORD_SCHEMA, attributes, NULL,
                         (GAsyncReadyCallback)secret_service_clear_cb,
-                        replacement ? replace_record_async_data_new (self, replacement) : NULL);
+                        replacement ? manage_record_async_data_new (self, replacement) : NULL);
 
   ephy_password_manager_cache_remove (self,
                                       ephy_password_record_get_origin (record),
@@ -815,7 +778,7 @@ static void
 replace_existing_cb (GList    *records,
                      gpointer  user_data)
 {
-  ReplaceRecordAsyncData *data = (ReplaceRecordAsyncData *)user_data;
+  ManageRecordAsyncData *data = (ManageRecordAsyncData *)user_data;
 
   /* We expect only one matching record here. */
   g_assert (g_list_length (records) == 1);
@@ -823,7 +786,7 @@ replace_existing_cb (GList    *records,
   ephy_password_manager_forget_record (data->manager, records->data, data->record);
 
   g_list_free_full (records, g_object_unref);
-  replace_record_async_data_free (data);
+  manage_record_async_data_free (data);
 }
 
 static void
@@ -836,7 +799,7 @@ ephy_password_manager_replace_existing (EphyPasswordManager *self,
   ephy_password_manager_query (self, ephy_password_record_get_id (record),
                                NULL, NULL, NULL, NULL, NULL,
                                replace_existing_cb,
-                               replace_record_async_data_new (self, record));
+                               manage_record_async_data_new (self, record));
 }
 
 static void
diff --git a/lib/sync/ephy-password-manager.h b/lib/sync/ephy-password-manager.h
index b6fe346..969651e 100644
--- a/lib/sync/ephy-password-manager.h
+++ b/lib/sync/ephy-password-manager.h
@@ -68,16 +68,5 @@ void                 ephy_password_manager_query                    (EphyPasswor
 void                 ephy_password_manager_forget                    (EphyPasswordManager *self,
                                                                       const char          *id);
 void                 ephy_password_manager_forget_all                (EphyPasswordManager *self);
-/* Note: Below functions are deprecated and should not be used in newly written code.
- * The only reason they still exist is that the profile migrator expects them. */
-void                 ephy_password_manager_store_raw                 (const char          *origin,
-                                                                      const char          *username,
-                                                                      const char          *password,
-                                                                      const char          *username_field,
-                                                                      const char          *password_field,
-                                                                      GAsyncReadyCallback  callback,
-                                                                      gpointer             user_data);
-gboolean             ephy_password_manager_store_finish              (GAsyncResult  *result,
-                                                                      GError       **error);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]