diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-03 20:08:59 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-03 20:08:59 +0000 |
commit | 36c1ff9fd1b301c7b2de0f364e9ba10835d3a9c6 (patch) | |
tree | 1db4b79cff59183ba947a7994522efaaab619c21 /chrome/browser/autofill | |
parent | ad3c0f1de336eef69795f1228101cd0486ec0a4c (diff) | |
download | chromium_src-36c1ff9fd1b301c7b2de0f364e9ba10835d3a9c6.zip chromium_src-36c1ff9fd1b301c7b2de0f364e9ba10835d3a9c6.tar.gz chromium_src-36c1ff9fd1b301c7b2de0f364e9ba10835d3a9c6.tar.bz2 |
AutoFill: Make PersonalDataManager RefCountedThreadSafe.
BUG=40617
TEST=none
Review URL: http://codereview.chromium.org/2521001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48858 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
5 files changed, 32 insertions, 18 deletions
diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm index fb1f38e..b82c377 100644 --- a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm +++ b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/ref_counted.h" #import "chrome/browser/autofill/autofill_address_model_mac.h" #import "chrome/browser/autofill/autofill_address_view_controller_mac.h" #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" @@ -70,7 +71,7 @@ class PersonalDataManagerMock : public PersonalDataManager { class ProfileMock : public TestingProfile { public: ProfileMock() { - test_manager_.reset(new PersonalDataManagerMock); + test_manager_ =new PersonalDataManagerMock; } virtual ~ProfileMock() {} @@ -78,7 +79,7 @@ class ProfileMock : public TestingProfile { return test_manager_.get(); } - scoped_ptr<PersonalDataManagerMock> test_manager_; + scoped_refptr<PersonalDataManagerMock> test_manager_; private: DISALLOW_COPY_AND_ASSIGN(ProfileMock); @@ -245,16 +246,18 @@ TEST_F(AutoFillDialogControllerTest, AutoFillDataMutation) { profile.SetInfo(AutoFillType(EMAIL_ADDRESS), ASCIIToUTF16("dhollowa@chromium.org")); profile.SetInfo(AutoFillType(COMPANY_NAME), ASCIIToUTF16("Google Inc.")); - profile.SetInfo( - AutoFillType(ADDRESS_HOME_LINE1), ASCIIToUTF16("1122 Mountain View Road")); + profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), + ASCIIToUTF16("1122 Mountain View Road")); profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), ASCIIToUTF16("Suite #1")); profile.SetInfo(AutoFillType(ADDRESS_HOME_CITY), ASCIIToUTF16("Mountain View")); profile.SetInfo(AutoFillType(ADDRESS_HOME_STATE), ASCIIToUTF16("CA")); profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP), ASCIIToUTF16("94111")); profile.SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("USA")); - profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), ASCIIToUTF16("014155552258")); - profile.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), ASCIIToUTF16("024087172258")); + profile.SetInfo( + AutoFillType(PHONE_HOME_WHOLE_NUMBER), ASCIIToUTF16("014155552258")); + profile.SetInfo( + AutoFillType(PHONE_FAX_WHOLE_NUMBER), ASCIIToUTF16("024087172258")); profiles().push_back(&profile); LoadDialog(); diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h index 262a8a0..546f02c 100644 --- a/chrome/browser/autofill/autofill_manager.h +++ b/chrome/browser/autofill/autofill_manager.h @@ -99,6 +99,9 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill, AutoFillManager(); AutoFillManager(TabContents* tab_contents, PersonalDataManager* personal_data); + void set_personal_data_manager(PersonalDataManager* personal_data) { + personal_data_ = personal_data; + } private: // Returns a list of values from the stored profiles that match |type| and the diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc index a54b04d..e8ecac3 100644 --- a/chrome/browser/autofill/autofill_manager_unittest.cc +++ b/chrome/browser/autofill/autofill_manager_unittest.cc @@ -4,6 +4,7 @@ #include <vector> +#include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "base/scoped_vector.h" #include "base/string16.h" @@ -87,17 +88,19 @@ class TestPersonalDataManager : public PersonalDataManager { class TestAutoFillManager : public AutoFillManager { public: explicit TestAutoFillManager(TabContents* tab_contents) - : AutoFillManager(tab_contents, &test_personal_data_) { + : AutoFillManager(tab_contents, NULL) { + test_personal_data_ = new TestPersonalDataManager(); + set_personal_data_manager(test_personal_data_.get()); } virtual bool IsAutoFillEnabled() const { return true; } AutoFillProfile* GetLabeledProfile(const char* label) { - return test_personal_data_.GetLabeledProfile(label); + return test_personal_data_->GetLabeledProfile(label); } private: - TestPersonalDataManager test_personal_data_; + scoped_refptr<TestPersonalDataManager> test_personal_data_; DISALLOW_COPY_AND_ASSIGN(TestAutoFillManager); }; diff --git a/chrome/browser/autofill/personal_data_manager.h b/chrome/browser/autofill/personal_data_manager.h index 9b5ac12..678d001 100644 --- a/chrome/browser/autofill/personal_data_manager.h +++ b/chrome/browser/autofill/personal_data_manager.h @@ -8,6 +8,7 @@ #include <set> #include <vector> +#include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "base/scoped_vector.h" #include "base/string16.h" @@ -24,8 +25,10 @@ class Profile; // Handles loading and saving AutoFill profile information to the web database. // This class also stores the profiles loaded from the database for use during // AutoFill. -class PersonalDataManager : public WebDataServiceConsumer, - public AutoFillDialogObserver { +class PersonalDataManager + : public WebDataServiceConsumer, + public AutoFillDialogObserver, + public base::RefCountedThreadSafe<PersonalDataManager> { public: // An interface the PersonalDataManager uses to notify its clients (observers) // when it has finished loading personal data from the web database. Register @@ -39,8 +42,6 @@ class PersonalDataManager : public WebDataServiceConsumer, virtual ~Observer() {} }; - virtual ~PersonalDataManager(); - // WebDataServiceConsumer implementation: virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, const WDTypedResult* result); @@ -153,12 +154,15 @@ class PersonalDataManager : public WebDataServiceConsumer, void Init(Profile* profile); protected: - // Make sure that only Profile and the PersonalDataManager tests can create an - // instance of PersonalDataManager. - friend class ProfileImpl; + // Make sure that only Profile and certain tests can create an instance of + // PersonalDataManager. + friend class base::RefCountedThreadSafe<PersonalDataManager>; friend class PersonalDataManagerTest; + friend class ProfileImpl; + friend class ProfileSyncServiceAutofillTest; PersonalDataManager(); + ~PersonalDataManager(); // Returns the profile of the tab contents. Profile* profile(); diff --git a/chrome/browser/autofill/personal_data_manager_unittest.cc b/chrome/browser/autofill/personal_data_manager_unittest.cc index 8656e25..a1ea3d0 100644 --- a/chrome/browser/autofill/personal_data_manager_unittest.cc +++ b/chrome/browser/autofill/personal_data_manager_unittest.cc @@ -4,6 +4,7 @@ #include "base/basictypes.h" #include "base/message_loop.h" +#include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "chrome/browser/autofill/autofill_common_unittest.h" #include "chrome/browser/autofill/autofill_profile.h" @@ -61,7 +62,7 @@ class PersonalDataManagerTest : public testing::Test { } void ResetPersonalDataManager() { - personal_data_.reset(new PersonalDataManager()); + personal_data_ = new PersonalDataManager(); personal_data_->Init(profile_.get()); personal_data_->SetObserver(&personal_data_observer_); @@ -82,7 +83,7 @@ class PersonalDataManagerTest : public testing::Test { ChromeThread ui_thread_; ChromeThread db_thread_; scoped_ptr<TestingProfile> profile_; - scoped_ptr<PersonalDataManager> personal_data_; + scoped_refptr<PersonalDataManager> personal_data_; NotificationRegistrar registrar_; NotificationObserverMock observer_; PersonalDataLoadedObserverMock personal_data_observer_; |