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

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

Issue 7285014: [wip] Profile: Sketch of a creation system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/testing_profile.h" 5 #include "chrome/test/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"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/message_loop_proxy.h" 12 #include "base/message_loop_proxy.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
16 #include "chrome/browser/background/background_contents_service_factory.h"
17 #include "chrome/browser/bookmarks/bookmark_model.h" 16 #include "chrome/browser/bookmarks/bookmark_model.h"
18 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/content_settings/host_content_settings_map.h" 18 #include "chrome/browser/content_settings/host_content_settings_map.h"
20 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 19 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
21 #include "chrome/browser/extensions/extension_pref_value_map.h" 20 #include "chrome/browser/extensions/extension_pref_value_map.h"
22 #include "chrome/browser/extensions/extension_service.h" 21 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/extensions/extension_special_storage_policy.h" 22 #include "chrome/browser/extensions/extension_special_storage_policy.h"
24 #include "chrome/browser/favicon/favicon_service.h" 23 #include "chrome/browser/favicon/favicon_service.h"
25 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" 24 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
26 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" 25 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
27 #include "chrome/browser/history/history.h" 26 #include "chrome/browser/history/history.h"
28 #include "chrome/browser/history/history_backend.h" 27 #include "chrome/browser/history/history_backend.h"
29 #include "chrome/browser/history/top_sites.h" 28 #include "chrome/browser/history/top_sites.h"
30 #include "chrome/browser/net/gaia/token_service.h" 29 #include "chrome/browser/net/gaia/token_service.h"
31 #include "chrome/browser/net/pref_proxy_config_service.h" 30 #include "chrome/browser/net/pref_proxy_config_service.h"
32 #include "chrome/browser/notifications/desktop_notification_service.h" 31 #include "chrome/browser/notifications/desktop_notification_service.h"
33 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 32 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
34 #include "chrome/browser/prefs/browser_prefs.h" 33 #include "chrome/browser/prefs/browser_prefs.h"
35 #include "chrome/browser/prefs/testing_pref_store.h" 34 #include "chrome/browser/prefs/testing_pref_store.h"
36 #include "chrome/browser/prerender/prerender_manager.h" 35 #include "chrome/browser/prerender/prerender_manager.h"
37 #include "chrome/browser/profiles/profile_dependency_manager.h" 36 #include "chrome/browser/profiles/profile_dependency_manager.h"
38 #include "chrome/browser/search_engines/template_url_fetcher.h" 37 #include "chrome/browser/search_engines/template_url_fetcher.h"
39 #include "chrome/browser/search_engines/template_url_service.h" 38 #include "chrome/browser/search_engines/template_url_service.h"
40 #include "chrome/browser/search_engines/template_url_service_factory.h" 39 #include "chrome/browser/search_engines/template_url_service_factory.h"
41 #include "chrome/browser/sessions/session_service_factory.h"
42 #include "chrome/browser/sessions/tab_restore_service_factory.h"
43 #include "chrome/browser/sync/profile_sync_service_mock.h" 40 #include "chrome/browser/sync/profile_sync_service_mock.h"
44 #include "chrome/browser/ui/find_bar/find_bar_state.h" 41 #include "chrome/browser/ui/find_bar/find_bar_state.h"
45 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 42 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
46 #include "chrome/common/chrome_constants.h" 43 #include "chrome/common/chrome_constants.h"
47 #include "chrome/common/chrome_notification_types.h" 44 #include "chrome/common/chrome_notification_types.h"
48 #include "chrome/common/url_constants.h" 45 #include "chrome/common/url_constants.h"
49 #include "chrome/test/bookmark_load_observer.h" 46 #include "chrome/test/bookmark_load_observer.h"
50 #include "chrome/test/test_url_request_context_getter.h" 47 #include "chrome/test/test_url_request_context_getter.h"
51 #include "chrome/test/testing_pref_service.h" 48 #include "chrome/test/testing_pref_service.h"
52 #include "chrome/test/ui_test_utils.h" 49 #include "chrome/test/ui_test_utils.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 119 }
123 120
124 } // namespace 121 } // namespace
125 122
126 TestingProfile::TestingProfile() 123 TestingProfile::TestingProfile()
127 : start_time_(Time::Now()), 124 : start_time_(Time::Now()),
128 testing_prefs_(NULL), 125 testing_prefs_(NULL),
129 incognito_(false), 126 incognito_(false),
130 last_session_exited_cleanly_(true), 127 last_session_exited_cleanly_(true),
131 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { 128 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) {
132 #ifndef NDEBUG 129 profile_dependency_manager_->CreateProfileServices(this, true);
133 profile_dependency_manager_->ProfileNowExists(this);
134 #endif
135 130
136 if (!temp_dir_.CreateUniqueTempDir()) { 131 if (!temp_dir_.CreateUniqueTempDir()) {
137 LOG(ERROR) << "Failed to create unique temporary directory."; 132 LOG(ERROR) << "Failed to create unique temporary directory.";
138 133
139 // Fallback logic in case we fail to create unique temporary directory. 134 // Fallback logic in case we fail to create unique temporary directory.
140 FilePath system_tmp_dir; 135 FilePath system_tmp_dir;
141 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); 136 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
142 137
143 // We're severly screwed if we can't get the system temporary 138 // We're severly screwed if we can't get the system temporary
144 // directory. Die now to avoid writing to the filesystem root 139 // directory. Die now to avoid writing to the filesystem root
145 // or other bad places. 140 // or other bad places.
146 CHECK(success); 141 CHECK(success);
147 142
148 FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath")); 143 FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath"));
149 file_util::Delete(fallback_dir, true); 144 file_util::Delete(fallback_dir, true);
150 file_util::CreateDirectory(fallback_dir); 145 file_util::CreateDirectory(fallback_dir);
151 if (!temp_dir_.Set(fallback_dir)) { 146 if (!temp_dir_.Set(fallback_dir)) {
152 // That shouldn't happen, but if it does, try to recover. 147 // That shouldn't happen, but if it does, try to recover.
153 LOG(ERROR) << "Failed to use a fallback temporary directory."; 148 LOG(ERROR) << "Failed to use a fallback temporary directory.";
154 149
155 // We're screwed if this fails, see CHECK above. 150 // We're screwed if this fails, see CHECK above.
156 CHECK(temp_dir_.Set(system_tmp_dir)); 151 CHECK(temp_dir_.Set(system_tmp_dir));
157 } 152 }
158 } 153 }
159 154
160 // Install profile keyed service factory hooks for dummy/test services 155 // Install profile keyed service factory hooks for dummy/test services
161 BackgroundContentsServiceFactory::GetInstance()->SetTestingFactory(
162 this, NULL);
163 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( 156 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
164 this, CreateTestDesktopNotificationService); 157 this, CreateTestDesktopNotificationService);
165 SessionServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
166 TabRestoreServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
167 TemplateURLServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
168 158
169 NotificationService::current()->Notify( 159 NotificationService::current()->Notify(
170 chrome::NOTIFICATION_PROFILE_CREATED, 160 chrome::NOTIFICATION_PROFILE_CREATED,
171 Source<Profile>(static_cast<Profile*>(this)), 161 Source<Profile>(static_cast<Profile*>(this)),
172 NotificationService::NoDetails()); 162 NotificationService::NoDetails());
173 } 163 }
174 164
175 TestingProfile::~TestingProfile() { 165 TestingProfile::~TestingProfile() {
176 NotificationService::current()->Notify( 166 NotificationService::current()->Notify(
177 chrome::NOTIFICATION_PROFILE_DESTROYED, 167 chrome::NOTIFICATION_PROFILE_DESTROYED,
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { 783 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
794 return GetExtensionSpecialStoragePolicy(); 784 return GetExtensionSpecialStoragePolicy();
795 } 785 }
796 786
797 void TestingProfile::DestroyWebDataService() { 787 void TestingProfile::DestroyWebDataService() {
798 if (!web_data_service_.get()) 788 if (!web_data_service_.get())
799 return; 789 return;
800 790
801 web_data_service_->Shutdown(); 791 web_data_service_->Shutdown();
802 } 792 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698