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

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

Issue 7554008: Removal of Profile from content part 6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/core_options_handler.h" 5 #include "chrome/browser/ui/webui/options/core_options_handler.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/google/google_util.h" 14 #include "chrome/browser/google/google_util.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/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
20 #include "content/browser/tab_contents/tab_contents.h"
20 #include "content/browser/user_metrics.h" 21 #include "content/browser/user_metrics.h"
21 #include "content/common/content_notification_types.h" 22 #include "content/common/content_notification_types.h"
22 #include "content/common/notification_details.h" 23 #include "content/common/notification_details.h"
23 #include "googleurl/src/gurl.h" 24 #include "googleurl/src/gurl.h"
24 #include "grit/chromium_strings.h" 25 #include "grit/chromium_strings.h"
25 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
26 #include "grit/locale_settings.h" 27 #include "grit/locale_settings.h"
27 #include "grit/theme_resources.h" 28 #include "grit/theme_resources.h"
28 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
29 30
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 if (last_pref != iter->first) { 106 if (last_pref != iter->first) {
106 StopObservingPref(iter->first); 107 StopObservingPref(iter->first);
107 last_pref = iter->first; 108 last_pref = iter->first;
108 } 109 }
109 } 110 }
110 } 111 }
111 112
112 WebUIMessageHandler* CoreOptionsHandler::Attach(WebUI* web_ui) { 113 WebUIMessageHandler* CoreOptionsHandler::Attach(WebUI* web_ui) {
113 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); 114 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui);
114 DCHECK(web_ui_); 115 DCHECK(web_ui_);
115 registrar_.Init(web_ui_->GetProfile()->GetPrefs()); 116 Profile* profile =
117 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
118 registrar_.Init(profile->GetPrefs());
116 return result; 119 return result;
117 } 120 }
118 121
119 void CoreOptionsHandler::Observe(int type, 122 void CoreOptionsHandler::Observe(int type,
120 const NotificationSource& source, 123 const NotificationSource& source,
121 const NotificationDetails& details) { 124 const NotificationDetails& details) {
122 if (type == chrome::NOTIFICATION_PREF_CHANGED) 125 if (type == chrome::NOTIFICATION_PREF_CHANGED)
123 NotifyPrefChanged(Details<std::string>(details).ptr()); 126 NotifyPrefChanged(Details<std::string>(details).ptr());
124 } 127 }
125 128
(...skipping 19 matching lines...) Expand all
145 web_ui_->RegisterMessageCallback("coreOptionsUserMetricsAction", 148 web_ui_->RegisterMessageCallback("coreOptionsUserMetricsAction",
146 NewCallback(this, &CoreOptionsHandler::HandleUserMetricsAction)); 149 NewCallback(this, &CoreOptionsHandler::HandleUserMetricsAction));
147 } 150 }
148 151
149 void CoreOptionsHandler::HandleInitialize(const ListValue* args) { 152 void CoreOptionsHandler::HandleInitialize(const ListValue* args) {
150 DCHECK(handlers_host_); 153 DCHECK(handlers_host_);
151 handlers_host_->InitializeHandlers(); 154 handlers_host_->InitializeHandlers();
152 } 155 }
153 156
154 Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) { 157 Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) {
155 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); 158 Profile* profile =
159 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
160 PrefService* pref_service = profile->GetPrefs();
156 161
157 const PrefService::Preference* pref = 162 const PrefService::Preference* pref =
158 pref_service->FindPreference(pref_name.c_str()); 163 pref_service->FindPreference(pref_name.c_str());
159 if (!pref) 164 if (!pref)
160 return Value::CreateNullValue(); 165 return Value::CreateNullValue();
161 166
162 return CreateValueForPref(pref); 167 return CreateValueForPref(pref);
163 } 168 }
164 169
165 void CoreOptionsHandler::ObservePref(const std::string& pref_name) { 170 void CoreOptionsHandler::ObservePref(const std::string& pref_name) {
166 registrar_.Add(pref_name.c_str(), this); 171 registrar_.Add(pref_name.c_str(), this);
167 } 172 }
168 173
169 void CoreOptionsHandler::SetPref(const std::string& pref_name, 174 void CoreOptionsHandler::SetPref(const std::string& pref_name,
170 const Value* value, 175 const Value* value,
171 const std::string& metric) { 176 const std::string& metric) {
172 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); 177 Profile* profile =
178 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
179 PrefService* pref_service = profile->GetPrefs();
173 180
174 switch (value->GetType()) { 181 switch (value->GetType()) {
175 case Value::TYPE_BOOLEAN: 182 case Value::TYPE_BOOLEAN:
176 case Value::TYPE_INTEGER: 183 case Value::TYPE_INTEGER:
177 case Value::TYPE_DOUBLE: 184 case Value::TYPE_DOUBLE:
178 case Value::TYPE_STRING: 185 case Value::TYPE_STRING:
179 pref_service->Set(pref_name.c_str(), *value); 186 pref_service->Set(pref_name.c_str(), *value);
180 break; 187 break;
181 188
182 default: 189 default:
183 NOTREACHED(); 190 NOTREACHED();
184 return; 191 return;
185 } 192 }
186 193
187 pref_service->ScheduleSavePersistentPrefs(); 194 pref_service->ScheduleSavePersistentPrefs();
188 ProcessUserMetric(value, metric); 195 ProcessUserMetric(value, metric);
189 } 196 }
190 197
191 void CoreOptionsHandler::ClearPref(const std::string& pref_name, 198 void CoreOptionsHandler::ClearPref(const std::string& pref_name,
192 const std::string& metric) { 199 const std::string& metric) {
193 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); 200 Profile* profile =
201 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
202 PrefService* pref_service = profile->GetPrefs();
194 pref_service->ClearPref(pref_name.c_str()); 203 pref_service->ClearPref(pref_name.c_str());
195 pref_service->ScheduleSavePersistentPrefs(); 204 pref_service->ScheduleSavePersistentPrefs();
196 205
197 if (!metric.empty()) 206 if (!metric.empty())
198 UserMetrics::RecordComputedAction(metric); 207 UserMetrics::RecordComputedAction(metric);
199 } 208 }
200 209
201 void CoreOptionsHandler::ProcessUserMetric(const Value* value, 210 void CoreOptionsHandler::ProcessUserMetric(const Value* value,
202 const std::string& metric) { 211 const std::string& metric) {
203 if (metric.empty()) 212 if (metric.empty())
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 "OptionsPage.setClearPluginLSODataEnabled", *enabled); 379 "OptionsPage.setClearPluginLSODataEnabled", *enabled);
371 } 380 }
372 381
373 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) { 382 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) {
374 if (*pref_name == prefs::kClearPluginLSODataEnabled) { 383 if (*pref_name == prefs::kClearPluginLSODataEnabled) {
375 // This preference is stored in Local State, not in the user preferences. 384 // This preference is stored in Local State, not in the user preferences.
376 UpdateClearPluginLSOData(); 385 UpdateClearPluginLSOData();
377 return; 386 return;
378 } 387 }
379 388
380 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); 389 Profile* profile =
390 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context());
391 PrefService* pref_service = profile->GetPrefs();
381 const PrefService::Preference* pref = 392 const PrefService::Preference* pref =
382 pref_service->FindPreference(pref_name->c_str()); 393 pref_service->FindPreference(pref_name->c_str());
383 if (!pref) 394 if (!pref)
384 return; 395 return;
385 396
386 std::pair<PreferenceCallbackMap::const_iterator, 397 std::pair<PreferenceCallbackMap::const_iterator,
387 PreferenceCallbackMap::const_iterator> range; 398 PreferenceCallbackMap::const_iterator> range;
388 range = pref_callback_map_.equal_range(*pref_name); 399 range = pref_callback_map_.equal_range(*pref_name);
389 for (PreferenceCallbackMap::const_iterator iter = range.first; 400 for (PreferenceCallbackMap::const_iterator iter = range.first;
390 iter != range.second; ++iter) { 401 iter != range.second; ++iter) {
391 const std::wstring& callback_function = iter->second; 402 const std::wstring& callback_function = iter->second;
392 ListValue result_value; 403 ListValue result_value;
393 result_value.Append(Value::CreateStringValue(pref_name->c_str())); 404 result_value.Append(Value::CreateStringValue(pref_name->c_str()));
394 405
395 result_value.Append(CreateValueForPref(pref)); 406 result_value.Append(CreateValueForPref(pref));
396 407
397 web_ui_->CallJavascriptFunction(WideToASCII(callback_function), 408 web_ui_->CallJavascriptFunction(WideToASCII(callback_function),
398 result_value); 409 result_value);
399 } 410 }
400 } 411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698