| 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 "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 // It is up to the caller to create the history service if one is needed. | 359 // It is up to the caller to create the history service if one is needed. |
| 360 FaviconServiceFactory::GetInstance()->SetTestingFactory( | 360 FaviconServiceFactory::GetInstance()->SetTestingFactory( |
| 361 this, BuildFaviconService); | 361 this, BuildFaviconService); |
| 362 } | 362 } |
| 363 | 363 |
| 364 static BrowserContextKeyedService* BuildHistoryService( | 364 static BrowserContextKeyedService* BuildHistoryService( |
| 365 content::BrowserContext* profile) { | 365 content::BrowserContext* profile) { |
| 366 return new HistoryService(static_cast<Profile*>(profile)); | 366 return new HistoryService(static_cast<Profile*>(profile)); |
| 367 } | 367 } |
| 368 | 368 |
| 369 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { | 369 bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { |
| 370 DestroyHistoryService(); | 370 DestroyHistoryService(); |
| 371 if (delete_file) { | 371 if (delete_file) { |
| 372 base::FilePath path = GetPath(); | 372 base::FilePath path = GetPath(); |
| 373 path = path.Append(chrome::kHistoryFilename); | 373 path = path.Append(chrome::kHistoryFilename); |
| 374 base::DeleteFile(path, false); | 374 if (!base::DeleteFile(path, false) || base::PathExists(path)) |
| 375 return false; |
| 375 } | 376 } |
| 376 // This will create and init the history service. | 377 // This will create and init the history service. |
| 377 HistoryService* history_service = static_cast<HistoryService*>( | 378 HistoryService* history_service = static_cast<HistoryService*>( |
| 378 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 379 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 379 this, BuildHistoryService)); | 380 this, BuildHistoryService)); |
| 380 if (!history_service->Init(this->GetPath(), | 381 if (!history_service->Init(this->GetPath(), |
| 381 BookmarkModelFactory::GetForProfile(this), | 382 BookmarkModelFactory::GetForProfile(this), |
| 382 no_db)) { | 383 no_db)) { |
| 383 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL); | 384 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL); |
| 384 } | 385 } |
| 385 // Disable WebHistoryService by default, since it makes network requests. | 386 // Disable WebHistoryService by default, since it makes network requests. |
| 386 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL); | 387 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL); |
| 388 return true; |
| 387 } | 389 } |
| 388 | 390 |
| 389 void TestingProfile::DestroyHistoryService() { | 391 void TestingProfile::DestroyHistoryService() { |
| 390 HistoryService* history_service = | 392 HistoryService* history_service = |
| 391 HistoryServiceFactory::GetForProfileWithoutCreating(this); | 393 HistoryServiceFactory::GetForProfileWithoutCreating(this); |
| 392 if (!history_service) | 394 if (!history_service) |
| 393 return; | 395 return; |
| 394 | 396 |
| 395 history_service->NotifyRenderProcessHostDestruction(0); | 397 history_service->NotifyRenderProcessHostDestruction(0); |
| 396 history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure()); | 398 history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure()); |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 | 812 |
| 811 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { | 813 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { |
| 812 DCHECK(!build_called_); | 814 DCHECK(!build_called_); |
| 813 build_called_ = true; | 815 build_called_ = true; |
| 814 return scoped_ptr<TestingProfile>(new TestingProfile( | 816 return scoped_ptr<TestingProfile>(new TestingProfile( |
| 815 path_, | 817 path_, |
| 816 delegate_, | 818 delegate_, |
| 817 extension_policy_, | 819 extension_policy_, |
| 818 pref_service_.Pass())); | 820 pref_service_.Pass())); |
| 819 } | 821 } |
| OLD | NEW |