diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-15 16:26:54 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-15 16:26:54 +0000 |
commit | 049ac83121b991e8ff7ea5195401ce14dec064fa (patch) | |
tree | e8ba94dabb77a9e0356f56d4ef1d4b93bfd7e884 /chrome | |
parent | e9a1a8ddf2167d7a052ac4736b7f5ae622d1e8b2 (diff) | |
download | chromium_src-049ac83121b991e8ff7ea5195401ce14dec064fa.zip chromium_src-049ac83121b991e8ff7ea5195401ce14dec064fa.tar.gz chromium_src-049ac83121b991e8ff7ea5195401ce14dec064fa.tar.bz2 |
Commit issue 464079 for feldstein: limit the clear browsing data window to only pop up once.
BUG= 24980
TEST= see http://codereview.chromium.org/464079/show
Review URL: http://codereview.chromium.org/501001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34557 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
6 files changed, 69 insertions, 19 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index 21811ad..08d61b8 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -560,10 +560,8 @@ static bool g_is_opening_new_window = false; break; case IDC_CLEAR_BROWSING_DATA: { // There may not be a browser open, so use the default profile. - scoped_nsobject<ClearBrowsingDataController> controller( - [[ClearBrowsingDataController alloc] - initWithProfile:defaultProfile]); - [controller runModalDialog]; + [ClearBrowsingDataController + showClearBrowsingDialogForProfile:defaultProfile]; break; } case IDC_IMPORT_SETTINGS: { diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index 707a8a2..dc7566b 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -283,10 +283,8 @@ void BrowserWindowCocoa::ShowReportBugDialog() { } void BrowserWindowCocoa::ShowClearBrowsingDataDialog() { - scoped_nsobject<ClearBrowsingDataController> controller( - [[ClearBrowsingDataController alloc] - initWithProfile:browser_->profile()]); - [controller runModalDialog]; + [ClearBrowsingDataController + showClearBrowsingDialogForProfile:browser_->profile()]; } void BrowserWindowCocoa::ShowImportDialog() { diff --git a/chrome/browser/cocoa/clear_browsing_data_controller.h b/chrome/browser/cocoa/clear_browsing_data_controller.h index 3a8150b..4b75024 100644 --- a/chrome/browser/cocoa/clear_browsing_data_controller.h +++ b/chrome/browser/cocoa/clear_browsing_data_controller.h @@ -39,8 +39,10 @@ class Profile; NSInteger timePeriod_; } -// Create the controller with the given profile (which must not be NULL). -- (id)initWithProfile:(Profile*)profile; +// Show the clear browsing data window. Do not use |-initWithProfile:|, +// go through this instead so we don't end up with multiple instances. ++ (void)showClearBrowsingDialogForProfile:(Profile*)profile; ++ (ClearBrowsingDataController*)controllerForProfile:(Profile*)profile; // Run the dialog with an application-modal event loop. If the user accepts, // performs the deletion of the selected browsing data. The values of the @@ -65,8 +67,11 @@ class Profile; @interface ClearBrowsingDataController (ExposedForUnitTests) +// Create the controller with the given profile (which must not be NULL). +- (id)initWithProfile:(Profile*)profile; @property (readonly) int removeMask; - (void)persistToPrefs; +- (void)closeDialog; @end #endif // CHROME_BROWSER_COCOA_CLEAR_BROWSING_DATA_CONTROLLER_ diff --git a/chrome/browser/cocoa/clear_browsing_data_controller.mm b/chrome/browser/cocoa/clear_browsing_data_controller.mm index 1384bac..28ad931 100644 --- a/chrome/browser/cocoa/clear_browsing_data_controller.mm +++ b/chrome/browser/cocoa/clear_browsing_data_controller.mm @@ -6,6 +6,7 @@ #include "base/mac_util.h" #include "base/scoped_nsobject.h" +#include "base/singleton.h" #include "chrome/browser/browsing_data_remover.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" @@ -26,6 +27,12 @@ class ClearBrowsingObserver : public BrowsingDataRemover::Observer { ClearBrowsingDataController* controller_; }; +namespace { + +typedef std::map<Profile*, ClearBrowsingDataController*> ProfileControllerMap; + +} // namespace + @implementation ClearBrowsingDataController @synthesize clearBrowsingHistory = clearBrowsingHistory_; @@ -37,6 +44,34 @@ class ClearBrowsingObserver : public BrowsingDataRemover::Observer { @synthesize timePeriod = timePeriod_; @synthesize isClearing = isClearing_; ++ (void)showClearBrowsingDialogForProfile:(Profile*)profile { + ClearBrowsingDataController* controller = + [ClearBrowsingDataController controllerForProfile:profile]; + if (![controller isWindowLoaded]) { + [controller runModalDialog]; + } +} + ++ (ClearBrowsingDataController *)controllerForProfile:(Profile*)profile { + // Get the original profile in case we get here from an incognito window + // |GetOriginalProfile()| will return the same profile if it is the original + // profile. + profile = profile->GetOriginalProfile(); + + ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); + DCHECK(map != NULL); + ProfileControllerMap::iterator it = map->find(profile); + if (it == map->end()) { + // Since we don't currently support multiple profiles, this class + // has not been tested against this case. + DCHECK_EQ(map->size(), 0U); + + ClearBrowsingDataController* controller = + [[self alloc] initWithProfile:profile]; + it = map->insert(std::make_pair(profile, controller)).first; + } + return it->second; +} - (id)initWithProfile:(Profile*)profile { DCHECK(profile); @@ -60,6 +95,7 @@ class ClearBrowsingObserver : public BrowsingDataRemover::Observer { // while clearing is in progress as the dialog is modal and not closeable). remover_->RemoveObserver(observer_.get()); } + [super dealloc]; } @@ -106,8 +142,18 @@ class ClearBrowsingObserver : public BrowsingDataRemover::Observer { // Called when the user clicks the cancel button. All we need to do is stop // the modal session. - (IBAction)cancel:(id)sender { - [NSApp stopModal]; + [self closeDialog]; +} + +- (void)closeDialog { + ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); + ProfileControllerMap::iterator it = map->find(profile_); + if (it != map->end()) { + map->erase(it); + } + [self autorelease]; [[self window] orderOut:self]; + [NSApp stopModal]; } // Initialize the bools from prefs using the setters to be KVO-compliant. @@ -141,7 +187,7 @@ class ClearBrowsingObserver : public BrowsingDataRemover::Observer { // Called when the data remover object is done with its work. Close the window. // The remover will delete itself. End the modal session at this point. - (void)dataRemoverDidFinish { - [NSApp stopModal]; + [self closeDialog]; [[self window] orderOut:self]; [self setIsClearing:NO]; remover_ = NULL; diff --git a/chrome/browser/cocoa/clear_browsing_data_controller_unittest.mm b/chrome/browser/cocoa/clear_browsing_data_controller_unittest.mm index ade7f91..15b2ee0 100644 --- a/chrome/browser/cocoa/clear_browsing_data_controller_unittest.mm +++ b/chrome/browser/cocoa/clear_browsing_data_controller_unittest.mm @@ -31,13 +31,12 @@ class ClearBrowsingDataControllerTest : public CocoaTest { prefs->SetBoolean(prefs::kDeleteFormData, false); prefs->SetInteger(prefs::kDeleteTimePeriod, BrowsingDataRemover::FOUR_WEEKS); - controller_ = - [[ClearBrowsingDataController alloc] initWithProfile:helper_.profile()]; + [ClearBrowsingDataController controllerForProfile:helper_.profile()]; } virtual void TearDown() { - [controller_ close]; + [controller_ closeDialog]; CocoaTest::TearDown(); } @@ -113,4 +112,10 @@ TEST_F(ClearBrowsingDataControllerTest, PersistToPrefs) { prefs->GetInteger(prefs::kDeleteTimePeriod)); } +TEST_F(ClearBrowsingDataControllerTest, SameControllerForProfile) { + ClearBrowsingDataController* controller = + [ClearBrowsingDataController controllerForProfile:helper_.profile()]; + EXPECT_EQ(controller_, controller); +} + } // namespace diff --git a/chrome/browser/cocoa/preferences_window_controller.mm b/chrome/browser/cocoa/preferences_window_controller.mm index 5e8d99b..6bed529 100644 --- a/chrome/browser/cocoa/preferences_window_controller.mm +++ b/chrome/browser/cocoa/preferences_window_controller.mm @@ -1148,10 +1148,8 @@ const int kDisabledIndex = 1; // Called to clear user's browsing data. This puts up an application-modal // dialog to guide the user through clearing the data. - (IBAction)clearData:(id)sender { - scoped_nsobject<ClearBrowsingDataController> controller( - [[ClearBrowsingDataController alloc] - initWithProfile:profile_]); - [controller runModalDialog]; + [ClearBrowsingDataController + showClearBrowsingDialogForProfile:profile_]; } - (IBAction)resetThemeToDefault:(id)sender { |