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

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: Profile helper function, 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"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 if (last_pref != iter->first) { 105 if (last_pref != iter->first) {
106 StopObservingPref(iter->first); 106 StopObservingPref(iter->first);
107 last_pref = iter->first; 107 last_pref = iter->first;
108 } 108 }
109 } 109 }
110 } 110 }
111 111
112 WebUIMessageHandler* CoreOptionsHandler::Attach(WebUI* web_ui) { 112 WebUIMessageHandler* CoreOptionsHandler::Attach(WebUI* web_ui) {
113 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); 113 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui);
114 DCHECK(web_ui_); 114 DCHECK(web_ui_);
115 registrar_.Init(web_ui_->GetProfile()->GetPrefs()); 115 registrar_.Init(Profile::FromWebUI(web_ui_)->GetPrefs());
116 return result; 116 return result;
117 } 117 }
118 118
119 void CoreOptionsHandler::Observe(int type, 119 void CoreOptionsHandler::Observe(int type,
120 const NotificationSource& source, 120 const NotificationSource& source,
121 const NotificationDetails& details) { 121 const NotificationDetails& details) {
122 if (type == chrome::NOTIFICATION_PREF_CHANGED) 122 if (type == chrome::NOTIFICATION_PREF_CHANGED)
123 NotifyPrefChanged(Details<std::string>(details).ptr()); 123 NotifyPrefChanged(Details<std::string>(details).ptr());
124 } 124 }
125 125
(...skipping 19 matching lines...) Expand all
145 web_ui_->RegisterMessageCallback("coreOptionsUserMetricsAction", 145 web_ui_->RegisterMessageCallback("coreOptionsUserMetricsAction",
146 NewCallback(this, &CoreOptionsHandler::HandleUserMetricsAction)); 146 NewCallback(this, &CoreOptionsHandler::HandleUserMetricsAction));
147 } 147 }
148 148
149 void CoreOptionsHandler::HandleInitialize(const ListValue* args) { 149 void CoreOptionsHandler::HandleInitialize(const ListValue* args) {
150 DCHECK(handlers_host_); 150 DCHECK(handlers_host_);
151 handlers_host_->InitializeHandlers(); 151 handlers_host_->InitializeHandlers();
152 } 152 }
153 153
154 Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) { 154 Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) {
155 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); 155 PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs();
156 156
157 const PrefService::Preference* pref = 157 const PrefService::Preference* pref =
158 pref_service->FindPreference(pref_name.c_str()); 158 pref_service->FindPreference(pref_name.c_str());
159 if (!pref) 159 if (!pref)
160 return Value::CreateNullValue(); 160 return Value::CreateNullValue();
161 161
162 return CreateValueForPref(pref); 162 return CreateValueForPref(pref);
163 } 163 }
164 164
165 void CoreOptionsHandler::ObservePref(const std::string& pref_name) { 165 void CoreOptionsHandler::ObservePref(const std::string& pref_name) {
166 registrar_.Add(pref_name.c_str(), this); 166 registrar_.Add(pref_name.c_str(), this);
167 } 167 }
168 168
169 void CoreOptionsHandler::SetPref(const std::string& pref_name, 169 void CoreOptionsHandler::SetPref(const std::string& pref_name,
170 const Value* value, 170 const Value* value,
171 const std::string& metric) { 171 const std::string& metric) {
172 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); 172 PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs();
173 173
174 switch (value->GetType()) { 174 switch (value->GetType()) {
175 case Value::TYPE_BOOLEAN: 175 case Value::TYPE_BOOLEAN:
176 case Value::TYPE_INTEGER: 176 case Value::TYPE_INTEGER:
177 case Value::TYPE_DOUBLE: 177 case Value::TYPE_DOUBLE:
178 case Value::TYPE_STRING: 178 case Value::TYPE_STRING:
179 pref_service->Set(pref_name.c_str(), *value); 179 pref_service->Set(pref_name.c_str(), *value);
180 break; 180 break;
181 181
182 default: 182 default:
183 NOTREACHED(); 183 NOTREACHED();
184 return; 184 return;
185 } 185 }
186 186
187 pref_service->ScheduleSavePersistentPrefs(); 187 pref_service->ScheduleSavePersistentPrefs();
188 ProcessUserMetric(value, metric); 188 ProcessUserMetric(value, metric);
189 } 189 }
190 190
191 void CoreOptionsHandler::ClearPref(const std::string& pref_name, 191 void CoreOptionsHandler::ClearPref(const std::string& pref_name,
192 const std::string& metric) { 192 const std::string& metric) {
193 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); 193 PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs();
194 pref_service->ClearPref(pref_name.c_str()); 194 pref_service->ClearPref(pref_name.c_str());
195 pref_service->ScheduleSavePersistentPrefs(); 195 pref_service->ScheduleSavePersistentPrefs();
196 196
197 if (!metric.empty()) 197 if (!metric.empty())
198 UserMetrics::RecordComputedAction(metric); 198 UserMetrics::RecordComputedAction(metric);
199 } 199 }
200 200
201 void CoreOptionsHandler::ProcessUserMetric(const Value* value, 201 void CoreOptionsHandler::ProcessUserMetric(const Value* value,
202 const std::string& metric) { 202 const std::string& metric) {
203 if (metric.empty()) 203 if (metric.empty())
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 "OptionsPage.setClearPluginLSODataEnabled", *enabled); 370 "OptionsPage.setClearPluginLSODataEnabled", *enabled);
371 } 371 }
372 372
373 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) { 373 void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) {
374 if (*pref_name == prefs::kClearPluginLSODataEnabled) { 374 if (*pref_name == prefs::kClearPluginLSODataEnabled) {
375 // This preference is stored in Local State, not in the user preferences. 375 // This preference is stored in Local State, not in the user preferences.
376 UpdateClearPluginLSOData(); 376 UpdateClearPluginLSOData();
377 return; 377 return;
378 } 378 }
379 379
380 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); 380 PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs();
381 const PrefService::Preference* pref = 381 const PrefService::Preference* pref =
382 pref_service->FindPreference(pref_name->c_str()); 382 pref_service->FindPreference(pref_name->c_str());
383 if (!pref) 383 if (!pref)
384 return; 384 return;
385 385
386 std::pair<PreferenceCallbackMap::const_iterator, 386 std::pair<PreferenceCallbackMap::const_iterator,
387 PreferenceCallbackMap::const_iterator> range; 387 PreferenceCallbackMap::const_iterator> range;
388 range = pref_callback_map_.equal_range(*pref_name); 388 range = pref_callback_map_.equal_range(*pref_name);
389 for (PreferenceCallbackMap::const_iterator iter = range.first; 389 for (PreferenceCallbackMap::const_iterator iter = range.first;
390 iter != range.second; ++iter) { 390 iter != range.second; ++iter) {
391 const std::wstring& callback_function = iter->second; 391 const std::wstring& callback_function = iter->second;
392 ListValue result_value; 392 ListValue result_value;
393 result_value.Append(Value::CreateStringValue(pref_name->c_str())); 393 result_value.Append(Value::CreateStringValue(pref_name->c_str()));
394 394
395 result_value.Append(CreateValueForPref(pref)); 395 result_value.Append(CreateValueForPref(pref));
396 396
397 web_ui_->CallJavascriptFunction(WideToASCII(callback_function), 397 web_ui_->CallJavascriptFunction(WideToASCII(callback_function),
398 result_value); 398 result_value);
399 } 399 }
400 } 400 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/cookies_view_handler.cc ('k') | chrome/browser/ui/webui/options/font_settings_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698