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

Side by Side Diff: chrome/browser/profile.cc

Issue 395007: Move Mac to using renderer spellchecker. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: ui test fix Created 11 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
« no previous file with comments | « chrome/browser/profile.h ('k') | chrome/browser/renderer_host/browser_render_process_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/profile.h" 5 #include "chrome/browser/profile.h"
6 6
7 #include "app/theme_provider.h" 7 #include "app/theme_provider.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 20 matching lines...) Expand all
31 #include "chrome/browser/notifications/desktop_notification_service.h" 31 #include "chrome/browser/notifications/desktop_notification_service.h"
32 #include "chrome/browser/password_manager/password_store_default.h" 32 #include "chrome/browser/password_manager/password_store_default.h"
33 #include "chrome/browser/privacy_blacklist/blacklist_io.h" 33 #include "chrome/browser/privacy_blacklist/blacklist_io.h"
34 #include "chrome/browser/profile_manager.h" 34 #include "chrome/browser/profile_manager.h"
35 #include "chrome/browser/renderer_host/render_process_host.h" 35 #include "chrome/browser/renderer_host/render_process_host.h"
36 #include "chrome/browser/search_versus_navigate_classifier.h" 36 #include "chrome/browser/search_versus_navigate_classifier.h"
37 #include "chrome/browser/search_engines/template_url_fetcher.h" 37 #include "chrome/browser/search_engines/template_url_fetcher.h"
38 #include "chrome/browser/search_engines/template_url_model.h" 38 #include "chrome/browser/search_engines/template_url_model.h"
39 #include "chrome/browser/sessions/session_service.h" 39 #include "chrome/browser/sessions/session_service.h"
40 #include "chrome/browser/sessions/tab_restore_service.h" 40 #include "chrome/browser/sessions/tab_restore_service.h"
41 #include "chrome/browser/spellchecker.h"
42 #include "chrome/browser/ssl/ssl_host_state.h" 41 #include "chrome/browser/ssl/ssl_host_state.h"
43 #include "chrome/browser/sync/profile_sync_service.h" 42 #include "chrome/browser/sync/profile_sync_service.h"
44 #include "chrome/browser/thumbnail_store.h" 43 #include "chrome/browser/thumbnail_store.h"
45 #include "chrome/browser/visitedlink_master.h" 44 #include "chrome/browser/visitedlink_master.h"
46 #include "chrome/browser/visitedlink_event_listener.h" 45 #include "chrome/browser/visitedlink_event_listener.h"
47 #include "chrome/browser/webdata/web_data_service.h" 46 #include "chrome/browser/webdata/web_data_service.h"
48 #include "chrome/common/appcache/chrome_appcache_service.h" 47 #include "chrome/common/appcache/chrome_appcache_service.h"
49 #include "chrome/common/chrome_constants.h" 48 #include "chrome/common/chrome_constants.h"
50 #include "chrome/common/chrome_paths.h" 49 #include "chrome/common/chrome_paths.h"
51 #include "chrome/common/chrome_switches.h" 50 #include "chrome/common/chrome_switches.h"
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 return start_time_; 469 return start_time_;
471 } 470 }
472 471
473 virtual TabRestoreService* GetTabRestoreService() { 472 virtual TabRestoreService* GetTabRestoreService() {
474 return NULL; 473 return NULL;
475 } 474 }
476 475
477 virtual void ResetTabRestoreService() { 476 virtual void ResetTabRestoreService() {
478 } 477 }
479 478
480 virtual void ReinitializeSpellChecker() {
481 profile_->ReinitializeSpellChecker();
482 }
483
484 virtual SpellChecker* GetSpellChecker() {
485 return profile_->GetSpellChecker();
486 }
487
488 virtual void DeleteSpellChecker() {
489 profile_->DeleteSpellChecker();
490 }
491
492 #if defined(SPELLCHECKER_IN_RENDERER)
493 virtual SpellCheckHost* GetSpellCheckHost() { 479 virtual SpellCheckHost* GetSpellCheckHost() {
494 return profile_->GetSpellCheckHost(); 480 return profile_->GetSpellCheckHost();
495 } 481 }
496 482
497 virtual void ReinitializeSpellCheckHost(bool force) { 483 virtual void ReinitializeSpellCheckHost(bool force) {
498 profile_->ReinitializeSpellCheckHost(force); 484 profile_->ReinitializeSpellCheckHost(force);
499 } 485 }
500 #endif
501 486
502 virtual WebKitContext* GetWebKitContext() { 487 virtual WebKitContext* GetWebKitContext() {
503 if (!webkit_context_.get()) 488 if (!webkit_context_.get())
504 webkit_context_ = new WebKitContext(GetPath(), true); 489 webkit_context_ = new WebKitContext(GetPath(), true);
505 DCHECK(webkit_context_.get()); 490 DCHECK(webkit_context_.get());
506 return webkit_context_.get(); 491 return webkit_context_.get();
507 } 492 }
508 493
509 virtual ThumbnailStore* GetThumbnailStore() { 494 virtual ThumbnailStore* GetThumbnailStore() {
510 return NULL; 495 return NULL;
511 } 496 }
512 497
513 virtual void MarkAsCleanShutdown() { 498 virtual void MarkAsCleanShutdown() {
514 } 499 }
515 500
516 virtual void InitExtensions() { 501 virtual void InitExtensions() {
517 NOTREACHED(); 502 NOTREACHED();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 media_request_context_(NULL), 571 media_request_context_(NULL),
587 extensions_request_context_(NULL), 572 extensions_request_context_(NULL),
588 blacklist_(NULL), 573 blacklist_(NULL),
589 history_service_created_(false), 574 history_service_created_(false),
590 favicon_service_created_(false), 575 favicon_service_created_(false),
591 created_web_data_service_(false), 576 created_web_data_service_(false),
592 created_password_store_(false), 577 created_password_store_(false),
593 created_download_manager_(false), 578 created_download_manager_(false),
594 created_theme_provider_(false), 579 created_theme_provider_(false),
595 start_time_(Time::Now()), 580 start_time_(Time::Now()),
596 spellchecker_(NULL),
597 #if defined(OS_LINUX) 581 #if defined(OS_LINUX)
598 spellcheck_host_(NULL), 582 spellcheck_host_(NULL),
599 spellcheck_host_ready_(false), 583 spellcheck_host_ready_(false),
600 #endif 584 #endif
601 shutdown_session_service_(false) { 585 shutdown_session_service_(false) {
602 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << 586 DCHECK(!path.empty()) << "Using an empty path will attempt to write " <<
603 "profile files to the root directory!"; 587 "profile files to the root directory!";
604 create_session_service_timer_.Start( 588 create_session_service_timer_.Start(
605 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, 589 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
606 &ProfileImpl::EnsureSessionServiceCreated); 590 &ProfileImpl::EnsureSessionServiceCreated);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 // increased the ref count of the service. In such a situation, when we 746 // increased the ref count of the service. In such a situation, when we
763 // decrement the refcount, it won't be 0, and the threads/databases aren't 747 // decrement the refcount, it won't be 0, and the threads/databases aren't
764 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the 748 // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
765 // databases are properly closed. 749 // databases are properly closed.
766 if (web_data_service_.get()) 750 if (web_data_service_.get())
767 web_data_service_->Shutdown(); 751 web_data_service_->Shutdown();
768 752
769 if (history_service_.get()) 753 if (history_service_.get())
770 history_service_->Cleanup(); 754 history_service_->Cleanup();
771 755
772 #if defined(SPELLCHECKER_IN_RENDERER)
773 if (spellcheck_host_.get()) 756 if (spellcheck_host_.get())
774 spellcheck_host_->UnsetObserver(); 757 spellcheck_host_->UnsetObserver();
775 #endif
776 DeleteSpellCheckerImpl(false);
777 758
778 if (default_request_context_ == request_context_) 759 if (default_request_context_ == request_context_)
779 default_request_context_ = NULL; 760 default_request_context_ = NULL;
780 761
781 CleanupRequestContext(request_context_); 762 CleanupRequestContext(request_context_);
782 CleanupRequestContext(media_request_context_); 763 CleanupRequestContext(media_request_context_);
783 CleanupRequestContext(extensions_request_context_); 764 CleanupRequestContext(extensions_request_context_);
784 765
785 // When the request contexts are gone, the blacklist wont be needed anymore. 766 // When the request contexts are gone, the blacklist wont be needed anymore.
786 blacklist_.reset(); 767 blacklist_.reset();
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 thumbnail_store_->Init( 1226 thumbnail_store_->Init(
1246 GetPath().Append(chrome::kNewTabThumbnailsFilename), this); 1227 GetPath().Append(chrome::kNewTabThumbnailsFilename), this);
1247 } 1228 }
1248 return thumbnail_store_.get(); 1229 return thumbnail_store_.get();
1249 } 1230 }
1250 1231
1251 void ProfileImpl::ResetTabRestoreService() { 1232 void ProfileImpl::ResetTabRestoreService() {
1252 tab_restore_service_ = NULL; 1233 tab_restore_service_ = NULL;
1253 } 1234 }
1254 1235
1255 // To be run in the IO thread to notify all resource message filters that the
1256 // spellchecker has changed.
1257 class NotifySpellcheckerChangeTask : public Task {
1258 public:
1259 NotifySpellcheckerChangeTask(
1260 Profile* profile,
1261 const SpellcheckerReinitializedDetails& spellchecker)
1262 : profile_(profile),
1263 spellchecker_(spellchecker) {
1264 }
1265
1266 private:
1267 void Run(void) {
1268 NotificationService::current()->Notify(
1269 NotificationType::SPELLCHECKER_REINITIALIZED,
1270 Source<Profile>(profile_),
1271 Details<SpellcheckerReinitializedDetails>(&spellchecker_));
1272 }
1273
1274 Profile* profile_;
1275 SpellcheckerReinitializedDetails spellchecker_;
1276 };
1277
1278 void ProfileImpl::ReinitializeSpellChecker() {
1279 PrefService* prefs = GetPrefs();
1280 if (prefs->GetBoolean(prefs::kEnableSpellCheck)) {
1281 DeleteSpellCheckerImpl(false);
1282
1283 // Retrieve the (perhaps updated recently) dictionary name from preferences.
1284 FilePath dict_dir;
1285 PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir);
1286 // Note that, as the object pointed to by previously by spellchecker_
1287 // is being deleted in the io thread, the spellchecker_ can be made to point
1288 // to a new object (RE-initialized) in parallel in this UI thread.
1289 spellchecker_ = new SpellChecker(dict_dir,
1290 WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
1291 GetRequestContext(),
1292 FilePath());
1293 spellchecker_->AddRef(); // Manual refcounting.
1294
1295 // Set auto spell correct status for spellchecker.
1296 spellchecker_->EnableAutoSpellCorrect(
1297 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect));
1298
1299 NotifySpellCheckerChanged();
1300 } else {
1301 DeleteSpellCheckerImpl(true);
1302 }
1303 }
1304
1305 #if defined(SPELLCHECKER_IN_RENDERER)
1306 SpellCheckHost* ProfileImpl::GetSpellCheckHost() { 1236 SpellCheckHost* ProfileImpl::GetSpellCheckHost() {
1307 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL; 1237 return spellcheck_host_ready_ ? spellcheck_host_.get() : NULL;
1308 } 1238 }
1309 1239
1310 void ProfileImpl::ReinitializeSpellCheckHost(bool force) { 1240 void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
1311 // If we are already loading the spellchecker, and this is just a hint to 1241 // If we are already loading the spellchecker, and this is just a hint to
1312 // load the spellchecker, do nothing. 1242 // load the spellchecker, do nothing.
1313 if (!force && spellcheck_host_.get()) 1243 if (!force && spellcheck_host_.get())
1314 return; 1244 return;
1315 1245
(...skipping 14 matching lines...) Expand all
1330 GetRequestContext()); 1260 GetRequestContext());
1331 spellcheck_host_->Initialize(); 1261 spellcheck_host_->Initialize();
1332 } else if (notify) { 1262 } else if (notify) {
1333 // The spellchecker has been disabled. 1263 // The spellchecker has been disabled.
1334 SpellCheckHostInitialized(); 1264 SpellCheckHostInitialized();
1335 } 1265 }
1336 } 1266 }
1337 1267
1338 void ProfileImpl::SpellCheckHostInitialized() { 1268 void ProfileImpl::SpellCheckHostInitialized() {
1339 spellcheck_host_ready_ = spellcheck_host_ && 1269 spellcheck_host_ready_ = spellcheck_host_ &&
1340 spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue; 1270 (spellcheck_host_->bdict_file() != base::kInvalidPlatformFileValue ||
1271 spellcheck_host_->use_platform_spellchecker());
1341 NotificationService::current()->Notify( 1272 NotificationService::current()->Notify(
1342 NotificationType::SPELLCHECK_HOST_REINITIALIZED, 1273 NotificationType::SPELLCHECK_HOST_REINITIALIZED,
1343 Source<Profile>(this), NotificationService::NoDetails()); 1274 Source<Profile>(this), NotificationService::NoDetails());
1344 } 1275 }
1345 #endif
1346
1347 void ProfileImpl::NotifySpellCheckerChanged() {
1348 SpellcheckerReinitializedDetails scoped_spellchecker;
1349 scoped_spellchecker.spellchecker = spellchecker_;
1350 ChromeThread::PostTask(
1351 ChromeThread::IO, FROM_HERE,
1352 new NotifySpellcheckerChangeTask(this, scoped_spellchecker));
1353 }
1354
1355 void ProfileImpl::DeleteSpellCheckerImpl(bool notify) {
1356 if (!spellchecker_)
1357 return;
1358
1359 // The spellchecker must be deleted on the I/O thread.
1360 ChromeThread::ReleaseSoon(ChromeThread::IO, FROM_HERE, spellchecker_);
1361 spellchecker_ = NULL;
1362
1363 if (notify)
1364 NotifySpellCheckerChanged();
1365 }
1366
1367 SpellChecker* ProfileImpl::GetSpellChecker() {
1368 if (!spellchecker_) {
1369 // This is where spellchecker gets initialized. Note that this is being
1370 // initialized in the ui_thread. However, this is not a problem as long as
1371 // it is *used* in the io thread.
1372 // TODO(sidchat): One day, change everything so that spellchecker gets
1373 // initialized in the IO thread itself.
1374 ReinitializeSpellChecker();
1375 }
1376
1377 return spellchecker_;
1378 }
1379 1276
1380 WebKitContext* ProfileImpl::GetWebKitContext() { 1277 WebKitContext* ProfileImpl::GetWebKitContext() {
1381 if (!webkit_context_.get()) 1278 if (!webkit_context_.get())
1382 webkit_context_ = new WebKitContext(path_, false); 1279 webkit_context_ = new WebKitContext(path_, false);
1383 DCHECK(webkit_context_.get()); 1280 DCHECK(webkit_context_.get());
1384 return webkit_context_.get(); 1281 return webkit_context_.get();
1385 } 1282 }
1386 1283
1387 DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() { 1284 DesktopNotificationService* ProfileImpl::GetDesktopNotificationService() {
1388 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 1285 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
(...skipping 16 matching lines...) Expand all
1405 } 1302 }
1406 1303
1407 void ProfileImpl::Observe(NotificationType type, 1304 void ProfileImpl::Observe(NotificationType type,
1408 const NotificationSource& source, 1305 const NotificationSource& source,
1409 const NotificationDetails& details) { 1306 const NotificationDetails& details) {
1410 if (NotificationType::PREF_CHANGED == type) { 1307 if (NotificationType::PREF_CHANGED == type) {
1411 std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); 1308 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
1412 PrefService* prefs = Source<PrefService>(source).ptr(); 1309 PrefService* prefs = Source<PrefService>(source).ptr();
1413 DCHECK(pref_name_in && prefs); 1310 DCHECK(pref_name_in && prefs);
1414 if (*pref_name_in == prefs::kSpellCheckDictionary || 1311 if (*pref_name_in == prefs::kSpellCheckDictionary ||
1415 #if !defined(SPELLCHECKER_IN_RENDERER)
1416 *pref_name_in == prefs::kEnableAutoSpellCorrect ||
1417 #endif
1418 *pref_name_in == prefs::kEnableSpellCheck) { 1312 *pref_name_in == prefs::kEnableSpellCheck) {
1419 ReinitializeSpellChecker();
1420 #if defined(SPELLCHECKER_IN_RENDERER)
1421 ReinitializeSpellCheckHost(true); 1313 ReinitializeSpellCheckHost(true);
1422 #endif 1314 } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
1315 NotificationService::current()->Notify(
1316 NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
1317 Source<Profile>(this), NotificationService::NoDetails());
1423 } 1318 }
1424 } else if (NotificationType::THEME_INSTALLED == type) { 1319 } else if (NotificationType::THEME_INSTALLED == type) {
1425 Extension* extension = Details<Extension>(details).ptr(); 1320 Extension* extension = Details<Extension>(details).ptr();
1426 SetTheme(extension); 1321 SetTheme(extension);
1427 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) { 1322 } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
1428 GetProfileSyncService(); // Causes lazy-load if sync is enabled. 1323 GetProfileSyncService(); // Causes lazy-load if sync is enabled.
1429 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED, 1324 registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
1430 Source<Profile>(this)); 1325 Source<Profile>(this));
1431 } 1326 }
1432 } 1327 }
1433 1328
1434 void ProfileImpl::StopCreateSessionServiceTimer() { 1329 void ProfileImpl::StopCreateSessionServiceTimer() {
1435 create_session_service_timer_.Stop(); 1330 create_session_service_timer_.Stop();
1436 } 1331 }
1437 1332
1438 ProfileSyncService* ProfileImpl::GetProfileSyncService() { 1333 ProfileSyncService* ProfileImpl::GetProfileSyncService() {
1439 if (!ProfileSyncService::IsSyncEnabled()) { 1334 if (!ProfileSyncService::IsSyncEnabled()) {
1440 return NULL; 1335 return NULL;
1441 } 1336 }
1442 if (!sync_service_.get()) 1337 if (!sync_service_.get())
1443 InitSyncService(); 1338 InitSyncService();
1444 return sync_service_.get(); 1339 return sync_service_.get();
1445 } 1340 }
1446 1341
1447 void ProfileImpl::InitSyncService() { 1342 void ProfileImpl::InitSyncService() {
1448 sync_service_.reset(new ProfileSyncService(this)); 1343 sync_service_.reset(new ProfileSyncService(this));
1449 sync_service_->Initialize(); 1344 sync_service_->Initialize();
1450 } 1345 }
OLDNEW
« no previous file with comments | « chrome/browser/profile.h ('k') | chrome/browser/renderer_host/browser_render_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698