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

Side by Side Diff: chrome/test/base/testing_profile.cc

Issue 19616004: Add asserts to TestingProfile::CreateHistoryService to ensure files are deleted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Propigate CreateHistoryService return value properly Created 7 years, 5 months 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
OLDNEW
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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // It is up to the caller to create the history service if one is needed. 347 // It is up to the caller to create the history service if one is needed.
348 FaviconServiceFactory::GetInstance()->SetTestingFactory( 348 FaviconServiceFactory::GetInstance()->SetTestingFactory(
349 this, BuildFaviconService); 349 this, BuildFaviconService);
350 } 350 }
351 351
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 bool 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::DeleteFile(path, false); 362 if (!base::DeleteFile(path, false) ||
sky 2013/07/23 13:59:37 nit: seems like you could fit this on one line and
rmcilroy 2013/07/23 14:30:50 Done.
363 base::PathExists(path)) {
364 return false;
365 }
363 } 366 }
364 // This will create and init the history service. 367 // This will create and init the history service.
365 HistoryService* history_service = static_cast<HistoryService*>( 368 HistoryService* history_service = static_cast<HistoryService*>(
366 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( 369 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(
367 this, BuildHistoryService)); 370 this, BuildHistoryService));
368 if (!history_service->Init(this->GetPath(), 371 if (!history_service->Init(this->GetPath(),
369 BookmarkModelFactory::GetForProfile(this), 372 BookmarkModelFactory::GetForProfile(this),
370 no_db)) { 373 no_db)) {
371 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL); 374 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL);
372 } 375 }
373 // Disable WebHistoryService by default, since it makes network requests. 376 // Disable WebHistoryService by default, since it makes network requests.
374 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL); 377 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
378 return true;
375 } 379 }
376 380
377 void TestingProfile::DestroyHistoryService() { 381 void TestingProfile::DestroyHistoryService() {
378 HistoryService* history_service = 382 HistoryService* history_service =
379 HistoryServiceFactory::GetForProfileWithoutCreating(this); 383 HistoryServiceFactory::GetForProfileWithoutCreating(this);
380 if (!history_service) 384 if (!history_service)
381 return; 385 return;
382 386
383 history_service->NotifyRenderProcessHostDestruction(0); 387 history_service->NotifyRenderProcessHostDestruction(0);
384 history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure()); 388 history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure());
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 815
812 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { 816 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() {
813 DCHECK(!build_called_); 817 DCHECK(!build_called_);
814 build_called_ = true; 818 build_called_ = true;
815 return scoped_ptr<TestingProfile>(new TestingProfile( 819 return scoped_ptr<TestingProfile>(new TestingProfile(
816 path_, 820 path_,
817 delegate_, 821 delegate_,
818 extension_policy_, 822 extension_policy_,
819 pref_service_.Pass())); 823 pref_service_.Pass()));
820 } 824 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698