| OLD | NEW |
| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 23 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| 24 #include "chrome/browser/history/history.h" | 24 #include "chrome/browser/history/history.h" |
| 25 #include "chrome/browser/history/history_backend.h" | 25 #include "chrome/browser/history/history_backend.h" |
| 26 #include "chrome/browser/history/top_sites.h" | 26 #include "chrome/browser/history/top_sites.h" |
| 27 #include "chrome/browser/net/gaia/token_service.h" | 27 #include "chrome/browser/net/gaia/token_service.h" |
| 28 #include "chrome/browser/net/pref_proxy_config_service.h" | 28 #include "chrome/browser/net/pref_proxy_config_service.h" |
| 29 #include "chrome/browser/notifications/desktop_notification_service.h" | 29 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 30 #include "chrome/browser/prefs/browser_prefs.h" | 30 #include "chrome/browser/prefs/browser_prefs.h" |
| 31 #include "chrome/browser/prefs/testing_pref_store.h" | 31 #include "chrome/browser/prefs/testing_pref_store.h" |
| 32 #include "chrome/browser/prerender/prerender_manager.h" | 32 #include "chrome/browser/prerender/prerender_manager.h" |
| 33 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 33 #include "chrome/browser/search_engines/template_url_fetcher.h" | 34 #include "chrome/browser/search_engines/template_url_fetcher.h" |
| 34 #include "chrome/browser/search_engines/template_url_model.h" | 35 #include "chrome/browser/search_engines/template_url_model.h" |
| 35 #include "chrome/browser/sessions/session_service.h" | 36 #include "chrome/browser/sessions/session_service.h" |
| 36 #include "chrome/browser/sync/profile_sync_service_mock.h" | 37 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 37 #include "chrome/browser/ui/find_bar/find_bar_state.h" | 38 #include "chrome/browser/ui/find_bar/find_bar_state.h" |
| 38 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 39 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 39 #include "chrome/browser/ui/webui/ntp_resource_cache.h" | 40 #include "chrome/browser/ui/webui/ntp_resource_cache.h" |
| 40 #include "chrome/common/chrome_constants.h" | 41 #include "chrome/common/chrome_constants.h" |
| 41 #include "chrome/common/net/url_request_context_getter.h" | 42 #include "chrome/common/net/url_request_context_getter.h" |
| 42 #include "chrome/common/url_constants.h" | 43 #include "chrome/common/url_constants.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 private: | 139 private: |
| 139 scoped_refptr<net::URLRequestContext> context_; | 140 scoped_refptr<net::URLRequestContext> context_; |
| 140 }; | 141 }; |
| 141 | 142 |
| 142 } // namespace | 143 } // namespace |
| 143 | 144 |
| 144 TestingProfile::TestingProfile() | 145 TestingProfile::TestingProfile() |
| 145 : start_time_(Time::Now()), | 146 : start_time_(Time::Now()), |
| 146 testing_prefs_(NULL), | 147 testing_prefs_(NULL), |
| 147 incognito_(false), | 148 incognito_(false), |
| 148 last_session_exited_cleanly_(true) { | 149 last_session_exited_cleanly_(true), |
| 150 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { |
| 149 if (!temp_dir_.CreateUniqueTempDir()) { | 151 if (!temp_dir_.CreateUniqueTempDir()) { |
| 150 LOG(ERROR) << "Failed to create unique temporary directory."; | 152 LOG(ERROR) << "Failed to create unique temporary directory."; |
| 151 | 153 |
| 152 // Fallback logic in case we fail to create unique temporary directory. | 154 // Fallback logic in case we fail to create unique temporary directory. |
| 153 FilePath system_tmp_dir; | 155 FilePath system_tmp_dir; |
| 154 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); | 156 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); |
| 155 | 157 |
| 156 // We're severly screwed if we can't get the system temporary | 158 // We're severly screwed if we can't get the system temporary |
| 157 // directory. Die now to avoid writing to the filesystem root | 159 // directory. Die now to avoid writing to the filesystem root |
| 158 // or other bad places. | 160 // or other bad places. |
| 159 CHECK(success); | 161 CHECK(success); |
| 160 | 162 |
| 161 FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath")); | 163 FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath")); |
| 162 file_util::Delete(fallback_dir, true); | 164 file_util::Delete(fallback_dir, true); |
| 163 file_util::CreateDirectory(fallback_dir); | 165 file_util::CreateDirectory(fallback_dir); |
| 164 if (!temp_dir_.Set(fallback_dir)) { | 166 if (!temp_dir_.Set(fallback_dir)) { |
| 165 // That shouldn't happen, but if it does, try to recover. | 167 // That shouldn't happen, but if it does, try to recover. |
| 166 LOG(ERROR) << "Failed to use a fallback temporary directory."; | 168 LOG(ERROR) << "Failed to use a fallback temporary directory."; |
| 167 | 169 |
| 168 // We're screwed if this fails, see CHECK above. | 170 // We're screwed if this fails, see CHECK above. |
| 169 CHECK(temp_dir_.Set(system_tmp_dir)); | 171 CHECK(temp_dir_.Set(system_tmp_dir)); |
| 170 } | 172 } |
| 171 } | 173 } |
| 172 } | 174 } |
| 173 | 175 |
| 174 TestingProfile::~TestingProfile() { | 176 TestingProfile::~TestingProfile() { |
| 175 NotificationService::current()->Notify( | 177 NotificationService::current()->Notify( |
| 176 NotificationType::PROFILE_DESTROYED, | 178 NotificationType::PROFILE_DESTROYED, |
| 177 Source<Profile>(this), | 179 Source<Profile>(static_cast<Profile*>(this)), |
| 178 NotificationService::NoDetails()); | 180 NotificationService::NoDetails()); |
| 181 |
| 182 profile_dependency_manager_->DestroyProfileServices(this); |
| 183 |
| 179 DestroyTopSites(); | 184 DestroyTopSites(); |
| 180 DestroyHistoryService(); | 185 DestroyHistoryService(); |
| 181 // FaviconService depends on HistoryServce so destroying it later. | 186 // FaviconService depends on HistoryServce so destroying it later. |
| 182 DestroyFaviconService(); | 187 DestroyFaviconService(); |
| 183 DestroyWebDataService(); | 188 DestroyWebDataService(); |
| 184 if (extensions_service_.get()) { | 189 if (extensions_service_.get()) { |
| 185 extensions_service_->DestroyingProfile(); | 190 extensions_service_->DestroyingProfile(); |
| 186 extensions_service_ = NULL; | 191 extensions_service_ = NULL; |
| 187 } | 192 } |
| 188 if (pref_proxy_config_tracker_.get()) | 193 if (pref_proxy_config_tracker_.get()) |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 return temp_dir_.path(); | 354 return temp_dir_.path(); |
| 350 } | 355 } |
| 351 | 356 |
| 352 TestingPrefService* TestingProfile::GetTestingPrefService() { | 357 TestingPrefService* TestingProfile::GetTestingPrefService() { |
| 353 if (!prefs_.get()) | 358 if (!prefs_.get()) |
| 354 CreateTestingPrefService(); | 359 CreateTestingPrefService(); |
| 355 DCHECK(testing_prefs_); | 360 DCHECK(testing_prefs_); |
| 356 return testing_prefs_; | 361 return testing_prefs_; |
| 357 } | 362 } |
| 358 | 363 |
| 364 void TestingProfile::SetProfileDependencyManager( |
| 365 ProfileDependencyManager* manager) { |
| 366 profile_dependency_manager_ = manager; |
| 367 } |
| 368 |
| 359 ProfileId TestingProfile::GetRuntimeId() { | 369 ProfileId TestingProfile::GetRuntimeId() { |
| 360 return reinterpret_cast<ProfileId>(this); | 370 return reinterpret_cast<ProfileId>(this); |
| 361 } | 371 } |
| 362 | 372 |
| 363 bool TestingProfile::IsOffTheRecord() { | 373 bool TestingProfile::IsOffTheRecord() { |
| 364 return incognito_; | 374 return incognito_; |
| 365 } | 375 } |
| 366 | 376 |
| 367 void TestingProfile::SetOffTheRecordProfile(Profile* profile) { | 377 void TestingProfile::SetOffTheRecordProfile(Profile* profile) { |
| 368 incognito_profile_.reset(profile); | 378 incognito_profile_.reset(profile); |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 } | 798 } |
| 789 | 799 |
| 790 DerivedTestingProfile::DerivedTestingProfile(Profile* profile) | 800 DerivedTestingProfile::DerivedTestingProfile(Profile* profile) |
| 791 : original_profile_(profile) {} | 801 : original_profile_(profile) {} |
| 792 | 802 |
| 793 DerivedTestingProfile::~DerivedTestingProfile() {} | 803 DerivedTestingProfile::~DerivedTestingProfile() {} |
| 794 | 804 |
| 795 ProfileId DerivedTestingProfile::GetRuntimeId() { | 805 ProfileId DerivedTestingProfile::GetRuntimeId() { |
| 796 return original_profile_->GetRuntimeId(); | 806 return original_profile_->GetRuntimeId(); |
| 797 } | 807 } |
| OLD | NEW |