Unfork Autofill support: Clean up PersonalDataManagerFactory
authorAntonio Gomes <a1.gomes@samsung.com>
Tue, 20 Oct 2015 20:50:15 +0000 (16:50 -0400)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 07:55:23 +0000 (07:55 +0000)
Patch is the first step towards unforking our Autofill
and PassworkManager supports.
It removes lots of methods declared in PersonalDataManagerFactory
class that were just serving as bridge to PersonalDataManager:
- AddProfile
- UpdateProfile
- RemoveByGUID
- GetProfileByGUID

Additionally, patch removes some methods that were not used
anywhere, including:
- GetProfileCount
- GetProfileByIndex
- GetCreditCardCount
- GetCreditCardByIndex
- AddCreditCard
- UpdateCreditCard
- GetCreditCardByGUID

Original beta/m42 patch:
- http://165.213.202.130/gerrit/#/c/90480/ , reviewed by
Janusz Majnert, arno renevier.

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=14553

Reviewed by: sns.park

Change-Id: I2380048b101c0bb1d56f9a2e52640b0cc7c653ff
Signed-off-by: Antonio Gomes <a1.gomes@samsung.com>
tizen_src/ewk/efl_integration/browser/autofill/personal_data_manager_factory.cc
tizen_src/ewk/efl_integration/browser/autofill/personal_data_manager_factory.h
tizen_src/ewk/efl_integration/private/ewk_context_form_autofill_profile_private.cc

index 6bbceaf..fa32962 100644 (file)
@@ -6,16 +6,18 @@
 
 #include "browser/autofill/personal_data_manager_factory.h"
 
