| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 base::FilePath system_tmp_dir; | 261 base::FilePath system_tmp_dir; |
| 262 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); | 262 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); |
| 263 | 263 |
| 264 // We're severly screwed if we can't get the system temporary | 264 // We're severly screwed if we can't get the system temporary |
| 265 // directory. Die now to avoid writing to the filesystem root | 265 // directory. Die now to avoid writing to the filesystem root |
| 266 // or other bad places. | 266 // or other bad places. |
| 267 CHECK(success); | 267 CHECK(success); |
| 268 | 268 |
| 269 base::FilePath fallback_dir( | 269 base::FilePath fallback_dir( |
| 270 system_tmp_dir.AppendASCII("TestingProfilePath")); | 270 system_tmp_dir.AppendASCII("TestingProfilePath")); |
| 271 base::Delete(fallback_dir, true); | 271 base::DeleteFile(fallback_dir, true); |
| 272 file_util::CreateDirectory(fallback_dir); | 272 file_util::CreateDirectory(fallback_dir); |
| 273 if (!temp_dir_.Set(fallback_dir)) { | 273 if (!temp_dir_.Set(fallback_dir)) { |
| 274 // That shouldn't happen, but if it does, try to recover. | 274 // That shouldn't happen, but if it does, try to recover. |
| 275 LOG(ERROR) << "Failed to use a fallback temporary directory."; | 275 LOG(ERROR) << "Failed to use a fallback temporary directory."; |
| 276 | 276 |
| 277 // We're screwed if this fails, see CHECK above. | 277 // We're screwed if this fails, see CHECK above. |
| 278 CHECK(temp_dir_.Set(system_tmp_dir)); | 278 CHECK(temp_dir_.Set(system_tmp_dir)); |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 } | 281 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 static BrowserContextKeyedService* BuildHistoryService( | 352 static BrowserContextKeyedService* BuildHistoryService( |
| 353 content::BrowserContext* profile) { | 353 content::BrowserContext* profile) { |
| 354 return new HistoryService(static_cast<Profile*>(profile)); | 354 return new HistoryService(static_cast<Profile*>(profile)); |
| 355 } | 355 } |
| 356 | 356 |
| 357 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { | 357 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { |
| 358 DestroyHistoryService(); | 358 DestroyHistoryService(); |
| 359 if (delete_file) { | 359 if (delete_file) { |
| 360 base::FilePath path = GetPath(); | 360 base::FilePath path = GetPath(); |
| 361 path = path.Append(chrome::kHistoryFilename); | 361 path = path.Append(chrome::kHistoryFilename); |
| 362 base::Delete(path, false); | 362 base::DeleteFile(path, false); |
| 363 } | 363 } |
| 364 // This will create and init the history service. | 364 // This will create and init the history service. |
| 365 HistoryService* history_service = static_cast<HistoryService*>( | 365 HistoryService* history_service = static_cast<HistoryService*>( |
| 366 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 366 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 367 this, BuildHistoryService)); | 367 this, BuildHistoryService)); |
| 368 if (!history_service->Init(this->GetPath(), | 368 if (!history_service->Init(this->GetPath(), |
| 369 BookmarkModelFactory::GetForProfile(this), | 369 BookmarkModelFactory::GetForProfile(this), |
| 370 no_db)) { | 370 no_db)) { |
| 371 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL); | 371 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL); |
| 372 } | 372 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 Profile* profile = static_cast<Profile*>(context); | 421 Profile* profile = static_cast<Profile*>(context); |
| 422 BookmarkModel* bookmark_model = new BookmarkModel(profile); | 422 BookmarkModel* bookmark_model = new BookmarkModel(profile); |
| 423 bookmark_model->Load(profile->GetIOTaskRunner()); | 423 bookmark_model->Load(profile->GetIOTaskRunner()); |
| 424 return bookmark_model; | 424 return bookmark_model; |
| 425 } | 425 } |
| 426 | 426 |
| 427 | 427 |
| 428 void TestingProfile::CreateBookmarkModel(bool delete_file) { | 428 void TestingProfile::CreateBookmarkModel(bool delete_file) { |
| 429 if (delete_file) { | 429 if (delete_file) { |
| 430 base::FilePath path = GetPath().Append(chrome::kBookmarksFileName); | 430 base::FilePath path = GetPath().Append(chrome::kBookmarksFileName); |
| 431 base::Delete(path, false); | 431 base::DeleteFile(path, false); |
| 432 } | 432 } |
| 433 // This will create a bookmark model. | 433 // This will create a bookmark model. |
| 434 BookmarkModel* bookmark_service = static_cast<BookmarkModel*>( | 434 BookmarkModel* bookmark_service = static_cast<BookmarkModel*>( |
| 435 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse( | 435 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse( |
| 436 this, BuildBookmarkModel)); | 436 this, BuildBookmarkModel)); |
| 437 | 437 |
| 438 HistoryService* history_service = | 438 HistoryService* history_service = |
| 439 HistoryServiceFactory::GetForProfileWithoutCreating(this); | 439 HistoryServiceFactory::GetForProfileWithoutCreating(this); |
| 440 if (history_service) { | 440 if (history_service) { |
| 441 history_service->history_backend_->bookmark_service_ = bookmark_service; | 441 history_service->history_backend_->bookmark_service_ = bookmark_service; |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 | 806 |
| 807 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { | 807 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { |
| 808 DCHECK(!build_called_); | 808 DCHECK(!build_called_); |
| 809 build_called_ = true; | 809 build_called_ = true; |
| 810 return scoped_ptr<TestingProfile>(new TestingProfile( | 810 return scoped_ptr<TestingProfile>(new TestingProfile( |
| 811 path_, | 811 path_, |
| 812 delegate_, | 812 delegate_, |
| 813 extension_policy_, | 813 extension_policy_, |
| 814 pref_service_.Pass())); | 814 pref_service_.Pass())); |
| 815 } | 815 } |
| OLD | NEW |