Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/browser/cocoa/clear_browsing_data_controller.mm

Issue 112065: Implement Clear Browser Data for Mac as an app modal dialog. Uses the profile... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/cocoa/clear_browsing_data_controller.h"
6
7 #include "base/mac_util.h"
8 #include "base/scoped_nsobject.h"
9 #include "chrome/browser/browsing_data_remover.h"
10 #include "chrome/common/pref_names.h"
11 #include "chrome/common/pref_service.h"
12 #include "chrome/browser/profile.h"
13
14 @interface ClearBrowsingDataController(Private)
15 - (void)initFromPrefs;
16 - (void)persistToPrefs;
17 - (void)dataRemoverDidFinish;
18 @end
19
20 class ClearBrowsingObserver : public BrowsingDataRemover::Observer {
21 public:
22 ClearBrowsingObserver(ClearBrowsingDataController* controller)
23 : controller_(controller) { }
24 void OnBrowsingDataRemoverDone() { [controller_ dataRemoverDidFinish]; }
25 private:
26 ClearBrowsingDataController* controller_;
27 };
28
29 @implementation ClearBrowsingDataController
30
31 @synthesize clearBrowsingHistory = clearBrowsingHistory_;
32 @synthesize clearDownloadHistory = clearDownloadHistory_;
33 @synthesize emptyCache = emptyCache_;
34 @synthesize deleteCookies = deleteCookies_;
35 @synthesize clearSavedPasswords = clearSavedPasswords_;
36 @synthesize clearFormData = clearFormData_;
37 @synthesize timePeriod = timePeriod_;
38 @synthesize isClearing = isClearing_;
39
40
41 - (id)initWithProfile:(Profile*)profile {
42 DCHECK(profile);
43 // Use initWithWindowNibPath:: instead of initWithWindowNibName: so we
44 // can override it in a unit test.
45 NSString *nibpath = [mac_util::MainAppBundle()
46 pathForResource:@"ClearBrowsingData"
47 ofType:@"nib"];
48 if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
49 profile_ = profile;
50 observer_.reset(new ClearBrowsingObserver(self));
51 [self initFromPrefs];
52 }
53 return self;
54 }
55
56 - (void)dealloc {
57 if (remover_) {
58 // We were destroyed while clearing history was in progress. This can only
59 // occur during automated tests (normally the user can't close the dialog
60 // while clearing is in progress as the dialog is modal and not closeable).
61 remover_->RemoveObserver(observer_.get());
62 }
63 [super dealloc];
64 }
65
66 // Called when outlets are available. Set the throbber icon.
67 - (void)awakeFromNib {
68 NSString *imagePath = [mac_util::MainAppBundle()
69 pathForResource:@"throbber"
70 ofType:@"png"];
71 scoped_nsobject<NSImage> throbberImage(
72 [[NSImage alloc] initWithContentsOfFile:imagePath]);
73 [progress_ setImage:throbberImage];
74 }
75
76 // Run application modal.
77 - (void)runModalDialog {
78 [[NSApplication sharedApplication] runModalForWindow:[self window]];
79 }
80
81 // Called when the user clicks the "clear" button. Do the work and persist
82 // the prefs for next time. We don't stop the modal session until we get
83 // the callback from the BrowsingDataRemover so the window stays on the screen.
84 // While we're working, dim the buttons so the user can't click them.
85 - (IBAction)clearData:(id)sender {
86 // Set that we're working so that the buttons disable.
87 [self setIsClearing:YES];
88
89 [self persistToPrefs];
90
91 int removeMask = 0L;
92 if (clearBrowsingHistory_)
93 removeMask |= BrowsingDataRemover::REMOVE_HISTORY;
94 if (clearDownloadHistory_)
95 removeMask |= BrowsingDataRemover::REMOVE_DOWNLOADS;
96 if (emptyCache_)
97 removeMask |= BrowsingDataRemover::REMOVE_CACHE;
98 if (deleteCookies_)
99 removeMask |= BrowsingDataRemover::REMOVE_COOKIES;
100 if (clearSavedPasswords_)
101 removeMask |= BrowsingDataRemover::REMOVE_PASSWORDS;
102 if (clearFormData_)
103 removeMask |= BrowsingDataRemover::REMOVE_PASSWORDS;
104
105 // BrowsingDataRemover deletes itself when done.
106 remover_ = new BrowsingDataRemover(profile_,
107 static_cast<BrowsingDataRemover::TimePeriod>(timePeriod_),
108 base::Time());
109 remover_->AddObserver(observer_.get());
110 remover_->Remove(removeMask);
111 }
112
113 // Called when the user clicks the cancel button. All we need to do is stop
114 // the modal session.
115 - (IBAction)cancel:(id)sender {
116 [[NSApplication sharedApplication] stopModal];
117 [[self window] orderOut:self];
118 }
119
120 // Initialize the bools from prefs using the setters to be KVO-compliant.
121 - (void)initFromPrefs {
122 PrefService* prefs = profile_->GetPrefs();
123 [self setClearBrowsingHistory:
124 prefs->GetBoolean(prefs::kDeleteBrowsingHistory)];
125 [self setClearDownloadHistory:
126 prefs->GetBoolean(prefs::kDeleteDownloadHistory)];
127 [self setEmptyCache:prefs->GetBoolean(prefs::kDeleteCache)];
128 [self setDeleteCookies:prefs->GetBoolean(prefs::kDeleteCookies)];
129 [self setClearSavedPasswords:prefs->GetBoolean(prefs::kDeletePasswords)];
130 [self setClearFormData:prefs->GetBoolean(prefs::kDeleteFormData)];
131 [self setTimePeriod:prefs->GetInteger(prefs::kDeleteTimePeriod)];
132 }
133
134 // Save the checkbox values to the preferences.
135 - (void)persistToPrefs {
136 PrefService* prefs = profile_->GetPrefs();
137 prefs->SetBoolean(prefs::kDeleteBrowsingHistory,
138 [self clearBrowsingHistory]);
139 prefs->SetBoolean(prefs::kDeleteDownloadHistory,
140 [self clearDownloadHistory]);
141 prefs->SetBoolean(prefs::kDeleteCache, [self emptyCache]);
142 prefs->SetBoolean(prefs::kDeleteCookies, [self deleteCookies]);
143 prefs->SetBoolean(prefs::kDeletePasswords, [self clearSavedPasswords]);
144 prefs->SetBoolean(prefs::kDeleteFormData, [self clearFormData]);
145 prefs->SetInteger(prefs::kDeleteTimePeriod, [self timePeriod]);
146 }
147
148 // Called when the data remover object is done with its work. Close the window.
149 // The remover will delete itself. End the modal session at this point.
150 - (void)dataRemoverDidFinish {
151 [[NSApplication sharedApplication] stopModal];
152 [[self window] orderOut:self];
153 [self setIsClearing:NO];
154 remover_ = NULL;
155 }
156
157 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698