| OLD | NEW |
| 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/test/base/testing_profile.h" | 5 #include "chrome/test/base/testing_profile.h" |
| 6 | 6 |
| 7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 } | 463 } |
| 464 | 464 |
| 465 void TestingProfile::CreateFaviconService() { | 465 void TestingProfile::CreateFaviconService() { |
| 466 // It is up to the caller to create the history service if one is needed. | 466 // It is up to the caller to create the history service if one is needed. |
| 467 FaviconServiceFactory::GetInstance()->SetTestingFactory( | 467 FaviconServiceFactory::GetInstance()->SetTestingFactory( |
| 468 this, BuildFaviconService); | 468 this, BuildFaviconService); |
| 469 } | 469 } |
| 470 | 470 |
| 471 static KeyedService* BuildHistoryService(content::BrowserContext* context) { | 471 static KeyedService* BuildHistoryService(content::BrowserContext* context) { |
| 472 Profile* profile = static_cast<Profile*>(context); | 472 Profile* profile = static_cast<Profile*>(context); |
| 473 return new HistoryService(ChromeHistoryClientFactory::GetForProfile(profile), | 473 ChromeHistoryClient* history_client = |
| 474 profile); | 474 ChromeHistoryClientFactory::GetForProfile(profile); |
| 475 HistoryService* history_service = new HistoryService(history_client, profile); |
| 476 if (history_client) |
| 477 history_client->SetHistoryService(history_service); |
| 478 return history_service; |
| 475 } | 479 } |
| 476 | 480 |
| 477 bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { | 481 bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { |
| 478 DestroyHistoryService(); | 482 DestroyHistoryService(); |
| 479 if (delete_file) { | 483 if (delete_file) { |
| 480 base::FilePath path = GetPath(); | 484 base::FilePath path = GetPath(); |
| 481 path = path.Append(chrome::kHistoryFilename); | 485 path = path.Append(chrome::kHistoryFilename); |
| 482 if (!base::DeleteFile(path, false) || base::PathExists(path)) | 486 if (!base::DeleteFile(path, false) || base::PathExists(path)) |
| 483 return false; | 487 return false; |
| 484 } | 488 } |
| 485 // This will create and init the history service. | 489 // This will create and init the history service. |
| 486 HistoryService* history_service = static_cast<HistoryService*>( | 490 HistoryService* history_service = static_cast<HistoryService*>( |
| 487 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 491 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 488 this, BuildHistoryService)); | 492 this, BuildHistoryService)); |
| 489 if (!history_service->Init(this->GetPath(), no_db)) { | 493 if (!history_service->Init(this->GetPath(), no_db)) { |
| 490 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL); | 494 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL); |
| 491 } | 495 } |
| 492 // Disable WebHistoryService by default, since it makes network requests. | 496 // Disable WebHistoryService by default, since it makes network requests. |
| 493 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL); | 497 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL); |
| 494 return true; | 498 return true; |
| 495 } | 499 } |
| 496 | 500 |
| 497 void TestingProfile::DestroyHistoryService() { | 501 void TestingProfile::DestroyHistoryService() { |
| 502 // TODO(sdefresne): remove this once ChromeHistoryClient is no longer an |
| 503 // HistoryServiceObserver, http://crbug.com/373326 |
| 504 ChromeHistoryClient* history_client = |
| 505 ChromeHistoryClientFactory::GetForProfileWithoutCreating(this); |
| 506 if (history_client) |
| 507 history_client->Shutdown(); |
| 508 |
| 498 HistoryService* history_service = | 509 HistoryService* history_service = |
| 499 HistoryServiceFactory::GetForProfileWithoutCreating(this); | 510 HistoryServiceFactory::GetForProfileWithoutCreating(this); |
| 500 if (!history_service) | 511 if (!history_service) |
| 501 return; | 512 return; |
| 502 | 513 |
| 503 history_service->ClearCachedDataForContextID(0); | 514 history_service->ClearCachedDataForContextID(0); |
| 504 history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure()); | 515 history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure()); |
| 505 history_service->Cleanup(); | 516 history_service->Cleanup(); |
| 506 HistoryServiceFactory::ShutdownForProfile(this); | 517 HistoryServiceFactory::ShutdownForProfile(this); |
| 507 | 518 |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 #if defined(ENABLE_EXTENSIONS) | 1033 #if defined(ENABLE_EXTENSIONS) |
| 1023 extension_policy_, | 1034 extension_policy_, |
| 1024 #endif | 1035 #endif |
| 1025 pref_service_.Pass(), | 1036 pref_service_.Pass(), |
| 1026 original_profile, | 1037 original_profile, |
| 1027 guest_session_, | 1038 guest_session_, |
| 1028 supervised_user_id_, | 1039 supervised_user_id_, |
| 1029 policy_service_.Pass(), | 1040 policy_service_.Pass(), |
| 1030 testing_factories_); | 1041 testing_factories_); |
| 1031 } | 1042 } |
| OLD | NEW |