| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 #include "components/policy/core/common/policy_service_stub.h" | 94 #include "components/policy/core/common/policy_service_stub.h" |
| 95 #endif // defined(ENABLE_CONFIGURATION_POLICY) | 95 #endif // defined(ENABLE_CONFIGURATION_POLICY) |
| 96 | 96 |
| 97 #if defined(ENABLE_EXTENSIONS) | 97 #if defined(ENABLE_EXTENSIONS) |
| 98 #include "chrome/browser/extensions/extension_service.h" | 98 #include "chrome/browser/extensions/extension_service.h" |
| 99 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 99 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 100 #include "chrome/browser/extensions/extension_system_factory.h" | 100 #include "chrome/browser/extensions/extension_system_factory.h" |
| 101 #include "chrome/browser/extensions/test_extension_system.h" | 101 #include "chrome/browser/extensions/test_extension_system.h" |
| 102 #include "components/guest_view/browser/guest_view_manager.h" | 102 #include "components/guest_view/browser/guest_view_manager.h" |
| 103 #include "extensions/browser/event_router_factory.h" | 103 #include "extensions/browser/event_router_factory.h" |
| 104 #include "extensions/browser/extension_prefs.h" |
| 104 #include "extensions/browser/extension_prefs_factory.h" | 105 #include "extensions/browser/extension_prefs_factory.h" |
| 105 #include "extensions/browser/extension_system.h" | 106 #include "extensions/browser/extension_system.h" |
| 106 #endif | 107 #endif |
| 107 | 108 |
| 108 #if defined(OS_ANDROID) | 109 #if defined(OS_ANDROID) |
| 109 #include "chrome/browser/signin/android_profile_oauth2_token_service.h" | 110 #include "chrome/browser/signin/android_profile_oauth2_token_service.h" |
| 110 #endif | 111 #endif |
| 111 | 112 |
| 112 #if defined(ENABLE_SUPERVISED_USERS) | 113 #if defined(ENABLE_SUPERVISED_USERS) |
| 113 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 114 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 173 } |
| 173 | 174 |
| 174 protected: | 175 protected: |
| 175 ~TestExtensionURLRequestContextGetter() override {} | 176 ~TestExtensionURLRequestContextGetter() override {} |
| 176 | 177 |
| 177 private: | 178 private: |
| 178 scoped_ptr<net::URLRequestContext> context_; | 179 scoped_ptr<net::URLRequestContext> context_; |
| 179 }; | 180 }; |
| 180 | 181 |
| 181 #if defined(ENABLE_NOTIFICATIONS) | 182 #if defined(ENABLE_NOTIFICATIONS) |
| 182 KeyedService* CreateTestDesktopNotificationService( | 183 scoped_ptr<KeyedService> CreateTestDesktopNotificationService( |
| 183 content::BrowserContext* profile) { | 184 content::BrowserContext* profile) { |
| 184 return new DesktopNotificationService(static_cast<Profile*>(profile)); | 185 return make_scoped_ptr( |
| 186 new DesktopNotificationService(static_cast<Profile*>(profile))); |
| 185 } | 187 } |
| 186 #endif | 188 #endif |
| 187 | 189 |
| 188 KeyedService* BuildFaviconService(content::BrowserContext* context) { | 190 scoped_ptr<KeyedService> BuildFaviconService(content::BrowserContext* context) { |
| 189 Profile* profile = Profile::FromBrowserContext(context); | 191 Profile* profile = Profile::FromBrowserContext(context); |
| 190 return new favicon::FaviconService( | 192 return make_scoped_ptr(new favicon::FaviconService( |
| 191 ChromeFaviconClientFactory::GetForProfile(profile), | 193 ChromeFaviconClientFactory::GetForProfile(profile), |
| 192 HistoryServiceFactory::GetForProfile(profile, | 194 HistoryServiceFactory::GetForProfile( |
| 193 ServiceAccessType::EXPLICIT_ACCESS)); | 195 profile, ServiceAccessType::EXPLICIT_ACCESS))); |
| 194 } | 196 } |
| 195 | 197 |
| 196 KeyedService* BuildHistoryService(content::BrowserContext* context) { | 198 scoped_ptr<KeyedService> BuildHistoryService(content::BrowserContext* context) { |
| 197 Profile* profile = Profile::FromBrowserContext(context); | 199 Profile* profile = Profile::FromBrowserContext(context); |
| 198 history::HistoryService* history_service = new history::HistoryService( | 200 return make_scoped_ptr(new history::HistoryService( |
| 199 ChromeHistoryClientFactory::GetForProfile(profile), | 201 ChromeHistoryClientFactory::GetForProfile(profile), |
| 200 scoped_ptr<history::VisitDelegate>( | 202 scoped_ptr<history::VisitDelegate>( |
| 201 new history::ContentVisitDelegate(profile))); | 203 new history::ContentVisitDelegate(profile)))); |
| 202 return history_service; | |
| 203 } | 204 } |
| 204 | 205 |
| 205 KeyedService* BuildInMemoryURLIndex(content::BrowserContext* context) { | 206 scoped_ptr<KeyedService> BuildInMemoryURLIndex( |
| 207 content::BrowserContext* context) { |
| 206 Profile* profile = Profile::FromBrowserContext(context); | 208 Profile* profile = Profile::FromBrowserContext(context); |
| 207 InMemoryURLIndex* in_memory_url_index = new InMemoryURLIndex( | 209 scoped_ptr<InMemoryURLIndex> in_memory_url_index(new InMemoryURLIndex( |
| 208 BookmarkModelFactory::GetForProfile(profile), | 210 BookmarkModelFactory::GetForProfile(profile), |
| 209 HistoryServiceFactory::GetForProfile(profile, | 211 HistoryServiceFactory::GetForProfile(profile, |
| 210 ServiceAccessType::IMPLICIT_ACCESS), | 212 ServiceAccessType::IMPLICIT_ACCESS), |
| 211 profile->GetPath(), | 213 profile->GetPath(), |
| 212 profile->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 214 profile->GetPrefs()->GetString(prefs::kAcceptLanguages))); |
| 213 in_memory_url_index->Init(); | 215 in_memory_url_index->Init(); |
| 214 return in_memory_url_index; | 216 return in_memory_url_index.Pass(); |
| 215 } | 217 } |
| 216 | 218 |
| 217 KeyedService* BuildBookmarkModel(content::BrowserContext* context) { | 219 scoped_ptr<KeyedService> BuildBookmarkModel(content::BrowserContext* context) { |
| 218 Profile* profile = static_cast<Profile*>(context); | 220 Profile* profile = static_cast<Profile*>(context); |
| 219 ChromeBookmarkClient* bookmark_client = | 221 ChromeBookmarkClient* bookmark_client = |
| 220 ChromeBookmarkClientFactory::GetForProfile(profile); | 222 ChromeBookmarkClientFactory::GetForProfile(profile); |
| 221 BookmarkModel* bookmark_model = new BookmarkModel(bookmark_client); | 223 scoped_ptr<BookmarkModel> bookmark_model(new BookmarkModel(bookmark_client)); |
| 222 bookmark_client->Init(bookmark_model); | 224 bookmark_client->Init(bookmark_model.get()); |
| 223 bookmark_model->Load(profile->GetPrefs(), | 225 bookmark_model->Load(profile->GetPrefs(), |
| 224 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), | 226 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 225 profile->GetPath(), | 227 profile->GetPath(), |
| 226 profile->GetIOTaskRunner(), | 228 profile->GetIOTaskRunner(), |
| 227 content::BrowserThread::GetMessageLoopProxyForThread( | 229 content::BrowserThread::GetMessageLoopProxyForThread( |
| 228 content::BrowserThread::UI)); | 230 content::BrowserThread::UI)); |
| 229 return bookmark_model; | 231 return bookmark_model.Pass(); |
| 230 } | 232 } |
| 231 | 233 |
| 232 KeyedService* BuildChromeBookmarkClient( | 234 scoped_ptr<KeyedService> BuildChromeBookmarkClient( |
| 233 content::BrowserContext* context) { | 235 content::BrowserContext* context) { |
| 234 return new ChromeBookmarkClient(static_cast<Profile*>(context)); | 236 return make_scoped_ptr( |
| 237 new ChromeBookmarkClient(static_cast<Profile*>(context))); |
| 235 } | 238 } |
| 236 | 239 |
| 237 KeyedService* BuildChromeHistoryClient( | 240 scoped_ptr<KeyedService> BuildChromeHistoryClient( |
| 238 content::BrowserContext* context) { | 241 content::BrowserContext* context) { |
| 239 Profile* profile = static_cast<Profile*>(context); | 242 Profile* profile = static_cast<Profile*>(context); |
| 240 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile)); | 243 return make_scoped_ptr( |
| 244 new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile))); |
| 241 } | 245 } |
| 242 | 246 |
| 243 void TestProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type, | 247 void TestProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type, |
| 244 sql::InitStatus status) { | 248 sql::InitStatus status) { |
| 245 NOTREACHED(); | 249 NOTREACHED(); |
| 246 } | 250 } |
| 247 | 251 |
| 248 KeyedService* BuildWebDataService(content::BrowserContext* context) { | 252 scoped_ptr<KeyedService> BuildWebDataService(content::BrowserContext* context) { |
| 249 const base::FilePath& context_path = context->GetPath(); | 253 const base::FilePath& context_path = context->GetPath(); |
| 250 return new WebDataServiceWrapper( | 254 return make_scoped_ptr(new WebDataServiceWrapper( |
| 251 context_path, g_browser_process->GetApplicationLocale(), | 255 context_path, g_browser_process->GetApplicationLocale(), |
| 252 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | 256 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), |
| 253 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 257 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
| 254 sync_start_util::GetFlareForSyncableService(context_path), | 258 sync_start_util::GetFlareForSyncableService(context_path), |
| 255 &TestProfileErrorCallback); | 259 &TestProfileErrorCallback)); |
| 256 } | 260 } |
| 257 | 261 |
| 258 } // namespace | 262 } // namespace |
| 259 | 263 |
| 260 // static | 264 // static |
| 261 #if defined(OS_CHROMEOS) | 265 #if defined(OS_CHROMEOS) |
| 262 // Must be kept in sync with | 266 // Must be kept in sync with |
| 263 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. | 267 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. |
| 264 const char TestingProfile::kTestUserProfileDir[] = "test-user"; | 268 const char TestingProfile::kTestUserProfileDir[] = "test-user"; |
| 265 #else | 269 #else |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 449 |
| 446 extensions_path_ = profile_path_.AppendASCII("Extensions"); | 450 extensions_path_ = profile_path_.AppendASCII("Extensions"); |
| 447 | 451 |
| 448 #if defined(ENABLE_EXTENSIONS) | 452 #if defined(ENABLE_EXTENSIONS) |
| 449 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory( | 453 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory( |
| 450 this, extensions::TestExtensionSystem::Build); | 454 this, extensions::TestExtensionSystem::Build); |
| 451 | 455 |
| 452 extensions::TestExtensionSystem* test_extension_system = | 456 extensions::TestExtensionSystem* test_extension_system = |
| 453 static_cast<extensions::TestExtensionSystem*>( | 457 static_cast<extensions::TestExtensionSystem*>( |
| 454 extensions::ExtensionSystem::Get(this)); | 458 extensions::ExtensionSystem::Get(this)); |
| 455 extensions::ExtensionPrefs* extension_prefs = | 459 scoped_ptr<extensions::ExtensionPrefs> extension_prefs = |
| 456 test_extension_system->CreateExtensionPrefs( | 460 test_extension_system->CreateExtensionPrefs( |
| 457 base::CommandLine::ForCurrentProcess(), extensions_path_); | 461 base::CommandLine::ForCurrentProcess(), extensions_path_); |
| 458 extensions::ExtensionPrefsFactory::GetInstance()->SetInstanceForTesting( | 462 extensions::ExtensionPrefsFactory::GetInstance()->SetInstanceForTesting( |
| 459 this, extension_prefs); | 463 this, extension_prefs.Pass()); |
| 460 | 464 |
| 461 extensions::EventRouterFactory::GetInstance()->SetTestingFactory(this, | 465 extensions::EventRouterFactory::GetInstance()->SetTestingFactory(this, |
| 462 nullptr); | 466 nullptr); |
| 463 #endif | 467 #endif |
| 464 | 468 |
| 465 // Prefs for incognito profiles are set in CreateIncognitoPrefService() by | 469 // Prefs for incognito profiles are set in CreateIncognitoPrefService() by |
| 466 // simulating ProfileImpl::GetOffTheRecordPrefs(). | 470 // simulating ProfileImpl::GetOffTheRecordPrefs(). |
| 467 if (!IsOffTheRecord()) { | 471 if (!IsOffTheRecord()) { |
| 468 DCHECK(!original_profile_); | 472 DCHECK(!original_profile_); |
| 469 user_prefs::PrefRegistrySyncable* pref_registry = | 473 user_prefs::PrefRegistrySyncable* pref_registry = |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 #if defined(ENABLE_EXTENSIONS) | 1080 #if defined(ENABLE_EXTENSIONS) |
| 1077 extension_policy_, | 1081 extension_policy_, |
| 1078 #endif | 1082 #endif |
| 1079 pref_service_.Pass(), | 1083 pref_service_.Pass(), |
| 1080 original_profile, | 1084 original_profile, |
| 1081 guest_session_, | 1085 guest_session_, |
| 1082 supervised_user_id_, | 1086 supervised_user_id_, |
| 1083 policy_service_.Pass(), | 1087 policy_service_.Pass(), |
| 1084 testing_factories_); | 1088 testing_factories_); |
| 1085 } | 1089 } |
| OLD | NEW |