diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-30 00:33:10 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-30 00:33:10 +0000 |
commit | 8d4cc15e95bdce1ec41b68c2b1cc5685642c39e0 (patch) | |
tree | 0e00e143095ae775ee1ba1cc886c9142ae06f82f | |
parent | c1a47df6521776547b5a3a9966dba63aab9e2e6b (diff) | |
download | chromium_src-8d4cc15e95bdce1ec41b68c2b1cc5685642c39e0.zip chromium_src-8d4cc15e95bdce1ec41b68c2b1cc5685642c39e0.tar.gz chromium_src-8d4cc15e95bdce1ec41b68c2b1cc5685642c39e0.tar.bz2 |
Introduce AutofillClient and use it to get rid of PasswordManager dependency.
Also, this switches use of InfoBarTabService and PrefServiceBase in
AutofillManager from calling their ::ForXyz methods, to retrieving
them via AutofillClient.
BUG=140037
Review URL: https://chromiumcodereview.appspot.com/10837363
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154022 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/autofill/DEPS | 2 | ||||
-rw-r--r-- | chrome/browser/autofill/api/autofill_manager_delegate.h | 44 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_external_delegate_unittest.cc | 8 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager.cc | 33 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager.h | 11 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager_unittest.cc | 6 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_metrics_unittest.cc | 6 | ||||
-rw-r--r-- | chrome/browser/plugin_infobar_delegates.cc | 8 | ||||
-rw-r--r-- | chrome/browser/ui/autofill/OWNERS | 5 | ||||
-rw-r--r-- | chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc | 29 | ||||
-rw-r--r-- | chrome/browser/ui/autofill/tab_autofill_manager_delegate.h | 28 | ||||
-rw-r--r-- | chrome/browser/ui/tab_contents/tab_contents.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/tab_contents/tab_contents.h | 2 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 3 |
14 files changed, 159 insertions, 30 deletions
diff --git a/chrome/browser/autofill/DEPS b/chrome/browser/autofill/DEPS index 743b66f..cd6ce8b 100644 --- a/chrome/browser/autofill/DEPS +++ b/chrome/browser/autofill/DEPS @@ -14,7 +14,6 @@ include_rules = [ # # Do not add to the list of temporarily-allowed dependencies below, # and please do not introduce more #includes of these files. - "!chrome/browser/password_manager/password_manager.h", "!chrome/browser/profiles/profile.h", "!chrome/browser/profiles/profile_dependency_manager.h", "!chrome/browser/profiles/profile_keyed_service.h", @@ -46,6 +45,7 @@ specific_include_rules = { "!chrome/browser/password_manager/encryptor.h", "!chrome/browser/translate/translate_infobar_delegate.h", "!chrome/browser/translate/translate_manager.h", + "!chrome/browser/ui/autofill/tab_autofill_manager_delegate.h", "!chrome/browser/ui/browser_tabstrip.h", "!chrome/browser/ui/tab_contents/test_tab_contents.h", ] diff --git a/chrome/browser/autofill/api/autofill_manager_delegate.h b/chrome/browser/autofill/api/autofill_manager_delegate.h new file mode 100644 index 0000000..3f478a1 --- /dev/null +++ b/chrome/browser/autofill/api/autofill_manager_delegate.h @@ -0,0 +1,44 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_AUTOFILL_API_AUTOFILL_MANAGER_DELEGATE_H_ +#define CHROME_BROWSER_AUTOFILL_API_AUTOFILL_MANAGER_DELEGATE_H_ + +class InfoBarTabService; +class PrefServiceBase; + +namespace autofill { + +// A delegate interface that needs to be supplied to AutofillManager +// by the embedder. +// +// Each delegate instance is associated with a given context within +// which an AutofillManager is used (e.g. a single tab), so when we +// say "for the delegate" below, we mean "in the execution context the +// delegate is associated with" (e.g. for the tab the AutofillManager is +// attached to). +class AutofillManagerDelegate { + public: + virtual ~AutofillManagerDelegate() {} + + // Gets the infobar service associated with the delegate. + // + // TODO(joi): Given the approach (which we will likely use more + // widely) of a context associated with the instance of the delegate, + // it seems right to rename InfoBarTabService to just + // InfoBarService. Naming the getter appropriately, will name the + // class itself in a follow-up change. + virtual InfoBarTabService* GetInfoBarService() = 0; + + // Gets the preferences associated with the delegate. + virtual PrefServiceBase* GetPrefs() = 0; + + // Returns true if saving passwords is currently enabled for the + // delegate. + virtual bool IsSavingPasswordsEnabled() const = 0; +}; + +} // namespace autofill + +#endif // CHROME_BROWSER_AUTOFILL_API_AUTOFILL_MANAGER_DELEGATE_H_ diff --git a/chrome/browser/autofill/autofill_external_delegate_unittest.cc b/chrome/browser/autofill/autofill_external_delegate_unittest.cc index 0e6183d..86ae8ee 100644 --- a/chrome/browser/autofill/autofill_external_delegate_unittest.cc +++ b/chrome/browser/autofill/autofill_external_delegate_unittest.cc @@ -9,6 +9,7 @@ #include "base/string16.h" #include "chrome/browser/autofill/autofill_manager.h" #include "chrome/browser/autofill/test_autofill_external_delegate.h" +#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" #include "chrome/browser/ui/tab_contents/test_tab_contents.h" #include "chrome/test/base/testing_profile.h" #include "content/public/test/test_browser_thread.h" @@ -65,7 +66,9 @@ class MockAutofillManager : public AutofillManager { explicit MockAutofillManager(TabContents* tab_contents) // Force to use the constructor designated for unit test, but we don't // really need personal_data in this test so we pass a NULL pointer. - : AutofillManager(tab_contents, NULL) {} + : AutofillManager(&delegate_, tab_contents, NULL), + delegate_(tab_contents) { + } MOCK_METHOD4(OnFillAutofillFormData, void(int query_id, @@ -75,6 +78,9 @@ class MockAutofillManager : public AutofillManager { protected: virtual ~MockAutofillManager() {} + + private: + TabAutofillManagerDelegate delegate_; }; } // namespace diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc index c8b5b50..8a28c0c 100644 --- a/chrome/browser/autofill/autofill_manager.cc +++ b/chrome/browser/autofill/autofill_manager.cc @@ -20,6 +20,7 @@ #include "base/threading/sequenced_worker_pool.h" #include "base/utf_string_conversions.h" #include "chrome/browser/api/infobars/infobar_tab_service.h" +#include "chrome/browser/autofill/api/autofill_manager_delegate.h" #include "chrome/browser/autofill/autocomplete_history_manager.h" #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" #include "chrome/browser/autofill/autofill_external_delegate.h" @@ -36,7 +37,6 @@ #include "chrome/browser/autofill/phone_number.h" #include "chrome/browser/autofill/phone_number_i18n.h" #include "chrome/browser/autofill/select_control_handler.h" -#include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/api/prefs/pref_service_base.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/profile_sync_service.h" @@ -178,8 +178,10 @@ void DeterminePossibleFieldTypesForUpload( } // namespace -AutofillManager::AutofillManager(TabContents* tab_contents) +AutofillManager::AutofillManager(autofill::AutofillManagerDelegate* delegate, + TabContents* tab_contents) : content::WebContentsObserver(tab_contents->web_contents()), + manager_delegate_(delegate), tab_contents_(tab_contents), personal_data_(NULL), download_manager_(tab_contents->profile(), this), @@ -197,7 +199,7 @@ AutofillManager::AutofillManager(TabContents* tab_contents) personal_data_ = PersonalDataManagerFactory::GetForProfile( tab_contents->profile()->GetOriginalProfile()); RegisterWithSyncService(); - registrar_.Init(PrefServiceBase::ForProfile(tab_contents->profile())); + registrar_.Init(manager_delegate_->GetPrefs()); registrar_.Add(prefs::kPasswordGenerationEnabled, this); notification_registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, @@ -262,17 +264,13 @@ void AutofillManager::UpdatePasswordGenerationState( service->HasSyncSetupCompleted() && sync_set.Has(syncer::PASSWORDS); } - bool password_manager_enabled = - tab_contents_->password_manager()->IsSavingEnabled(); - - Profile* profile = Profile::FromBrowserContext( - web_contents()->GetBrowserContext()); - bool preference_checked = PrefServiceBase::ForProfile(profile)->GetBoolean( + bool saving_passwords_enabled = manager_delegate_->IsSavingPasswordsEnabled(); + bool preference_checked = manager_delegate_->GetPrefs()->GetBoolean( prefs::kPasswordGenerationEnabled); bool new_password_generation_enabled = password_sync_enabled && - password_manager_enabled && + saving_passwords_enabled && preference_checked; if (new_password_generation_enabled != password_generation_enabled_ || @@ -813,10 +811,7 @@ void AutofillManager::OnDidEndTextFieldEditing() { } bool AutofillManager::IsAutofillEnabled() const { - Profile* profile = Profile::FromBrowserContext( - const_cast<AutofillManager*>(this)->web_contents()->GetBrowserContext()); - return PrefServiceBase::ForProfile(profile)->GetBoolean( - prefs::kAutofillEnabled); + return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); } void AutofillManager::SendAutofillTypePredictions( @@ -845,8 +840,7 @@ void AutofillManager::ImportFormData(const FormStructure& submitted_form) { // it. scoped_ptr<const CreditCard> scoped_credit_card(imported_credit_card); if (imported_credit_card && web_contents()) { - InfoBarTabService* infobar_service = - InfoBarTabService::ForTab(tab_contents_); + InfoBarTabService* infobar_service = manager_delegate_->GetInfoBarService(); infobar_service->AddInfoBar( new AutofillCCInfoBarDelegate(infobar_service, scoped_credit_card.release(), @@ -910,9 +904,11 @@ void AutofillManager::Reset() { external_delegate_->Reset(); } -AutofillManager::AutofillManager(TabContents* tab_contents, +AutofillManager::AutofillManager(autofill::AutofillManagerDelegate* delegate, + TabContents* tab_contents, PersonalDataManager* personal_data) : content::WebContentsObserver(tab_contents->web_contents()), + manager_delegate_(delegate), tab_contents_(tab_contents), personal_data_(personal_data), download_manager_(tab_contents->profile(), this), @@ -926,7 +922,8 @@ AutofillManager::AutofillManager(TabContents* tab_contents, user_did_edit_autofilled_field_(false), password_generation_enabled_(false), external_delegate_(NULL) { - DCHECK(tab_contents); + DCHECK(tab_contents_); + DCHECK(manager_delegate_); RegisterWithSyncService(); // Test code doesn't need registrar_. } diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h index f2db3ce..eb46bf9 100644 --- a/chrome/browser/autofill/autofill_manager.h +++ b/chrome/browser/autofill/autofill_manager.h @@ -41,6 +41,7 @@ class TabContents; struct ViewHostMsg_FrameNavigate_Params; namespace autofill { +class AutofillManagerDelegate; class PasswordGenerator; } @@ -73,7 +74,10 @@ class AutofillManager : public content::NotificationObserver, public ProfileSyncServiceObserver, public base::RefCounted<AutofillManager> { public: - explicit AutofillManager(TabContents* tab_contents); + // Lifetime of |client| and |tab_contents| must exceed lifetime of + // AutofillManager. + explicit AutofillManager(autofill::AutofillManagerDelegate* delegate, + TabContents* tab_contents); // Registers our Enable/Disable Autofill pref. static void RegisterUserPrefs(PrefServiceBase* prefs); @@ -117,7 +121,8 @@ class AutofillManager : public content::NotificationObserver, typedef std::pair<std::string, size_t> GUIDPair; // Test code should prefer to use this constructor. - AutofillManager(TabContents* tab_contents, + AutofillManager(autofill::AutofillManagerDelegate* delegate, + TabContents* tab_contents, PersonalDataManager* personal_data); // Returns the value of the AutofillEnabled pref. @@ -321,6 +326,8 @@ class AutofillManager : public content::NotificationObserver, void SendAutofillTypePredictions( const std::vector<FormStructure*>& forms) const; + autofill::AutofillManagerDelegate* const manager_delegate_; + // The owning TabContents. TabContents* tab_contents_; diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc index abec88c..8aea816f 100644 --- a/chrome/browser/autofill/autofill_manager_unittest.cc +++ b/chrome/browser/autofill/autofill_manager_unittest.cc @@ -26,6 +26,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" +#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/ui/tab_contents/test_tab_contents.h" @@ -442,7 +443,8 @@ class TestAutofillManager : public AutofillManager { public: TestAutofillManager(TabContents* tab_contents, TestPersonalDataManager* personal_data) - : AutofillManager(tab_contents, personal_data), + : AutofillManager(&delegate_, tab_contents, personal_data), + delegate_(tab_contents), personal_data_(personal_data), autofill_enabled_(true), did_finish_async_form_submit_(false), @@ -563,6 +565,8 @@ class TestAutofillManager : public AutofillManager { // AutofillManager is ref counted. virtual ~TestAutofillManager() {} + TabAutofillManagerDelegate delegate_; + // Weak reference. TestPersonalDataManager* personal_data_; diff --git a/chrome/browser/autofill/autofill_metrics_unittest.cc b/chrome/browser/autofill/autofill_metrics_unittest.cc index 1037c68..e601030c 100644 --- a/chrome/browser/autofill/autofill_metrics_unittest.cc +++ b/chrome/browser/autofill/autofill_metrics_unittest.cc @@ -15,6 +15,7 @@ #include "chrome/browser/autofill/autofill_metrics.h" #include "chrome/browser/autofill/personal_data_manager.h" #include "chrome/browser/autofill/personal_data_manager_factory.h" +#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/ui/tab_contents/test_tab_contents.h" #include "chrome/browser/webdata/web_data_service.h" @@ -174,7 +175,8 @@ class TestAutofillManager : public AutofillManager { public: TestAutofillManager(TabContents* tab_contents, TestPersonalDataManager* personal_manager) - : AutofillManager(tab_contents, personal_manager), + : AutofillManager(&autofill_delegate_, tab_contents, personal_manager), + autofill_delegate_(tab_contents), autofill_enabled_(true), did_finish_async_form_submit_(false), message_loop_is_running_(false) { @@ -245,6 +247,8 @@ class TestAutofillManager : public AutofillManager { // AutofillManager is ref counted. virtual ~TestAutofillManager() {} + TabAutofillManagerDelegate autofill_delegate_; + bool autofill_enabled_; bool did_finish_async_form_submit_; bool message_loop_is_running_; diff --git a/chrome/browser/plugin_infobar_delegates.cc b/chrome/browser/plugin_infobar_delegates.cc index e359246..2881c81 100644 --- a/chrome/browser/plugin_infobar_delegates.cc +++ b/chrome/browser/plugin_infobar_delegates.cc @@ -175,11 +175,9 @@ OutdatedPluginInfoBarDelegate::OutdatedPluginInfoBarDelegate( PluginObserver* observer, PluginInstaller* installer, const string16& message) - : PluginInfoBarDelegate( - -InfoBarTabService::ForTab(observer->tab_contents()), - installer->name(), - installer->identifier()), + : PluginInfoBarDelegate(InfoBarTabService::ForTab(observer->tab_contents()), + installer->name(), + installer->identifier()), WeakPluginInstallerObserver(installer), observer_(observer), message_(message) { diff --git a/chrome/browser/ui/autofill/OWNERS b/chrome/browser/ui/autofill/OWNERS new file mode 100644 index 0000000..1957692 --- /dev/null +++ b/chrome/browser/ui/autofill/OWNERS @@ -0,0 +1,5 @@ +dhollowa@chromium.org +isherman@chromium.org + +# Temporary owner, for refactoring changes only. +joi@chromium.org diff --git a/chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc b/chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc new file mode 100644 index 0000000..7dbbf86 --- /dev/null +++ b/chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" + +#include "base/logging.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" +#include "chrome/browser/password_manager/password_manager.h" +#include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/tab_contents/tab_contents.h" + +TabAutofillManagerDelegate::TabAutofillManagerDelegate(TabContents* tab) + : tab_(tab) { + DCHECK(tab_); +} + +InfoBarTabService* TabAutofillManagerDelegate::GetInfoBarService() { + return tab_->infobar_tab_helper(); +} + +PrefServiceBase* TabAutofillManagerDelegate::GetPrefs() { + return tab_->profile()->GetPrefs(); +} + +bool TabAutofillManagerDelegate::IsSavingPasswordsEnabled() const { + return tab_->password_manager()->IsSavingEnabled(); +} diff --git a/chrome/browser/ui/autofill/tab_autofill_manager_delegate.h b/chrome/browser/ui/autofill/tab_autofill_manager_delegate.h new file mode 100644 index 0000000..5769c5d6 --- /dev/null +++ b/chrome/browser/ui/autofill/tab_autofill_manager_delegate.h @@ -0,0 +1,28 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_AUTOFILL_TAB_AUTOFILL_MANAGER_DELEGATE_H_ +#define CHROME_BROWSER_UI_AUTOFILL_TAB_AUTOFILL_MANAGER_DELEGATE_H_ + +#include "base/compiler_specific.h" +#include "chrome/browser/autofill/api/autofill_manager_delegate.h" + +class TabContents; + +// Chrome implementation of AutofillManagerDelegate. +class TabAutofillManagerDelegate : public autofill::AutofillManagerDelegate { + public: + // Lifetime of |tab| must exceed lifetime of TabAutofillManagerDelegate. + explicit TabAutofillManagerDelegate(TabContents* tab); + virtual ~TabAutofillManagerDelegate() {} + + virtual InfoBarTabService* GetInfoBarService() OVERRIDE; + virtual PrefServiceBase* GetPrefs() OVERRIDE; + virtual bool IsSavingPasswordsEnabled() const OVERRIDE; + + private: + TabContents* const tab_; +}; + +#endif // CHROME_BROWSER_UI_AUTOFILL_TAB_AUTOFILL_MANAGER_DELEGATE_H_ diff --git a/chrome/browser/ui/tab_contents/tab_contents.cc b/chrome/browser/ui/tab_contents/tab_contents.cc index 09b4965..1396484 100644 --- a/chrome/browser/ui/tab_contents/tab_contents.cc +++ b/chrome/browser/ui/tab_contents/tab_contents.cc @@ -35,6 +35,7 @@ #include "chrome/browser/tab_contents/thumbnail_generator.h" #include "chrome/browser/translate/translate_tab_helper.h" #include "chrome/browser/ui/alternate_error_tab_observer.h" +#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" #include "chrome/browser/ui/constrained_window_tab_helper.h" @@ -111,7 +112,8 @@ TabContents::TabContents(WebContents* contents) restore_tab_helper_.reset(new RestoreTabHelper(contents)); autocomplete_history_manager_.reset(new AutocompleteHistoryManager(contents)); - autofill_manager_ = new AutofillManager(this); + autofill_delegate_.reset(new TabAutofillManagerDelegate(this)); + autofill_manager_ = new AutofillManager(autofill_delegate_.get(), this); if (CommandLine::ForCurrentProcess()->HasSwitch( switches::kExternalAutofillPopup)) { autofill_external_delegate_.reset( diff --git a/chrome/browser/ui/tab_contents/tab_contents.h b/chrome/browser/ui/tab_contents/tab_contents.h index cd27fc5..05b8494 100644 --- a/chrome/browser/ui/tab_contents/tab_contents.h +++ b/chrome/browser/ui/tab_contents/tab_contents.h @@ -56,6 +56,7 @@ class SadTabHelper; class SearchEngineTabHelper; class ShellWindow; class SnapshotTabHelper; +class TabAutofillManagerDelegate; class TabContentsSSLHelper; class TabContentsTestHarness; class TabSpecificContentSettings; @@ -347,6 +348,7 @@ class TabContents : public content::WebContentsObserver { scoped_ptr<AutocompleteHistoryManager> autocomplete_history_manager_; scoped_refptr<AutofillManager> autofill_manager_; + scoped_ptr<TabAutofillManagerDelegate> autofill_delegate_; scoped_ptr<AutofillExternalDelegate> autofill_external_delegate_; scoped_ptr<AutomationTabHelper> automation_tab_helper_; scoped_ptr<BlockedContentTabHelper> blocked_content_tab_helper_; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index ae3f228..1d56f0d 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -193,6 +193,7 @@ 'browser/autofill/address.h', 'browser/autofill/address_field.cc', 'browser/autofill/address_field.h', + 'browser/autofill/api/autofill_manager_delegate.h', 'browser/autofill/autocomplete_history_manager.cc', 'browser/autofill/autocomplete_history_manager.h', 'browser/autofill/autofill-inl.h', @@ -2025,6 +2026,8 @@ 'browser/ui/aura/chrome_browser_main_extra_parts_aura.cc', 'browser/ui/aura/chrome_browser_main_extra_parts_aura.h', 'browser/ui/aura/tabs/dock_info_aurax11.cc', + 'browser/ui/autofill/tab_autofill_manager_delegate.cc', + 'browser/ui/autofill/tab_autofill_manager_delegate.h', 'browser/ui/auto_login_info_bar_delegate.cc', 'browser/ui/auto_login_info_bar_delegate.h', 'browser/ui/auto_login_prompter.cc', |