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

Side by Side Diff: chrome/browser/ui/webui/options2/clear_browser_data_handler2.cc

Issue 10502015: Adding "Clear hosted app data" checkbox to browsing data removal UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Feedback. Created 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options2/clear_browser_data_handler2.h" 5 #include "chrome/browser/ui/webui/options2/clear_browser_data_handler2.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/browsing_data_helper.h" 13 #include "chrome/browser/browsing_data_helper.h"
14 #include "chrome/browser/browsing_data_remover.h" 14 #include "chrome/browser/browsing_data_remover.h"
15 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/web_ui.h" 19 #include "content/public/browser/web_ui.h"
20 #include "grit/chromium_strings.h" 20 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
22 #include "grit/locale_settings.h" 22 #include "grit/locale_settings.h"
23 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 24
25 namespace options2 { 25 namespace options2 {
26 26
27 ClearBrowserDataHandler::ClearBrowserDataHandler() : remover_(NULL) { 27 ClearBrowserDataHandler::ClearBrowserDataHandler()
28 : remover_(NULL),
29 remove_hosted_app_data_pending_(false) {
28 } 30 }
29 31
30 ClearBrowserDataHandler::~ClearBrowserDataHandler() { 32 ClearBrowserDataHandler::~ClearBrowserDataHandler() {
31 if (remover_) 33 if (remover_)
32 remover_->RemoveObserver(this); 34 remover_->RemoveObserver(this);
33 } 35 }
34 36
35 void ClearBrowserDataHandler::InitializeHandler() { 37 void ClearBrowserDataHandler::InitializeHandler() {
36 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, 38 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled,
37 Profile::FromWebUI(web_ui())->GetPrefs(), 39 Profile::FromWebUI(web_ui())->GetPrefs(),
38 NULL); 40 NULL);
39 } 41 }
40 42
41 void ClearBrowserDataHandler::GetLocalizedValues( 43 void ClearBrowserDataHandler::GetLocalizedValues(
42 DictionaryValue* localized_strings) { 44 DictionaryValue* localized_strings) {
43 DCHECK(localized_strings); 45 DCHECK(localized_strings);
44 46
45 static OptionsStringResource resources[] = { 47 static OptionsStringResource resources[] = {
46 { "clearBrowserDataLabel", IDS_CLEAR_BROWSING_DATA_LABEL }, 48 { "clearBrowserDataLabel", IDS_CLEAR_BROWSING_DATA_LABEL },
47 { "deleteBrowsingHistoryCheckbox", IDS_DEL_BROWSING_HISTORY_CHKBOX }, 49 { "deleteBrowsingHistoryCheckbox", IDS_DEL_BROWSING_HISTORY_CHKBOX },
48 { "deleteDownloadHistoryCheckbox", IDS_DEL_DOWNLOAD_HISTORY_CHKBOX }, 50 { "deleteDownloadHistoryCheckbox", IDS_DEL_DOWNLOAD_HISTORY_CHKBOX },
49 { "deleteCacheCheckbox", IDS_DEL_CACHE_CHKBOX }, 51 { "deleteCacheCheckbox", IDS_DEL_CACHE_CHKBOX },
50 { "deleteCookiesCheckbox", IDS_DEL_COOKIES_CHKBOX }, 52 { "deleteCookiesCheckbox", IDS_DEL_COOKIES_CHKBOX },
51 { "deleteCookiesFlashCheckbox", IDS_DEL_COOKIES_FLASH_CHKBOX }, 53 { "deleteCookiesFlashCheckbox", IDS_DEL_COOKIES_FLASH_CHKBOX },
52 { "deletePasswordsCheckbox", IDS_DEL_PASSWORDS_CHKBOX }, 54 { "deletePasswordsCheckbox", IDS_DEL_PASSWORDS_CHKBOX },
53 { "deleteFormDataCheckbox", IDS_DEL_FORM_DATA_CHKBOX }, 55 { "deleteFormDataCheckbox", IDS_DEL_FORM_DATA_CHKBOX },
56 { "deleteHostedAppsDataCheckbox", IDS_DEL_HOSTED_APPS_DATA_CHKBOX },
54 { "deauthorizeContentLicensesCheckbox", 57 { "deauthorizeContentLicensesCheckbox",
55 IDS_DEAUTHORIZE_CONTENT_LICENSES_CHKBOX }, 58 IDS_DEAUTHORIZE_CONTENT_LICENSES_CHKBOX },
56 { "clearBrowserDataCommit", IDS_CLEAR_BROWSING_DATA_COMMIT }, 59 { "clearBrowserDataCommit", IDS_CLEAR_BROWSING_DATA_COMMIT },
57 { "flash_storage_url", IDS_FLASH_STORAGE_URL }, 60 { "flash_storage_url", IDS_FLASH_STORAGE_URL },
58 }; 61 };
59 62
60 RegisterStrings(localized_strings, resources, arraysize(resources)); 63 RegisterStrings(localized_strings, resources, arraysize(resources));
61 RegisterTitle(localized_strings, "clearBrowserDataOverlay", 64 RegisterTitle(localized_strings, "clearBrowserDataOverlay",
62 IDS_CLEAR_BROWSING_DATA_TITLE); 65 IDS_CLEAR_BROWSING_DATA_TITLE);
63 66
(...skipping 26 matching lines...) Expand all
90 } 93 }
91 94
92 void ClearBrowserDataHandler::RegisterMessages() { 95 void ClearBrowserDataHandler::RegisterMessages() {
93 // Setup handlers specific to this panel. 96 // Setup handlers specific to this panel.
94 web_ui()->RegisterMessageCallback("performClearBrowserData", 97 web_ui()->RegisterMessageCallback("performClearBrowserData",
95 base::Bind(&ClearBrowserDataHandler::HandleClearBrowserData, 98 base::Bind(&ClearBrowserDataHandler::HandleClearBrowserData,
96 base::Unretained(this))); 99 base::Unretained(this)));
97 } 100 }
98 101
99 void ClearBrowserDataHandler::HandleClearBrowserData(const ListValue* value) { 102 void ClearBrowserDataHandler::HandleClearBrowserData(const ListValue* value) {
103 DCHECK(!remover_);
104
100 Profile* profile = Profile::FromWebUI(web_ui()); 105 Profile* profile = Profile::FromWebUI(web_ui());
101 PrefService* prefs = profile->GetPrefs(); 106 PrefService* prefs = profile->GetPrefs();
102 107
103 int remove_mask = 0; 108 int remove_mask = 0;
104 if (prefs->GetBoolean(prefs::kDeleteBrowsingHistory)) 109 if (prefs->GetBoolean(prefs::kDeleteBrowsingHistory))
105 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY; 110 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY;
106 if (prefs->GetBoolean(prefs::kDeleteDownloadHistory)) 111 if (prefs->GetBoolean(prefs::kDeleteDownloadHistory))
107 remove_mask |= BrowsingDataRemover::REMOVE_DOWNLOADS; 112 remove_mask |= BrowsingDataRemover::REMOVE_DOWNLOADS;
108 if (prefs->GetBoolean(prefs::kDeleteCache)) 113 if (prefs->GetBoolean(prefs::kDeleteCache))
109 remove_mask |= BrowsingDataRemover::REMOVE_CACHE; 114 remove_mask |= BrowsingDataRemover::REMOVE_CACHE;
110 if (prefs->GetBoolean(prefs::kDeleteCookies)) { 115 if (prefs->GetBoolean(prefs::kDeleteCookies)) {
111 int site_data_mask = BrowsingDataRemover::REMOVE_SITE_DATA; 116 int site_data_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
112 // Don't try to clear LSO data if it's not supported. 117 // Don't try to clear LSO data if it's not supported.
113 if (!*clear_plugin_lso_data_enabled_) 118 if (!*clear_plugin_lso_data_enabled_)
114 site_data_mask &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; 119 site_data_mask &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA;
115 remove_mask |= site_data_mask; 120 remove_mask |= site_data_mask;
116 } 121 }
117 if (prefs->GetBoolean(prefs::kDeletePasswords)) 122 if (prefs->GetBoolean(prefs::kDeletePasswords))
118 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS; 123 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS;
119 if (prefs->GetBoolean(prefs::kDeleteFormData)) 124 if (prefs->GetBoolean(prefs::kDeleteFormData))
120 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; 125 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA;
121 if (prefs->GetBoolean(prefs::kDeauthorizeContentLicenses)) 126 if (prefs->GetBoolean(prefs::kDeauthorizeContentLicenses))
122 remove_mask |= BrowsingDataRemover::REMOVE_CONTENT_LICENSES; 127 remove_mask |= BrowsingDataRemover::REMOVE_CONTENT_LICENSES;
123 128
129 remove_hosted_app_data_pending_ =
130 prefs->GetBoolean(prefs::kDeleteHostedAppsData);
131
132 if (!remove_mask) {
133 // If no unprotected data should be removed, skip straight to removing
134 // hosted app data. If nothing should be removed (which would mean that the
135 // JS-side is buggy), skip straight to cleaning up.
136 if (remove_hosted_app_data_pending_)
137 ClearHostedAppData();
138 else
139 OnAllDataRemoved();
140 } else {
141 // BrowsingDataRemover deletes itself when done.
142 int period_selected = prefs->GetInteger(prefs::kDeleteTimePeriod);
143 remover_ = new BrowsingDataRemover(profile,
144 static_cast<BrowsingDataRemover::TimePeriod>(period_selected),
145 base::Time());
146 remover_->AddObserver(this);
147 remover_->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
148 }
149 }
150
151 void ClearBrowserDataHandler::ClearHostedAppData() {
152 DCHECK(!remover_);
153 DCHECK(remove_hosted_app_data_pending_);
154
155 remove_hosted_app_data_pending_ = false;
156 Profile* profile = Profile::FromWebUI(web_ui());
157 PrefService* prefs = profile->GetPrefs();
158
124 int period_selected = prefs->GetInteger(prefs::kDeleteTimePeriod); 159 int period_selected = prefs->GetInteger(prefs::kDeleteTimePeriod);
125
126 base::FundamentalValue state(true);
127 web_ui()->CallJavascriptFunction("ClearBrowserDataOverlay.setClearingState",
128 state);
129
130 // If we are still observing a previous data remover, we need to stop
131 // observing.
132 if (remover_)
133 remover_->RemoveObserver(this);
134
135 // BrowsingDataRemover deletes itself when done. 160 // BrowsingDataRemover deletes itself when done.
136 remover_ = new BrowsingDataRemover(profile, 161 remover_ = new BrowsingDataRemover(
162 profile,
137 static_cast<BrowsingDataRemover::TimePeriod>(period_selected), 163 static_cast<BrowsingDataRemover::TimePeriod>(period_selected),
138 base::Time()); 164 base::Time());
139 remover_->AddObserver(this); 165 remover_->AddObserver(this);
140 remover_->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB); 166 remover_->Remove(BrowsingDataRemover::REMOVE_SITE_DATA,
167 BrowsingDataHelper::PROTECTED_WEB);
141 } 168 }
142 169
143 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() { 170 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() {
144 // No need to remove ourselves as an observer as BrowsingDataRemover deletes 171 // No need to remove ourselves as an observer as BrowsingDataRemover deletes
145 // itself after we return. 172 // itself after we return.
146 remover_ = NULL; 173 remover_ = NULL;
174
175 if (remove_hosted_app_data_pending_)
176 ClearHostedAppData();
177 else
178 OnAllDataRemoved();
179 }
180
181 void ClearBrowserDataHandler::OnAllDataRemoved() {
147 web_ui()->CallJavascriptFunction("ClearBrowserDataOverlay.doneClearing"); 182 web_ui()->CallJavascriptFunction("ClearBrowserDataOverlay.doneClearing");
148 } 183 }
149 184
150 } // namespace options2 185 } // namespace options2
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options2/clear_browser_data_handler2.h ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698