-#include "eweb_view.h"
 #include "base/memory/scoped_ptr.h"
 #include "browser/webdata/web_data_service_factory.h"
 #include "components/autofill/core/browser/personal_data_manager.h"
 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
 #include "components/user_prefs/user_prefs.h"
 #include "content/common/content_client_export.h"
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/browser_context.h"
 #include "content/public/common/content_client.h"
 
 namespace autofill {
+
 // static
 PersonalDataManagerFactory* PersonalDataManagerFactory::GetInstance() {
   return base::Singleton<PersonalDataManagerFactory>::get();
@@ -27,7 +29,6 @@ void PersonalDataManagerFactory::PersonalDataManagerAdd(content::BrowserContext*
   if (ctx) {
     uint64_t uniqueId = reinterpret_cast<uint64_t>(ctx);
     PersonalDataManager* mgr = personal_data_manager_id_map_.Lookup(uniqueId);
-
     if (!mgr) {
       // TODO: LOCALE!
       PrefService* srv = user_prefs::UserPrefs::Get(ctx);
@@ -42,99 +43,14 @@ void PersonalDataManagerFactory::PersonalDataManagerAdd(content::BrowserContext*
 }
 
 void PersonalDataManagerFactory::PersonalDataManagerRemove(content::BrowserContext* ctx) {
-    uint64_t uniqueId = reinterpret_cast<uint64_t>(ctx);
-    personal_data_manager_id_map_.Remove(uniqueId);
+  uint64_t uniqueId = reinterpret_cast<uint64_t>(ctx);
+  personal_data_manager_id_map_.Remove(uniqueId);
 }
 
 PersonalDataManager* PersonalDataManagerFactory::PersonalDataManagerForContext(
     content::BrowserContext* ctx) {
-    uint64_t uniqueId = reinterpret_cast<uint64_t>(ctx);
-    return personal_data_manager_id_map_.Lookup(uniqueId);
-}
-
-int PersonalDataManagerFactory::GetProfileCount(
-   content::BrowserContext* ctx) {
-  PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
-  if (mgr)
-    return mgr->GetProfiles().size();
-  return 0;
-}
-
-AutofillProfile* PersonalDataManagerFactory::GetProfileByIndex(
-    content::BrowserContext* ctx, int index) {
-  PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
-  if (mgr) {
-    const std::vector<AutofillProfile*>& profiles = mgr->GetProfiles();
-    size_t index_size_t = static_cast<size_t>(index);
-    DCHECK_LT(index_size_t, profiles.size());
-    return (profiles[index_size_t]);
-  }
-  return NULL;
-}
-
-void PersonalDataManagerFactory::AddProfile(content::BrowserContext* ctx, const AutofillProfile& profile) {
-  PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
-  if (mgr)
-    mgr->AddProfile(profile);
-}
-
-void PersonalDataManagerFactory::UpdateProfile(content::BrowserContext* ctx, const AutofillProfile& profile) {
-  PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
-  if (mgr)
-    mgr->UpdateProfile(profile);
-}
-
-void PersonalDataManagerFactory::RemoveByGUID(content::BrowserContext* ctx, const std::string& guid) {
-  PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
-  if (mgr)
-    mgr->RemoveByGUID(guid);
-}
-
-AutofillProfile* PersonalDataManagerFactory::GetProfileByGUID(content::BrowserContext* ctx, const std::string& guid) {
-  PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
-  if (mgr)
-    return mgr->GetProfileByGUID(guid);
-
-  return NULL;
-}
-
-void PersonalDataManagerFactory::AddCreditCard(content::BrowserContext* ctx, const CreditCard& credit_card) {
-  PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
-  if (mgr)
-    mgr->AddCreditCard(credit_card);
-}
-
-void PersonalDataManagerFactory::UpdateCreditCard(content::BrowserContext* ctx, const CreditCard& credit_card) {
-  PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
-  if (mgr)
-    mgr->UpdateCreditCard(credit_card);
-}
-
-CreditCard* PersonalDataManagerFactory::GetCreditCardByGUID(content::BrowserContext* ctx, const std::string& guid) {
-  PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
-  if (mgr)
-    return mgr->GetCreditCardByGUID(guid);
-
-  return NULL;
-}
-
-int PersonalDataManagerFactory::GetCreditCardCount(content::BrowserContext* ctx) {
-  PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
-  if (mgr)
-    return mgr->GetCreditCards().size();
-
-  return 0;
-}
-
-CreditCard* PersonalDataManagerFactory::GetCreditCardByIndex(content::BrowserContext* ctx, int index) {
-  PersonalDataManager* mgr = PersonalDataManagerForContext(ctx);
-  if (mgr) {
-    const std::vector<CreditCard*>& credit_cards = mgr->GetCreditCards();
-    size_t index_size_t = static_cast<size_t>(index);
-    DCHECK_LT(index_size_t, credit_cards.size());
-    return (credit_cards[index_size_t]);
-  }
-  return NULL;
+  uint64_t uniqueId = reinterpret_cast<uint64_t>(ctx);
+  return personal_data_manager_id_map_.Lookup(uniqueId);
 }
 
 PersonalDataManagerFactory::PersonalDataManagerFactory()
index 3279b9c..1847fe8 100644 (file)
@@ -39,47 +39,6 @@ class PersonalDataManagerFactory : public PersonalDataManagerObserver {
   PersonalDataManager* PersonalDataManagerForContext(
       content::BrowserContext* ctx);
 
-  // Returns the number of web and auxiliary profiles.
-  int GetProfileCount(content::BrowserContext* mgr);
-
-  // Returns the profile with specified |index|
-  AutofillProfile* GetProfileByIndex(content::BrowserContext* mgr, int index);
-
- // Adds |profile| to the web database.
-  void AddProfile(content::BrowserContext* mgr, const AutofillProfile& profile);
-
-  // Updates |profile| which already exists in the web database.
-  void UpdateProfile(content::BrowserContext* mgr,
-      const AutofillProfile& profile);
-
-  // Removes the profile or credit card represented by |guid|.
-  void RemoveByGUID(content::BrowserContext* mgr, const std::string& guid);
-
-  // Returns the profile with the specified |guid|, or NULL if there is no
-  // profile with the specified |guid|. Both web and auxiliary profiles may
-  // be returned.
-  AutofillProfile* GetProfileByGUID(content::BrowserContext* mgr,
-      const std::string& guid);
-
-  // Returns the number of web and auxiliary CC.
-  int GetCreditCardCount(content::BrowserContext* mgr);
-
-  // Returns the credit card with specified |index|
-  CreditCard* GetCreditCardByIndex(content::BrowserContext* mgr, int index);
-
-  // Adds |credit_card| to the web database.
-  void AddCreditCard(content::BrowserContext* mgr,
-      const CreditCard& credit_card);
-
-  // Updates |credit_card| which already exists in the web database.
-  void UpdateCreditCard(content::BrowserContext* mgr,
-      const CreditCard& credit_card);
-
-  // Returns the credit card with the specified |guid|, or NULL if there is
-  // no credit card with the specified |guid|.
-  CreditCard* GetCreditCardByGUID(content::BrowserContext* mgr,
-      const std::string& guid);
-
   void SetCallback(Ewk_Context_Form_Autofill_Profile_Changed_Callback callback,
       void* user_data);
 
index 474d241..e7760a1 100644 (file)
@@ -188,22 +188,29 @@ Ewk_Autofill_Profile* to_Ewk_Autofill_Profile(
   return ret;
 }
 
+autofill::PersonalDataManager* PersonalDataManagerForEWKContext(
+    Ewk_Context* ewk_context) {
+  EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_context, nullptr);
 
-Eina_List*
-EwkContextFormAutofillProfileManager::priv_form_autofill_profile_get_all(
-    Ewk_Context* context) {
-  EINA_SAFETY_ON_NULL_RETURN_VAL(context, nullptr);
-  autofill::PersonalDataManagerFactory* dataManagerFactory =
+  autofill::PersonalDataManagerFactory* personal_data_manager_factory =
       autofill::PersonalDataManagerFactory::GetInstance();
+  content::BrowserContext* context = ewk_context->browser_context();
+  EINA_SAFETY_ON_NULL_RETURN_VAL(context, nullptr);
 
-  autofill::PersonalDataManager* dataManager =
-      dataManagerFactory->PersonalDataManagerForContext(
-          context->browser_context());
+  return personal_data_manager_factory->PersonalDataManagerForContext(context);
+}
 
+Eina_List*
+EwkContextFormAutofillProfileManager::priv_form_autofill_profile_get_all(
+    Ewk_Context* ewk_context) {
+  EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_context, nullptr);
+
+  autofill::PersonalDataManager* manager =
+      PersonalDataManagerForEWKContext(ewk_context);
+  DCHECK(manager);
 
-  EINA_SAFETY_ON_NULL_RETURN_VAL(dataManager, nullptr);
   std::vector<autofill::AutofillProfile*> dataVector =
-      dataManager->GetProfiles();
+      manager->GetProfiles();
   Eina_List* list = nullptr;
   for (unsigned i = 0; i < dataVector.size(); ++i) {
     autofill::AutofillProfile* profile = dataVector[i];
@@ -218,14 +225,15 @@ EwkContextFormAutofillProfileManager::priv_form_autofill_profile_get_all(
 
 Ewk_Autofill_Profile*
 EwkContextFormAutofillProfileManager::priv_form_autofill_profile_get(
-    Ewk_Context* context, unsigned id) {
-  EINA_SAFETY_ON_NULL_RETURN_VAL(context, nullptr);
-  autofill::PersonalDataManagerFactory* dataManagerFactory =
-      autofill::PersonalDataManagerFactory::GetInstance();
+    Ewk_Context* ewk_context, unsigned id) {
+  EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_context, nullptr);
+
+  autofill::PersonalDataManager* manager =
+      PersonalDataManagerForEWKContext(ewk_context);
+  DCHECK(manager);
+
+  autofill::AutofillProfile* profile = manager->GetProfileByGUID(UnsignedToGUID(id));
 
-  autofill::AutofillProfile* profile =
-      dataManagerFactory->GetProfileByGUID(context->browser_context(),
-                                           UnsignedToGUID(id));
   Ewk_Autofill_Profile* ret = nullptr;
   if (profile)
     ret = to_Ewk_Autofill_Profile(*profile);
@@ -233,41 +241,44 @@ EwkContextFormAutofillProfileManager::priv_form_autofill_profile_get(
 }
 
 Eina_Bool EwkContextFormAutofillProfileManager::priv_form_autofill_profile_set(
-    Ewk_Context* context,
-    unsigned id, Ewk_Autofill_Profile* profile) {
-  autofill::PersonalDataManagerFactory* personalDataManagerFactory =
-      autofill::PersonalDataManagerFactory::GetInstance();
-  content::BrowserContext* ctx = context->browser_context();
-  EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);
-
+    Ewk_Context* ewk_context,
+    unsigned id, Ewk_Autofill_Profile* ewk_profile) {
+  EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_context, EINA_FALSE);
 
-  // check if such profile already exists
-  if (personalDataManagerFactory->GetProfileByGUID(ctx, UnsignedToGUID(id))) {
-    personalDataManagerFactory->UpdateProfile(ctx,
-                                              to_Autofill_Profile(profile));
-  } else {
-    personalDataManagerFactory->AddProfile(ctx, to_Autofill_Profile(profile));
-  }
+  autofill::PersonalDataManager* manager =
+      PersonalDataManagerForEWKContext(ewk_context);
+  DCHECK(manager);
 
+  autofill::AutofillProfile* profile = manager->GetProfileByGUID(UnsignedToGUID(id));
+  if (profile)
+    manager->UpdateProfile(to_Autofill_Profile(ewk_profile));
+  else
+    manager->AddProfile(to_Autofill_Profile(ewk_profile));
   return EINA_TRUE;
 }
 
 Eina_Bool EwkContextFormAutofillProfileManager::priv_form_autofill_profile_add(
-    Ewk_Context* context, Ewk_Autofill_Profile* profile) {
-  autofill::PersonalDataManagerFactory* personalDataManagerFactory =
-      autofill::PersonalDataManagerFactory::GetInstance();
-  personalDataManagerFactory->AddProfile(
-      context->browser_context(), to_Autofill_Profile(profile));
+    Ewk_Context* ewk_context, Ewk_Autofill_Profile* profile) {
+  EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_context, EINA_FALSE);
+
+  autofill::PersonalDataManager* manager =
+      PersonalDataManagerForEWKContext(ewk_context);
+  DCHECK(manager);
+
+  manager->AddProfile(to_Autofill_Profile(profile));
   return EINA_TRUE;
 }
 
 Eina_Bool
 EwkContextFormAutofillProfileManager::priv_form_autofill_profile_remove(
-    Ewk_Context* context, unsigned id) {
-  autofill::PersonalDataManagerFactory* personalDataManagerFactory =
-      autofill::PersonalDataManagerFactory::GetInstance();
-  personalDataManagerFactory->RemoveByGUID(context->browser_context(),
-                                           UnsignedToGUID(id));
+    Ewk_Context* ewk_context, unsigned id) {
+  EINA_SAFETY_ON_NULL_RETURN_VAL(ewk_context, EINA_FALSE);
+
+  autofill::PersonalDataManager* manager =
+      PersonalDataManagerForEWKContext(ewk_context);
+  DCHECK(manager);
+
+  manager->RemoveByGUID(UnsignedToGUID(id));
   return EINA_TRUE;
 }