summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-05 01:15:15 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-05 01:15:15 +0000
commitf5fb4d4bc5bc2477eb3d7aadd13bd5c487b79559 (patch)
tree2d86029eeac9e0b4302c3479a1cd07cfce4b15f2 /chrome/browser/cocoa
parent87e6564011c57a6760dd6a2f90afc419b37967ae (diff)
downloadchromium_src-f5fb4d4bc5bc2477eb3d7aadd13bd5c487b79559.zip
chromium_src-f5fb4d4bc5bc2477eb3d7aadd13bd5c487b79559.tar.gz
chromium_src-f5fb4d4bc5bc2477eb3d7aadd13bd5c487b79559.tar.bz2
Revert 46424 - AutoFill profile shouldn't be saved when cancelled during initial setup.
For first encounter with fillable form, the AutoFillManager::OnInfoBarAccepted() call now passes the new profile and credit card information to the dialog directly instead of saving it to the database and then invoking the dialog. This facilitates "Cancel" in the dialog where the new information is not persisted. This was a good opportunity to refactor the deferred PersonalDataManager::Observer() logic out of the preferences dialog and into the AutoFillDialogController itself. This also consolidates the Windows, Mac, and Linux interfaces for the ShowAutoFillDialog() call. More work is required on Linux and Windows to properly conform to this interface and fix bug 41010. The Linux and Windows implementations will need to respect the new input parameters |imported_profile| and |imported_credit_card|. BUG=41010 TEST=AutoFillDialogControllerTest.WaitForDataToLoad, AutoFillDialogControllerTest.ImportedParameters Review URL: http://codereview.chromium.org/1930002 TBR=dhollowa@chromium.org Review URL: http://codereview.chromium.org/1902003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46426 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/browser_test_helper.h4
-rw-r--r--chrome/browser/cocoa/preferences_window_controller.h4
-rw-r--r--chrome/browser/cocoa/preferences_window_controller.mm109
3 files changed, 114 insertions, 3 deletions
diff --git a/chrome/browser/cocoa/browser_test_helper.h b/chrome/browser/cocoa/browser_test_helper.h
index 8869aad..b7e3e64 100644
--- a/chrome/browser/cocoa/browser_test_helper.h
+++ b/chrome/browser/cocoa/browser_test_helper.h
@@ -37,7 +37,7 @@ class BrowserTestHelper {
browser_.reset(new Browser(Browser::TYPE_NORMAL, profile_.get()));
}
- virtual ~BrowserTestHelper() {
+ ~BrowserTestHelper() {
// Delete the testing profile on the UI thread. But first release the
// browser, since it may trigger accesses to the profile upon destruction.
browser_.reset(NULL);
@@ -45,7 +45,7 @@ class BrowserTestHelper {
message_loop_.RunAllPending();
}
- virtual TestingProfile* profile() const { return profile_.get(); }
+ TestingProfile* profile() const { return profile_.get(); }
Browser* browser() const { return browser_.get(); }
// Creates the browser window. To close this window call |CloseBrowserWindow|.
diff --git a/chrome/browser/cocoa/preferences_window_controller.h b/chrome/browser/cocoa/preferences_window_controller.h
index 97d8a14..c49a879 100644
--- a/chrome/browser/cocoa/preferences_window_controller.h
+++ b/chrome/browser/cocoa/preferences_window_controller.h
@@ -10,6 +10,7 @@
#include "chrome/browser/pref_member.h"
namespace PreferencesWindowControllerInternal {
+class PersonalDataManagerObserver;
class PrefObserverBridge;
}
@@ -84,6 +85,9 @@ class ProfileSyncService;
// User Data panel
BooleanPrefMember askSavePasswords_;
BooleanPrefMember formAutofill_;
+ // Manages PersonalDataManager loading.
+ scoped_ptr<PreferencesWindowControllerInternal::PersonalDataManagerObserver>
+ personalDataManagerObserver_;
IBOutlet NSButton* autoFillSettingsButton_;
IBOutlet NSButton* syncButton_;
IBOutlet NSButton* syncCustomizeButton_;
diff --git a/chrome/browser/cocoa/preferences_window_controller.mm b/chrome/browser/cocoa/preferences_window_controller.mm
index a27a9cf..dd37f62 100644
--- a/chrome/browser/cocoa/preferences_window_controller.mm
+++ b/chrome/browser/cocoa/preferences_window_controller.mm
@@ -375,6 +375,100 @@ class PrefObserverBridge : public NotificationObserver,
PreferencesWindowController* controller_; // weak, owns us
};
+// PersonalDataManagerObserver facilitates asynchronous loading of
+// PersonalDataManager data before showing the auto fill settings dialog to the
+// user. It acts as a C++-based delegate for the |PreferencesWindowController|.
+class PersonalDataManagerObserver : public PersonalDataManager::Observer {
+ public:
+ explicit PersonalDataManagerObserver(
+ PersonalDataManager* personal_data_manager,
+ Profile* profile)
+ : personal_data_manager_(personal_data_manager),
+ profile_(profile) {
+ }
+
+ virtual ~PersonalDataManagerObserver();
+
+ // Notifies the observer that the PersonalDataManager has finished loading.
+ virtual void OnPersonalDataLoaded();
+
+ // Static method to dispatch to |ShowAutoFillDialog| method in autofill
+ // module. This is public to facilitate direct external call when the
+ // data manager has already loaded its data.
+ static void ShowAutoFillDialog(PersonalDataManager* personal_data_manager,
+ Profile* profile);
+
+ private:
+ // Utility method to remove |this| from |personal_data_manager_| as an
+ // observer.
+ void RemoveObserver();
+
+ // The object in which we are registered as an observer. We hold on to
+ // it to facilitate un-registering ourself in the destructor and in the
+ // |OnPersonalDataLoaded| method. This may be NULL.
+ // Weak reference.
+ PersonalDataManager* personal_data_manager_;
+
+ // Profile of caller. Held as weak reference. May not be NULL.
+ Profile* profile_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerObserver);
+};
+
+// During destruction ensure that we are removed from the
+// |personal_data_manager_| as an observer.
+PersonalDataManagerObserver::~PersonalDataManagerObserver() {
+ RemoveObserver();
+}
+
+void PersonalDataManagerObserver::RemoveObserver() {
+ if (personal_data_manager_) {
+ personal_data_manager_->RemoveObserver(this);
+ }
+}
+
+// The data is ready so display our dialog. Recursively call
+// |showAutoFillSettings:| to try again now knowing that the
+// |PersonalDataManager| is ready. Once done we clear the observer
+// (deleting |this| in the process).
+void PersonalDataManagerObserver::OnPersonalDataLoaded() {
+ RemoveObserver();
+ PersonalDataManagerObserver::ShowAutoFillDialog(personal_data_manager_,
+ profile_);
+}
+
+// Dispatches request to show the autofill dialog. If there are no profiles
+// in the |personal_data_manager| the we create a new one here. Similary with
+// credit card info.
+void PersonalDataManagerObserver::ShowAutoFillDialog(
+ PersonalDataManager* personal_data_manager, Profile* profile) {
+ DCHECK(profile);
+ if (!personal_data_manager)
+ return;
+
+ std::vector<AutoFillProfile*> profiles =
+ personal_data_manager->web_profiles();
+ AutoFillProfile autofill_profile(ASCIIToUTF16(""), 0);
+ if (profiles.size() == 0) {
+ string16 new_profile_name =
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_NEW_ADDRESS);
+ autofill_profile.set_label(new_profile_name);
+ profiles.push_back(&autofill_profile);
+ }
+
+ std::vector<CreditCard*> credit_cards = personal_data_manager->credit_cards();
+ CreditCard credit_card(ASCIIToUTF16(""), 0);
+ if (credit_cards.size() == 0) {
+ string16 new_credit_card_name =
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_NEW_CREDITCARD);
+ credit_card.set_label(new_credit_card_name);
+ credit_cards.push_back(&credit_card);
+ }
+
+ ::ShowAutoFillDialog(personal_data_manager, profiles, credit_cards, profile);
+}
+
} // namespace PreferencesWindowControllerInternal
@implementation PreferencesWindowController
@@ -657,6 +751,7 @@ class PrefObserverBridge : public NotificationObserver,
[customPagesSource_ removeObserver:self forKeyPath:@"customHomePages"];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self unregisterPrefObservers];
+ personalDataManagerObserver_.reset();
[super dealloc];
}
@@ -1157,7 +1252,19 @@ const int kDisabledIndex = 1;
return;
}
- ShowAutoFillDialog(NULL, personalDataManager, profile_, NULL, NULL);
+ if (personalDataManager->IsDataLoaded()) {
+ // |personalDataManager| data is loaded, we can proceed with the dialog.
+ PreferencesWindowControllerInternal::
+ PersonalDataManagerObserver::ShowAutoFillDialog(personalDataManager,
+ profile_);
+ } else {
+ // |personalDataManager| data is NOT loaded, so we load it here, installing
+ // our observer.
+ personalDataManagerObserver_.reset(
+ new PreferencesWindowControllerInternal::PersonalDataManagerObserver(
+ personalDataManager, profile_));
+ personalDataManager->SetObserver(personalDataManagerObserver_.get());
+ }
}
// Called to import data from other browsers (Safari, Firefox, etc).