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

Side by Side Diff: chrome/browser/ui/webui/options/reset_profile_settings_handler.cc

Issue 62193002: Integrate UI and reset logic into AutomaticProfileResetter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reduced boilerplate in unit tests. Created 7 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/options/reset_profile_settings_handler.h" 5 #include "chrome/browser/ui/webui/options/reset_profile_settings_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/google/google_util.h" 13 #include "chrome/browser/google/google_util.h"
14 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h"
15 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h"
14 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" 16 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h"
15 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" 17 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h"
16 #include "chrome/browser/profile_resetter/profile_resetter.h" 18 #include "chrome/browser/profile_resetter/profile_resetter.h"
17 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" 19 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h"
18 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
20 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
21 #include "content/public/browser/user_metrics.h" 23 #include "content/public/browser/user_metrics.h"
22 #include "content/public/browser/web_ui.h" 24 #include "content/public/browser/web_ui.h"
23 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
25 27
26 namespace options { 28 namespace options {
27 29
28 ResetProfileSettingsHandler::ResetProfileSettingsHandler() { 30 ResetProfileSettingsHandler::ResetProfileSettingsHandler() {
29 google_util::GetBrand(&brandcode_); 31 google_util::GetBrand(&brandcode_);
30 } 32 }
31 33
32 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() { 34 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() {
35 // Will be ignored if it was already called in OnResetProfileSettingsDone.
36 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog(
37 false /*performed_reset*/);
33 } 38 }
34 39
35 void ResetProfileSettingsHandler::InitializeHandler() { 40 void ResetProfileSettingsHandler::InitializeHandler() {
36 Profile* profile = Profile::FromWebUI(web_ui()); 41 Profile* profile = Profile::FromWebUI(web_ui());
37 resetter_.reset(new ProfileResetter(profile)); 42 resetter_.reset(new ProfileResetter(profile));
43 automatic_profile_resetter_ =
44 AutomaticProfileResetterFactory::GetForBrowserContext(profile);
45 DCHECK(automatic_profile_resetter_);
38 } 46 }
39 47
40 void ResetProfileSettingsHandler::InitializePage() { 48 void ResetProfileSettingsHandler::InitializePage() {
41 web_ui()->CallJavascriptFunction( 49 web_ui()->CallJavascriptFunction(
42 "ResetProfileSettingsOverlay.setResettingState", 50 "ResetProfileSettingsOverlay.setResettingState",
43 base::FundamentalValue(resetter_->IsActive())); 51 base::FundamentalValue(resetter_->IsActive()));
44 } 52 }
45 53
46 void ResetProfileSettingsHandler::GetLocalizedValues( 54 void ResetProfileSettingsHandler::GetLocalizedValues(
47 DictionaryValue* localized_strings) { 55 DictionaryValue* localized_strings) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 void ResetProfileSettingsHandler::OnResetProfileSettingsDone() { 101 void ResetProfileSettingsHandler::OnResetProfileSettingsDone() {
94 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting"); 102 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting");
95 if (setting_snapshot_) { 103 if (setting_snapshot_) {
96 Profile* profile = Profile::FromWebUI(web_ui()); 104 Profile* profile = Profile::FromWebUI(web_ui());
97 ResettableSettingsSnapshot current_snapshot(profile); 105 ResettableSettingsSnapshot current_snapshot(profile);
98 int difference = setting_snapshot_->FindDifferentFields(current_snapshot); 106 int difference = setting_snapshot_->FindDifferentFields(current_snapshot);
99 if (difference) { 107 if (difference) {
100 setting_snapshot_->Subtract(current_snapshot); 108 setting_snapshot_->Subtract(current_snapshot);
101 std::string report = SerializeSettingsReport(*setting_snapshot_, 109 std::string report = SerializeSettingsReport(*setting_snapshot_,
102 difference); 110 difference);
103 SendSettingsFeedback(report, profile, PROFILE_RESET_WEBUI); 111 bool is_reset_prompt_active =
112 automatic_profile_resetter_->IsResetPromptActive();
113 SendSettingsFeedback(report, profile, is_reset_prompt_active ?
114 PROFILE_RESET_PROMPT : PROFILE_RESET_WEBUI);
104 } 115 }
105 setting_snapshot_.reset(); 116 setting_snapshot_.reset();
106 } 117 }
118 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog(
119 true /*performed_reset*/);
107 } 120 }
108 121
109 void ResetProfileSettingsHandler::OnShowResetProfileDialog(const ListValue*) { 122 void ResetProfileSettingsHandler::OnShowResetProfileDialog(const ListValue*) {
110 DictionaryValue flashInfo; 123 DictionaryValue flashInfo;
111 flashInfo.Set("feedbackInfo", GetReadableFeedback( 124 flashInfo.Set("feedbackInfo", GetReadableFeedback(
112 Profile::FromWebUI(web_ui()))); 125 Profile::FromWebUI(web_ui())));
113 web_ui()->CallJavascriptFunction( 126 web_ui()->CallJavascriptFunction(
114 "ResetProfileSettingsOverlay.setFeedbackInfo", 127 "ResetProfileSettingsOverlay.setFeedbackInfo",
115 flashInfo); 128 flashInfo);
116 129
130 automatic_profile_resetter_->NotifyDidOpenWebUIResetDialog();
131
117 if (brandcode_.empty()) 132 if (brandcode_.empty())
118 return; 133 return;
119 config_fetcher_.reset(new BrandcodeConfigFetcher( 134 config_fetcher_.reset(new BrandcodeConfigFetcher(
120 base::Bind(&ResetProfileSettingsHandler::OnSettingsFetched, 135 base::Bind(&ResetProfileSettingsHandler::OnSettingsFetched,
121 Unretained(this)), 136 Unretained(this)),
122 GURL("https://tools.google.com/service/update2"), 137 GURL("https://tools.google.com/service/update2"),
123 brandcode_)); 138 brandcode_));
124 } 139 }
125 140
126 void ResetProfileSettingsHandler::OnSettingsFetched() { 141 void ResetProfileSettingsHandler::OnSettingsFetched() {
(...skipping 25 matching lines...) Expand all
152 resetter_->Reset( 167 resetter_->Reset(
153 ProfileResetter::ALL, 168 ProfileResetter::ALL,
154 default_settings.Pass(), 169 default_settings.Pass(),
155 base::Bind(&ResetProfileSettingsHandler::OnResetProfileSettingsDone, 170 base::Bind(&ResetProfileSettingsHandler::OnResetProfileSettingsDone,
156 AsWeakPtr())); 171 AsWeakPtr()));
157 content::RecordAction(content::UserMetricsAction("ResetProfile")); 172 content::RecordAction(content::UserMetricsAction("ResetProfile"));
158 UMA_HISTOGRAM_BOOLEAN("ProfileReset.SendFeedback", send_settings); 173 UMA_HISTOGRAM_BOOLEAN("ProfileReset.SendFeedback", send_settings);
159 } 174 }
160 175
161 } // namespace options 176 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698