| OLD | NEW |
| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/lock.h" | 10 #include "base/lock.h" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 profile_->ReinitializeSpellChecker(); | 250 profile_->ReinitializeSpellChecker(); |
| 251 } | 251 } |
| 252 | 252 |
| 253 virtual SpellChecker* GetSpellChecker() { | 253 virtual SpellChecker* GetSpellChecker() { |
| 254 return profile_->GetSpellChecker(); | 254 return profile_->GetSpellChecker(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 virtual void MarkAsCleanShutdown() { | 257 virtual void MarkAsCleanShutdown() { |
| 258 } | 258 } |
| 259 | 259 |
| 260 virtual void InitExtensions() { |
| 261 NOTREACHED(); |
| 262 } |
| 263 |
| 260 virtual void ExitedOffTheRecordMode() { | 264 virtual void ExitedOffTheRecordMode() { |
| 261 // Drop our download manager so we forget about all the downloads made | 265 // Drop our download manager so we forget about all the downloads made |
| 262 // in off-the-record mode. | 266 // in off-the-record mode. |
| 263 download_manager_ = NULL; | 267 download_manager_ = NULL; |
| 264 } | 268 } |
| 265 | 269 |
| 266 virtual void Observe(NotificationType type, | 270 virtual void Observe(NotificationType type, |
| 267 const NotificationSource& source, | 271 const NotificationSource& source, |
| 268 const NotificationDetails& details) { | 272 const NotificationDetails& details) { |
| 269 DCHECK_EQ(NOTIFY_BROWSER_CLOSED, type); | 273 DCHECK_EQ(NOTIFY_BROWSER_CLOSED, type); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 290 | 294 |
| 291 // Time we were started. | 295 // Time we were started. |
| 292 Time start_time_; | 296 Time start_time_; |
| 293 | 297 |
| 294 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl); | 298 DISALLOW_EVIL_CONSTRUCTORS(OffTheRecordProfileImpl); |
| 295 }; | 299 }; |
| 296 | 300 |
| 297 ProfileImpl::ProfileImpl(const std::wstring& path) | 301 ProfileImpl::ProfileImpl(const std::wstring& path) |
| 298 : path_(path), | 302 : path_(path), |
| 299 off_the_record_(false), | 303 off_the_record_(false), |
| 300 extensions_service_(new ExtensionsService(FilePath(path))), | |
| 301 history_service_created_(false), | 304 history_service_created_(false), |
| 302 created_web_data_service_(false), | 305 created_web_data_service_(false), |
| 303 created_download_manager_(false), | 306 created_download_manager_(false), |
| 304 request_context_(NULL), | 307 request_context_(NULL), |
| 305 start_time_(Time::Now()), | 308 start_time_(Time::Now()), |
| 306 spellchecker_(NULL), | 309 spellchecker_(NULL), |
| 307 #ifdef CHROME_PERSONALIZATION | 310 #ifdef CHROME_PERSONALIZATION |
| 308 personalization_(NULL), | 311 personalization_(NULL), |
| 309 #endif | 312 #endif |
| 310 shutdown_session_service_(false) { | 313 shutdown_session_service_(false) { |
| 311 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 314 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
| 312 "profile files to the root directory!"; | 315 "profile files to the root directory!"; |
| 313 create_session_service_timer_.Start( | 316 create_session_service_timer_.Start( |
| 314 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, | 317 TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, |
| 315 &ProfileImpl::EnsureSessionServiceCreated); | 318 &ProfileImpl::EnsureSessionServiceCreated); |
| 319 |
| 316 PrefService* prefs = GetPrefs(); | 320 PrefService* prefs = GetPrefs(); |
| 317 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this); | 321 prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this); |
| 318 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this); | 322 prefs->AddPrefObserver(prefs::kEnableSpellCheck, this); |
| 323 |
| 324 InitExtensions(); |
| 325 } |
| 326 |
| 327 void ProfileImpl::InitExtensions() { |
| 328 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 329 bool user_scripts_enabled = |
| 330 command_line->HasSwitch(switches::kEnableUserScripts); |
| 331 bool extensions_enabled = |
| 332 command_line->HasSwitch(switches::kEnableExtensions); |
| 333 |
| 334 std::wstring script_dir; |
| 335 if (user_scripts_enabled) { |
| 336 script_dir = GetPath(); |
| 337 file_util::AppendToPath(&script_dir, chrome::kUserScriptsDirname); |
| 338 } |
| 339 |
| 340 user_script_master_ = new UserScriptMaster( |
| 341 g_browser_process->file_thread()->message_loop(), FilePath(script_dir)); |
| 342 extensions_service_ = new ExtensionsService( |
| 343 FilePath(GetPath()), user_script_master_.get()); |
| 344 |
| 345 // If we have extensions, the extension service will kick off the first scan |
| 346 // after extensions are loaded. Otherwise, we need to do that now. |
| 347 if (extensions_enabled) |
| 348 extensions_service_->Init(); |
| 349 else if (user_scripts_enabled) |
| 350 user_script_master_->StartScan(); |
| 319 } | 351 } |
| 320 | 352 |
| 321 ProfileImpl::~ProfileImpl() { | 353 ProfileImpl::~ProfileImpl() { |
| 322 tab_restore_service_ = NULL; | 354 tab_restore_service_ = NULL; |
| 323 | 355 |
| 324 StopCreateSessionServiceTimer(); | 356 StopCreateSessionServiceTimer(); |
| 325 // TemplateURLModel schedules a task on the WebDataService from its | 357 // TemplateURLModel schedules a task on the WebDataService from its |
| 326 // destructor. Delete it first to ensure the task gets scheduled before we | 358 // destructor. Delete it first to ensure the task gets scheduled before we |
| 327 // shut down the database. | 359 // shut down the database. |
| 328 template_url_model_.reset(); | 360 template_url_model_.reset(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 } | 474 } |
| 443 | 475 |
| 444 return visited_link_master_.get(); | 476 return visited_link_master_.get(); |
| 445 } | 477 } |
| 446 | 478 |
| 447 ExtensionsService* ProfileImpl::GetExtensionsService() { | 479 ExtensionsService* ProfileImpl::GetExtensionsService() { |
| 448 return extensions_service_.get(); | 480 return extensions_service_.get(); |
| 449 } | 481 } |
| 450 | 482 |
| 451 UserScriptMaster* ProfileImpl::GetUserScriptMaster() { | 483 UserScriptMaster* ProfileImpl::GetUserScriptMaster() { |
| 452 if (!user_script_master_.get()) { | |
| 453 std::wstring script_dir = GetPath(); | |
| 454 file_util::AppendToPath(&script_dir, chrome::kUserScriptsDirname); | |
| 455 user_script_master_ = | |
| 456 new UserScriptMaster(g_browser_process->file_thread()->message_loop(), | |
| 457 FilePath(script_dir)); | |
| 458 } | |
| 459 | |
| 460 return user_script_master_.get(); | 484 return user_script_master_.get(); |
| 461 } | 485 } |
| 462 | 486 |
| 463 PrefService* ProfileImpl::GetPrefs() { | 487 PrefService* ProfileImpl::GetPrefs() { |
| 464 if (!prefs_.get()) { | 488 if (!prefs_.get()) { |
| 465 prefs_.reset(new PrefService(GetPrefFilePath())); | 489 prefs_.reset(new PrefService(GetPrefFilePath())); |
| 466 | 490 |
| 467 // The Profile class and ProfileManager class may read some prefs so | 491 // The Profile class and ProfileManager class may read some prefs so |
| 468 // register known prefs as soon as possible. | 492 // register known prefs as soon as possible. |
| 469 Profile::RegisterUserPrefs(prefs_.get()); | 493 Profile::RegisterUserPrefs(prefs_.get()); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 } | 782 } |
| 759 | 783 |
| 760 #ifdef CHROME_PERSONALIZATION | 784 #ifdef CHROME_PERSONALIZATION |
| 761 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() { | 785 ProfilePersonalization* ProfileImpl::GetProfilePersonalization() { |
| 762 if (!personalization_.get()) | 786 if (!personalization_.get()) |
| 763 personalization_.reset( | 787 personalization_.reset( |
| 764 Personalization::CreateProfilePersonalization(this)); | 788 Personalization::CreateProfilePersonalization(this)); |
| 765 return personalization_.get(); | 789 return personalization_.get(); |
| 766 } | 790 } |
| 767 #endif | 791 #endif |
| OLD | NEW |