diff options
author | jeanfrancoisg@chromium.org <jeanfrancoisg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-10 21:34:45 +0000 |
---|---|---|
committer | jeanfrancoisg@chromium.org <jeanfrancoisg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-10 21:34:45 +0000 |
commit | d5fd67273f7d2105efde6f517605ac27f6af451e (patch) | |
tree | bea6c18f95f6be8e92a243f14216f3a89ecb4d46 /components | |
parent | 0ea7fab752cc0fa397c116354ee9d9631b2483e4 (diff) | |
download | chromium_src-d5fd67273f7d2105efde6f517605ac27f6af451e.zip chromium_src-d5fd67273f7d2105efde6f517605ac27f6af451e.tar.gz chromium_src-d5fd67273f7d2105efde6f517605ac27f6af451e.tar.bz2 |
Removes usage of RenderViewHost from AutofillManager.
BUG=302510
Review URL: https://codereview.chromium.org/98683003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239851 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
15 files changed, 39 insertions, 83 deletions
diff --git a/components/autofill/content/browser/autofill_driver_impl.cc b/components/autofill/content/browser/autofill_driver_impl.cc index 43e5d92..a547acd3 100644 --- a/components/autofill/content/browser/autofill_driver_impl.cc +++ b/components/autofill/content/browser/autofill_driver_impl.cc @@ -120,7 +120,7 @@ void AutofillDriverImpl::SendAutofillTypePredictionsToRenderer( switches::kShowAutofillTypePredictions)) return; - content::RenderViewHost* host = GetWebContents()->GetRenderViewHost(); + content::RenderViewHost* host = web_contents()->GetRenderViewHost(); if (!host) return; diff --git a/components/autofill/content/browser/autofill_driver_impl.h b/components/autofill/content/browser/autofill_driver_impl.h index 51fd308..099ac0d 100644 --- a/components/autofill/content/browser/autofill_driver_impl.h +++ b/components/autofill/content/browser/autofill_driver_impl.h @@ -45,7 +45,6 @@ class AutofillDriverImpl : public AutofillDriver, // AutofillDriver: virtual bool IsOffTheRecord() const OVERRIDE; virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE; - virtual content::WebContents* GetWebContents() OVERRIDE; virtual base::SequencedWorkerPool* GetBlockingPool() OVERRIDE; virtual bool RendererIsAvailable() OVERRIDE; virtual void SetRendererActionOnFormDataReception( @@ -62,6 +61,9 @@ class AutofillDriverImpl : public AutofillDriver, virtual void RendererShouldClearPreviewedForm() OVERRIDE; virtual void RendererShouldSetNodeText(const base::string16& value) OVERRIDE; + // Returns the WebContents with which this instance is associated. + content::WebContents* GetWebContents(); + AutofillExternalDelegate* autofill_external_delegate() { return &autofill_external_delegate_; } diff --git a/components/autofill/content/browser/request_autocomplete_manager_unittest.cc b/components/autofill/content/browser/request_autocomplete_manager_unittest.cc index 5415625..378ba49 100644 --- a/components/autofill/content/browser/request_autocomplete_manager_unittest.cc +++ b/components/autofill/content/browser/request_autocomplete_manager_unittest.cc @@ -74,9 +74,8 @@ class TestAutofillDriverImpl : public AutofillDriverImpl { TestAutofillDriverImpl(content::WebContents* contents, AutofillManagerDelegate* delegate) : AutofillDriverImpl(contents, delegate, kAppLocale, kDownloadState) { - scoped_ptr<AutofillManager> autofill_manager( - new TestAutofillManager(this, delegate)); - SetAutofillManager(autofill_manager.Pass()); + SetAutofillManager(make_scoped_ptr<AutofillManager>( + new TestAutofillManager(this, delegate))); } virtual ~TestAutofillDriverImpl() {} diff --git a/components/autofill/core/browser/DEPS b/components/autofill/core/browser/DEPS index ee70c1f..a75ce94 100644 --- a/components/autofill/core/browser/DEPS +++ b/components/autofill/core/browser/DEPS @@ -12,17 +12,10 @@ include_rules = [ # # Do not add to the list of temporarily-allowed dependencies below, # and please do not introduce more #includes of these files. - "!content/public/browser/render_view_host.h", - "!content/public/browser/web_contents.h", "!third_party/WebKit/public/web/WebAutofillClient.h", ] specific_include_rules = { - 'test_autofill_driver.*': [ - # TODO(blundell): Eliminate the need for TestAutofillDriver to be a - # WebContentsObserver. - "!content/public/browser/web_contents_observer.h", - ], 'autofill_test_utils\.cc': [ # TODO(blundell): Bring this list to zero. # diff --git a/components/autofill/core/browser/autocomplete_history_manager_unittest.cc b/components/autofill/core/browser/autocomplete_history_manager_unittest.cc index 7fd26a7..2e7ce5f 100644 --- a/components/autofill/core/browser/autocomplete_history_manager_unittest.cc +++ b/components/autofill/core/browser/autocomplete_history_manager_unittest.cc @@ -69,13 +69,14 @@ class MockAutofillManagerDelegate } // namespace -class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { +class AutocompleteHistoryManagerTest : public testing::Test { protected: + AutocompleteHistoryManagerTest() {} + virtual void SetUp() OVERRIDE { - ChromeRenderViewHostTestHarness::SetUp(); web_data_service_ = new MockWebDataService(); manager_delegate_.reset(new MockAutofillManagerDelegate(web_data_service_)); - autofill_driver_.reset(new TestAutofillDriver(web_contents())); + autofill_driver_.reset(new TestAutofillDriver()); autocomplete_manager_.reset( new AutocompleteHistoryManager(autofill_driver_.get(), manager_delegate_.get())); @@ -83,9 +84,9 @@ class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { virtual void TearDown() OVERRIDE { autocomplete_manager_.reset(); - ChromeRenderViewHostTestHarness::TearDown(); } + base::MessageLoop message_loop_; scoped_refptr<MockWebDataService> web_data_service_; scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_; scoped_ptr<AutofillDriver> autofill_driver_; diff --git a/components/autofill/core/browser/autofill_download_unittest.cc b/components/autofill/core/browser/autofill_download_unittest.cc index 498f03b..d99c8ca 100644 --- a/components/autofill/core/browser/autofill_download_unittest.cc +++ b/components/autofill/core/browser/autofill_download_unittest.cc @@ -65,8 +65,7 @@ class AutofillDownloadTest : public AutofillDownloadManager::Observer, public testing::Test { public: AutofillDownloadTest() - : driver_(NULL), - download_manager_(&driver_, profile_.GetPrefs(), this) { + : download_manager_(&driver_, profile_.GetPrefs(), this) { driver_.SetURLRequestContext(profile_.GetRequestContext()); } diff --git a/components/autofill/core/browser/autofill_driver.h b/components/autofill/core/browser/autofill_driver.h index b599c4d..933ef68 100644 --- a/components/autofill/core/browser/autofill_driver.h +++ b/components/autofill/core/browser/autofill_driver.h @@ -13,10 +13,6 @@ namespace base { class SequencedWorkerPool; } -namespace content { -class WebContents; -} - namespace net { class URLRequestContextGetter; } @@ -47,10 +43,6 @@ class AutofillDriver { // Returns the URL request context information associated with this driver. virtual net::URLRequestContextGetter* GetURLRequestContext() = 0; - // TODO(blundell): Remove this method once shared code no longer needs to - // know about WebContents. - virtual content::WebContents* GetWebContents() = 0; - // Returns the SequencedWorkerPool on which core Autofill code should run // tasks that may block. This pool must live at least as long as the driver. virtual base::SequencedWorkerPool* GetBlockingPool() = 0; diff --git a/components/autofill/core/browser/autofill_external_delegate_unittest.cc b/components/autofill/core/browser/autofill_external_delegate_unittest.cc index fe0f6f7..3b8acbe 100644 --- a/components/autofill/core/browser/autofill_external_delegate_unittest.cc +++ b/components/autofill/core/browser/autofill_external_delegate_unittest.cc @@ -5,9 +5,9 @@ #include <vector> #include "base/compiler_specific.h" +#include "base/message_loop/message_loop.h" #include "base/strings/string16.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/testing_profile.h" #include "components/autofill/core/browser/autofill_manager.h" #include "components/autofill/core/browser/test_autofill_driver.h" @@ -36,9 +36,7 @@ const int kAutofillProfileId = 1; class MockAutofillDriver : public TestAutofillDriver { public: - explicit MockAutofillDriver(content::WebContents* web_contents) - : TestAutofillDriver(web_contents) {} - + MockAutofillDriver() {} // Mock methods to enable testability. MOCK_METHOD1(SetRendererActionOnFormDataReception, void(RendererFormDataAction action)); @@ -98,12 +96,10 @@ class MockAutofillManager : public AutofillManager { } // namespace -class AutofillExternalDelegateUnitTest - : public ChromeRenderViewHostTestHarness { +class AutofillExternalDelegateUnitTest : public testing::Test { protected: virtual void SetUp() OVERRIDE { - ChromeRenderViewHostTestHarness::SetUp(); - autofill_driver_.reset(new MockAutofillDriver(web_contents())); + autofill_driver_.reset(new MockAutofillDriver()); autofill_manager_.reset( new MockAutofillManager(autofill_driver_.get(), &manager_delegate_)); @@ -114,13 +110,10 @@ class AutofillExternalDelegateUnitTest virtual void TearDown() OVERRIDE { // Order of destruction is important as AutofillManager relies on - // PersonalDataManager to be around when it gets destroyed. Also, a real - // AutofillManager is tied to the lifetime of the WebContents, so it must - // be destroyed at the destruction of the WebContents. + // PersonalDataManager to be around when it gets destroyed. autofill_manager_.reset(); external_delegate_.reset(); autofill_driver_.reset(); - ChromeRenderViewHostTestHarness::TearDown(); } // Issue an OnQuery call with the given |query_id|. @@ -138,6 +131,8 @@ class AutofillExternalDelegateUnitTest scoped_ptr<MockAutofillDriver> autofill_driver_; scoped_ptr<MockAutofillManager> autofill_manager_; scoped_ptr<AutofillExternalDelegate> external_delegate_; + + base::MessageLoop message_loop_; }; // Test that our external delegate called the virtual methods at the right time. diff --git a/components/autofill/core/browser/autofill_manager.cc b/components/autofill/core/browser/autofill_manager.cc index 22ec8be..baac144 100644 --- a/components/autofill/core/browser/autofill_manager.cc +++ b/components/autofill/core/browser/autofill_manager.cc @@ -43,7 +43,6 @@ #include "components/autofill/core/common/form_field_data.h" #include "components/autofill/core/common/password_form_fill_data.h" #include "components/user_prefs/pref_registry_syncable.h" -#include "content/public/browser/web_contents.h" #include "grit/component_strings.h" #include "third_party/WebKit/public/web/WebAutofillClient.h" #include "ui/base/l10n/l10n_util.h" @@ -55,7 +54,6 @@ namespace autofill { typedef PersonalDataManager::GUIDPair GUIDPair; using base::TimeTicks; -using content::RenderViewHost; namespace { @@ -309,8 +307,7 @@ void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, if (is_post_document_load) Reset(); - RenderViewHost* host = driver_->GetWebContents()->GetRenderViewHost(); - if (!host) + if (!driver_->RendererIsAvailable()) return; bool enabled = IsAutofillEnabled(); @@ -369,11 +366,10 @@ void AutofillManager::OnQueryFormFieldAutofill(int query_id, field, bounding_box, display_warning); - - RenderViewHost* host = NULL; FormStructure* form_structure = NULL; AutofillField* autofill_field = NULL; - if (GetHost(&host) && + if (RefreshDataModels() && + driver_->RendererIsAvailable() && GetCachedFormAndField(form, field, &form_structure, &autofill_field) && // Don't send suggestions for forms that aren't auto-fillable. form_structure->IsAutofillable(false)) { @@ -447,20 +443,19 @@ void AutofillManager::OnFillAutofillFormData(int query_id, const FormData& form, const FormFieldData& field, int unique_id) { - RenderViewHost* host = NULL; const AutofillDataModel* data_model = NULL; size_t variant = 0; FormStructure* form_structure = NULL; AutofillField* autofill_field = NULL; - // NOTE: GetHost may invalidate |data_model| because it causes the - // PersonalDataManager to reload Mac address book entries. Thus it must - // come before GetProfileOrCreditCard. - if (!GetHost(&host) || + // NOTE: RefreshDataModels may invalidate |data_model| because it causes the + // PersonalDataManager to reload Mac address book entries. Thus it must come + // before GetProfileOrCreditCard. + if (!RefreshDataModels() || + !driver_->RendererIsAvailable() || !GetProfileOrCreditCard(unique_id, &data_model, &variant) || !GetCachedFormAndField(form, field, &form_structure, &autofill_field)) return; - DCHECK(host); DCHECK(form_structure); DCHECK(autofill_field); @@ -791,7 +786,6 @@ AutofillManager::AutofillManager(AutofillDriver* driver, test_delegate_(NULL), weak_ptr_factory_(this) { DCHECK(driver_); - DCHECK(driver_->GetWebContents()); DCHECK(manager_delegate_); } @@ -799,7 +793,7 @@ void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) { metric_logger_.reset(metric_logger); } -bool AutofillManager::GetHost(RenderViewHost** host) const { +bool AutofillManager::RefreshDataModels() const { if (!IsAutofillEnabled()) return false; @@ -809,10 +803,6 @@ bool AutofillManager::GetHost(RenderViewHost** host) const { return false; } - if (!driver_->RendererIsAvailable()) - return false; - - *host = driver_->GetWebContents()->GetRenderViewHost(); return true; } diff --git a/components/autofill/core/browser/autofill_manager.h b/components/autofill/core/browser/autofill_manager.h index 735f18a..f1ce426 100644 --- a/components/autofill/core/browser/autofill_manager.h +++ b/components/autofill/core/browser/autofill_manager.h @@ -211,9 +211,8 @@ class AutofillManager : public AutofillDownloadManager::Observer { virtual void OnLoadedServerPredictions( const std::string& response_xml) OVERRIDE; - // Fills |host| with the RenderViewHost for this tab. - // Returns false if Autofill is disabled or if the host is unavailable. - bool GetHost(content::RenderViewHost** host) const WARN_UNUSED_RESULT; + // Returns false if Autofill is disabled or if no Autofill data is available. + bool RefreshDataModels() const; // Unpacks |unique_id| and fills |form_group| and |variant| with the // appropriate data source and variant index. Returns false if the unpacked diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc index 138f7d4..5074284 100644 --- a/components/autofill/core/browser/autofill_manager_unittest.cc +++ b/components/autofill/core/browser/autofill_manager_unittest.cc @@ -42,7 +42,6 @@ #include "components/autofill/core/common/form_field_data.h" #include "components/autofill/core/common/forms_seen_state.h" #include "components/user_prefs/user_prefs.h" -#include "content/public/browser/web_contents.h" #include "content/public/test/mock_render_process_host.h" #include "content/public/test/test_utils.h" #include "grit/component_strings.h" @@ -391,8 +390,7 @@ class MockAutocompleteHistoryManager : public AutocompleteHistoryManager { class MockAutofillDriver : public TestAutofillDriver { public: - explicit MockAutofillDriver(content::WebContents* web_contents) - : TestAutofillDriver(web_contents) {} + MockAutofillDriver() {} // Mock methods to enable testability. MOCK_METHOD2(SendFormDataToRenderer, void(int query_id, @@ -631,7 +629,7 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness { autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()); personal_data_.set_database(manager_delegate->GetDatabase()); personal_data_.set_pref_service(profile()->GetPrefs()); - autofill_driver_.reset(new MockAutofillDriver(web_contents())); + autofill_driver_.reset(new MockAutofillDriver()); autofill_manager_.reset(new TestAutofillManager( autofill_driver_.get(), manager_delegate, &personal_data_)); diff --git a/components/autofill/core/browser/autofill_metrics_unittest.cc b/components/autofill/core/browser/autofill_metrics_unittest.cc index 8eb952b..0febf13 100644 --- a/components/autofill/core/browser/autofill_metrics_unittest.cc +++ b/components/autofill/core/browser/autofill_metrics_unittest.cc @@ -290,7 +290,7 @@ void AutofillMetricsTest::SetUp() { personal_data_.reset(new TestPersonalDataManager()); personal_data_->set_database(manager_delegate->GetDatabase()); personal_data_->set_pref_service(profile()->GetPrefs()); - autofill_driver_.reset(new TestAutofillDriver(web_contents())); + autofill_driver_.reset(new TestAutofillDriver()); autofill_manager_.reset(new TestAutofillManager( autofill_driver_.get(), manager_delegate, personal_data_.get())); @@ -302,9 +302,7 @@ void AutofillMetricsTest::SetUp() { void AutofillMetricsTest::TearDown() { // Order of destruction is important as AutofillManager relies on - // PersonalDataManager to be around when it gets destroyed. Also, a real - // AutofillManager is tied to the lifetime of the WebContents, so it must - // be destroyed at the destruction of the WebContents. + // PersonalDataManager to be around when it gets destroyed. autofill_manager_.reset(); autofill_driver_.reset(); personal_data_.reset(); diff --git a/components/autofill/core/browser/password_autofill_manager_unittest.cc b/components/autofill/core/browser/password_autofill_manager_unittest.cc index a5bb791..5a4767a 100644 --- a/components/autofill/core/browser/password_autofill_manager_unittest.cc +++ b/components/autofill/core/browser/password_autofill_manager_unittest.cc @@ -22,7 +22,7 @@ namespace { class MockAutofillDriver : public autofill::TestAutofillDriver { public: - MockAutofillDriver() : autofill::TestAutofillDriver(NULL) {} + MockAutofillDriver() {} MOCK_METHOD1(RendererShouldAcceptPasswordAutofillSuggestion, void(const base::string16&)); }; diff --git a/components/autofill/core/browser/test_autofill_driver.cc b/components/autofill/core/browser/test_autofill_driver.cc index 780c01a..bbeaa10 100644 --- a/components/autofill/core/browser/test_autofill_driver.cc +++ b/components/autofill/core/browser/test_autofill_driver.cc @@ -8,9 +8,8 @@ namespace autofill { -TestAutofillDriver::TestAutofillDriver(content::WebContents* web_contents) - : content::WebContentsObserver(web_contents), - blocking_pool_(new base::SequencedWorkerPool(4, "TestAutofillDriver")), +TestAutofillDriver::TestAutofillDriver() + : blocking_pool_(new base::SequencedWorkerPool(4, "TestAutofillDriver")), url_request_context_(NULL) {} TestAutofillDriver::~TestAutofillDriver() { @@ -25,10 +24,6 @@ net::URLRequestContextGetter* TestAutofillDriver::GetURLRequestContext() { return url_request_context_; } -content::WebContents* TestAutofillDriver::GetWebContents() { - return web_contents(); -} - base::SequencedWorkerPool* TestAutofillDriver::GetBlockingPool() { return blocking_pool_; } diff --git a/components/autofill/core/browser/test_autofill_driver.h b/components/autofill/core/browser/test_autofill_driver.h index 5ebd4d6..343b657b 100644 --- a/components/autofill/core/browser/test_autofill_driver.h +++ b/components/autofill/core/browser/test_autofill_driver.h @@ -9,17 +9,13 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "components/autofill/core/browser/autofill_driver.h" -#include "content/public/browser/web_contents_observer.h" namespace autofill { // This class is only for easier writing of tests. -// TODO(blundell): Eliminate this class being a WebContentsObserver once -// autofill shared code no longer needs knowledge of WebContents. -class TestAutofillDriver : public AutofillDriver, - public content::WebContentsObserver { +class TestAutofillDriver : public AutofillDriver { public: - explicit TestAutofillDriver(content::WebContents* web_contents); + TestAutofillDriver(); virtual ~TestAutofillDriver(); // AutofillDriver implementation. @@ -27,7 +23,6 @@ class TestAutofillDriver : public AutofillDriver, // Returns the value passed in to the last call to |SetURLRequestContext()| // or NULL if that method has never been called. virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE; - virtual content::WebContents* GetWebContents() OVERRIDE; virtual base::SequencedWorkerPool* GetBlockingPool() OVERRIDE; virtual bool RendererIsAvailable() OVERRIDE; virtual void SetRendererActionOnFormDataReception( |