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

Side by Side Diff: chrome/browser/profiles/profile_impl.cc

Issue 9289007: Profiles: Move the Spelling system onto a ProfileKeyedServiceFactory. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove stray mark Created 8 years, 11 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
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/profiles/profile_impl.h" 5 #include "chrome/browser/profiles/profile_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 #include "chrome/browser/profiles/gaia_info_update_service.h" 66 #include "chrome/browser/profiles/gaia_info_update_service.h"
67 #include "chrome/browser/profiles/profile_dependency_manager.h" 67 #include "chrome/browser/profiles/profile_dependency_manager.h"
68 #include "chrome/browser/profiles/profile_info_cache.h" 68 #include "chrome/browser/profiles/profile_info_cache.h"
69 #include "chrome/browser/profiles/profile_manager.h" 69 #include "chrome/browser/profiles/profile_manager.h"
70 #include "chrome/browser/search_engines/template_url_fetcher.h" 70 #include "chrome/browser/search_engines/template_url_fetcher.h"
71 #include "chrome/browser/search_engines/template_url_service.h" 71 #include "chrome/browser/search_engines/template_url_service.h"
72 #include "chrome/browser/sessions/session_service_factory.h" 72 #include "chrome/browser/sessions/session_service_factory.h"
73 #include "chrome/browser/signin/token_service.h" 73 #include "chrome/browser/signin/token_service.h"
74 #include "chrome/browser/speech/chrome_speech_input_manager.h" 74 #include "chrome/browser/speech/chrome_speech_input_manager.h"
75 #include "chrome/browser/speech/chrome_speech_input_preferences.h" 75 #include "chrome/browser/speech/chrome_speech_input_preferences.h"
76 #include "chrome/browser/spellchecker/spellcheck_profile.h"
77 #include "chrome/browser/sync/profile_sync_service_factory.h" 76 #include "chrome/browser/sync/profile_sync_service_factory.h"
78 #include "chrome/browser/tabs/pinned_tab_service_factory.h" 77 #include "chrome/browser/tabs/pinned_tab_service_factory.h"
79 #include "chrome/browser/transport_security_persister.h" 78 #include "chrome/browser/transport_security_persister.h"
80 #include "chrome/browser/ui/browser_init.h" 79 #include "chrome/browser/ui/browser_init.h"
81 #include "chrome/browser/ui/browser_list.h" 80 #include "chrome/browser/ui/browser_list.h"
82 #include "chrome/browser/ui/find_bar/find_bar_state.h" 81 #include "chrome/browser/ui/find_bar/find_bar_state.h"
83 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 82 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
84 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 83 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
85 #include "chrome/browser/user_style_sheet_watcher.h" 84 #include "chrome/browser/user_style_sheet_watcher.h"
86 #include "chrome/browser/visitedlink/visitedlink_event_listener.h" 85 #include "chrome/browser/visitedlink/visitedlink_event_listener.h"
87 #include "chrome/browser/visitedlink/visitedlink_master.h" 86 #include "chrome/browser/visitedlink/visitedlink_master.h"
88 #include "chrome/browser/web_resource/promo_resource_service.h" 87 #include "chrome/browser/web_resource/promo_resource_service.h"
89 #include "chrome/browser/webdata/web_data_service.h" 88 #include "chrome/browser/webdata/web_data_service.h"
90 #include "chrome/common/chrome_constants.h" 89 #include "chrome/common/chrome_constants.h"
91 #include "chrome/common/chrome_notification_types.h" 90 #include "chrome/common/chrome_notification_types.h"
92 #include "chrome/common/chrome_paths_internal.h" 91 #include "chrome/common/chrome_paths_internal.h"
93 #include "chrome/common/chrome_switches.h" 92 #include "chrome/common/chrome_switches.h"
94 #include "chrome/common/extensions/extension_permission_set.h" 93 #include "chrome/common/extensions/extension_permission_set.h"
95 #include "chrome/common/json_pref_store.h" 94 #include "chrome/common/json_pref_store.h"
96 #include "chrome/common/pref_names.h" 95 #include "chrome/common/pref_names.h"
97 #include "chrome/common/render_messages.h"
98 #include "chrome/common/spellcheck_messages.h"
99 #include "chrome/common/url_constants.h" 96 #include "chrome/common/url_constants.h"
100 #include "content/browser/appcache/chrome_appcache_service.h" 97 #include "content/browser/appcache/chrome_appcache_service.h"
101 #include "content/browser/chrome_blob_storage_context.h" 98 #include "content/browser/chrome_blob_storage_context.h"
102 #include "content/browser/file_system/browser_file_system_helper.h" 99 #include "content/browser/file_system/browser_file_system_helper.h"
103 #include "content/browser/host_zoom_map.h" 100 #include "content/browser/host_zoom_map.h"
104 #include "content/browser/in_process_webkit/webkit_context.h" 101 #include "content/browser/in_process_webkit/webkit_context.h"
105 #include "content/browser/speech/speech_input_manager.h" 102 #include "content/browser/speech/speech_input_manager.h"
106 #include "content/browser/ssl/ssl_host_state.h" 103 #include "content/browser/ssl/ssl_host_state.h"
107 #include "content/public/browser/browser_thread.h" 104 #include "content/public/browser/browser_thread.h"
108 #include "content/public/browser/notification_service.h" 105 #include "content/public/browser/notification_service.h"
109 #include "content/public/browser/render_process_host.h"
110 #include "content/public/browser/user_metrics.h" 106 #include "content/public/browser/user_metrics.h"
111 #include "grit/locale_settings.h" 107 #include "grit/locale_settings.h"
112 #include "net/base/transport_security_state.h" 108 #include "net/base/transport_security_state.h"
113 #include "net/http/http_server_properties.h" 109 #include "net/http/http_server_properties.h"
114 #include "webkit/database/database_tracker.h" 110 #include "webkit/database/database_tracker.h"
115 #include "webkit/quota/quota_manager.h" 111 #include "webkit/quota/quota_manager.h"
116 112
117 #if defined(OS_WIN) 113 #if defined(OS_WIN)
118 #include "chrome/browser/instant/promo_counter.h" 114 #include "chrome/browser/instant/promo_counter.h"
119 #include "chrome/browser/password_manager/password_store_win.h" 115 #include "chrome/browser/password_manager/password_store_win.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 GetPrefFilePath(), 292 GetPrefFilePath(),
297 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), 293 new ExtensionPrefStore(GetExtensionPrefValueMap(), false),
298 false)); 294 false));
299 OnPrefsLoaded(true); 295 OnPrefsLoaded(true);
300 } 296 }
301 } 297 }
302 298
303 void ProfileImpl::DoFinalInit() { 299 void ProfileImpl::DoFinalInit() {
304 PrefService* prefs = GetPrefs(); 300 PrefService* prefs = GetPrefs();
305 pref_change_registrar_.Init(prefs); 301 pref_change_registrar_.Init(prefs);
306 pref_change_registrar_.Add(prefs::kSpellCheckDictionary, this);
307 pref_change_registrar_.Add(prefs::kEnableSpellCheck, this);
308 pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this);
309 pref_change_registrar_.Add(prefs::kSpeechInputFilterProfanities, this); 302 pref_change_registrar_.Add(prefs::kSpeechInputFilterProfanities, this);
310 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); 303 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this);
311 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this); 304 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this);
312 pref_change_registrar_.Add(prefs::kDefaultZoomLevel, this); 305 pref_change_registrar_.Add(prefs::kDefaultZoomLevel, this);
313 pref_change_registrar_.Add(prefs::kProfileAvatarIndex, this); 306 pref_change_registrar_.Add(prefs::kProfileAvatarIndex, this);
314 pref_change_registrar_.Add(prefs::kProfileName, this); 307 pref_change_registrar_.Add(prefs::kProfileName, this);
315 308
316 // It would be nice to use PathService for fetching this directory, but 309 // It would be nice to use PathService for fetching this directory, but
317 // the cache directory depends on the profile directory, which isn't available 310 // the cache directory depends on the profile directory, which isn't available
318 // to PathService. 311 // to PathService.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 if (clear_local_state_on_exit_) { 361 if (clear_local_state_on_exit_) {
369 content::RecordAction( 362 content::RecordAction(
370 UserMetricsAction("ClearSiteDataOnExitEnabled")); 363 UserMetricsAction("ClearSiteDataOnExitEnabled"));
371 } else { 364 } else {
372 content::RecordAction( 365 content::RecordAction(
373 UserMetricsAction("ClearSiteDataOnExitDisabled")); 366 UserMetricsAction("ClearSiteDataOnExitDisabled"));
374 } 367 }
375 368
376 InstantController::RecordMetrics(this); 369 InstantController::RecordMetrics(this);
377 370
378 // Instantiates Metrics object for spellchecking for use.
379 if (g_browser_process->metrics_service() &&
380 g_browser_process->metrics_service()->recording_active())
381 GetSpellCheckProfile()->StartRecordingMetrics(
382 GetPrefs()->GetBoolean(prefs::kEnableSpellCheck));
383
384 FilePath cookie_path = GetPath(); 371 FilePath cookie_path = GetPath();
385 cookie_path = cookie_path.Append(chrome::kCookieFilename); 372 cookie_path = cookie_path.Append(chrome::kCookieFilename);
386 FilePath origin_bound_cert_path = GetPath(); 373 FilePath origin_bound_cert_path = GetPath();
387 origin_bound_cert_path = 374 origin_bound_cert_path =
388 origin_bound_cert_path.Append(chrome::kOBCertFilename); 375 origin_bound_cert_path.Append(chrome::kOBCertFilename);
389 FilePath cache_path = base_cache_path_; 376 FilePath cache_path = base_cache_path_;
390 int cache_max_size; 377 int cache_max_size;
391 GetCacheParameters(false, &cache_path, &cache_max_size); 378 GetCacheParameters(false, &cache_path, &cache_max_size);
392 cache_path = GetCachePath(cache_path); 379 cache_path = GetCachePath(cache_path);
393 380
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 top_sites_ = new history::TopSites(this); 1192 top_sites_ = new history::TopSites(this);
1206 top_sites_->Init(GetPath().Append(chrome::kTopSitesFilename)); 1193 top_sites_->Init(GetPath().Append(chrome::kTopSitesFilename));
1207 } 1194 }
1208 return top_sites_; 1195 return top_sites_;
1209 } 1196 }
1210 1197
1211 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { 1198 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() {
1212 return top_sites_; 1199 return top_sites_;
1213 } 1200 }
1214 1201
1215 SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1216 return GetSpellCheckProfile()->GetHost();
1217 }
1218
1219
1220 void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1221 PrefService* pref = GetPrefs();
1222 SpellCheckProfile::ReinitializeResult result =
1223 GetSpellCheckProfile()->ReinitializeHost(
1224 force,
1225 pref->GetBoolean(prefs::kEnableSpellCheck),
1226 pref->GetString(prefs::kSpellCheckDictionary),
1227 GetRequestContext());
1228 if (result == SpellCheckProfile::REINITIALIZE_REMOVED_HOST) {
1229 // The spellchecker has been disabled.
1230 for (content::RenderProcessHost::iterator i(
1231 content::RenderProcessHost::AllHostsIterator());
1232 !i.IsAtEnd(); i.Advance()) {
1233 content::RenderProcessHost* process = i.GetCurrentValue();
1234 process->Send(new SpellCheckMsg_Init(IPC::InvalidPlatformFileForTransit(),
1235 std::vector<std::string>(),
1236 std::string(),
1237 false));
1238 }
1239 }
1240 }
1241
1242 ExtensionPrefValueMap* ProfileImpl::GetExtensionPrefValueMap() { 1202 ExtensionPrefValueMap* ProfileImpl::GetExtensionPrefValueMap() {
1243 if (!extension_pref_value_map_.get()) 1203 if (!extension_pref_value_map_.get())
1244 extension_pref_value_map_.reset(new ExtensionPrefValueMap); 1204 extension_pref_value_map_.reset(new ExtensionPrefValueMap);
1245 return extension_pref_value_map_.get(); 1205 return extension_pref_value_map_.get();
1246 } 1206 }
1247 1207
1248 void ProfileImpl::CreateQuotaManagerAndClients() { 1208 void ProfileImpl::CreateQuotaManagerAndClients() {
1249 if (quota_manager_.get()) { 1209 if (quota_manager_.get()) {
1250 DCHECK(file_system_context_.get()); 1210 DCHECK(file_system_context_.get());
1251 DCHECK(db_tracker_.get()); 1211 DCHECK(db_tracker_.get());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 registrar_.Remove(this, 1278 registrar_.Remove(this,
1319 chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, 1279 chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED,
1320 content::Source<PrefService>(prefs)); 1280 content::Source<PrefService>(prefs));
1321 OnPrefsLoaded(*succeeded); 1281 OnPrefsLoaded(*succeeded);
1322 break; 1282 break;
1323 } 1283 }
1324 case chrome::NOTIFICATION_PREF_CHANGED: { 1284 case chrome::NOTIFICATION_PREF_CHANGED: {
1325 std::string* pref_name_in = content::Details<std::string>(details).ptr(); 1285 std::string* pref_name_in = content::Details<std::string>(details).ptr();
1326 PrefService* prefs = content::Source<PrefService>(source).ptr(); 1286 PrefService* prefs = content::Source<PrefService>(source).ptr();
1327 DCHECK(pref_name_in && prefs); 1287 DCHECK(pref_name_in && prefs);
1328 if (*pref_name_in == prefs::kSpellCheckDictionary || 1288 if (*pref_name_in == prefs::kSpeechInputFilterProfanities) {
1329 *pref_name_in == prefs::kEnableSpellCheck) {
1330 ReinitializeSpellCheckHost(true);
1331 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1332 bool enabled = prefs->GetBoolean(prefs::kEnableAutoSpellCorrect);
1333 for (content::RenderProcessHost::iterator i(
1334 content::RenderProcessHost::AllHostsIterator());
1335 !i.IsAtEnd(); i.Advance()) {
1336 content::RenderProcessHost* process = i.GetCurrentValue();
1337 process->Send(new SpellCheckMsg_EnableAutoSpellCorrect(enabled));
1338 }
1339 } else if (*pref_name_in == prefs::kSpeechInputFilterProfanities) {
1340 GetSpeechInputPreferences()->set_filter_profanities(prefs->GetBoolean( 1289 GetSpeechInputPreferences()->set_filter_profanities(prefs->GetBoolean(
1341 prefs::kSpeechInputFilterProfanities)); 1290 prefs::kSpeechInputFilterProfanities));
1342 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { 1291 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) {
1343 clear_local_state_on_exit_ = 1292 clear_local_state_on_exit_ =
1344 prefs->GetBoolean(prefs::kClearSiteDataOnExit); 1293 prefs->GetBoolean(prefs::kClearSiteDataOnExit);
1345 if (webkit_context_) { 1294 if (webkit_context_) {
1346 webkit_context_->set_clear_local_state_on_exit( 1295 webkit_context_->set_clear_local_state_on_exit(
1347 clear_local_state_on_exit_); 1296 clear_local_state_on_exit_);
1348 } 1297 }
1349 if (db_tracker_) { 1298 if (db_tracker_) {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 if (db_tracker_.get()) 1545 if (db_tracker_.get())
1597 db_tracker_->SaveSessionState(); 1546 db_tracker_->SaveSessionState();
1598 1547
1599 BrowserThread::PostTask( 1548 BrowserThread::PostTask(
1600 BrowserThread::IO, FROM_HERE, 1549 BrowserThread::IO, FROM_HERE,
1601 base::Bind(&SaveSessionStateOnIOThread, 1550 base::Bind(&SaveSessionStateOnIOThread,
1602 make_scoped_refptr(GetRequestContext()), 1551 make_scoped_refptr(GetRequestContext()),
1603 make_scoped_refptr(appcache_service_.get()))); 1552 make_scoped_refptr(appcache_service_.get())));
1604 } 1553 }
1605 1554
1606 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() {
1607 if (!spellcheck_profile_.get())
1608 spellcheck_profile_.reset(new SpellCheckProfile(path_));
1609 return spellcheck_profile_.get();
1610 }
1611
1612 void ProfileImpl::UpdateProfileUserNameCache() { 1555 void ProfileImpl::UpdateProfileUserNameCache() {
1613 ProfileManager* profile_manager = g_browser_process->profile_manager(); 1556 ProfileManager* profile_manager = g_browser_process->profile_manager();
1614 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1557 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
1615 size_t index = cache.GetIndexOfProfileWithPath(GetPath()); 1558 size_t index = cache.GetIndexOfProfileWithPath(GetPath());
1616 if (index != std::string::npos) { 1559 if (index != std::string::npos) {
1617 std::string user_name = 1560 std::string user_name =
1618 GetPrefs()->GetString(prefs::kGoogleServicesUsername); 1561 GetPrefs()->GetString(prefs::kGoogleServicesUsername);
1619 cache.SetUserNameOfProfileAtIndex(index, UTF8ToUTF16(user_name)); 1562 cache.SetUserNameOfProfileAtIndex(index, UTF8ToUTF16(user_name));
1620 } 1563 }
1621 } 1564 }
(...skipping 29 matching lines...) Expand all
1651 FilePath* cache_path, 1594 FilePath* cache_path,
1652 int* max_size) { 1595 int* max_size) {
1653 DCHECK(cache_path); 1596 DCHECK(cache_path);
1654 DCHECK(max_size); 1597 DCHECK(max_size);
1655 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); 1598 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir));
1656 if (!path.empty()) 1599 if (!path.empty())
1657 *cache_path = path; 1600 *cache_path = path;
1658 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : 1601 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1659 prefs_->GetInteger(prefs::kDiskCacheSize); 1602 prefs_->GetInteger(prefs::kDiskCacheSize);
1660 } 1603 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698