OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
10 #include "chrome/browser/dom_ui/ntp_resource_cache.h" | 10 #include "chrome/browser/dom_ui/ntp_resource_cache.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 last_session_exited_cleanly_(true) { | 127 last_session_exited_cleanly_(true) { |
128 PathService::Get(base::DIR_TEMP, &path_); | 128 PathService::Get(base::DIR_TEMP, &path_); |
129 path_ = path_.Append(FILE_PATH_LITERAL("TestingProfilePath")); | 129 path_ = path_.Append(FILE_PATH_LITERAL("TestingProfilePath")); |
130 path_ = path_.AppendASCII(IntToString(count)); | 130 path_ = path_.AppendASCII(IntToString(count)); |
131 file_util::Delete(path_, true); | 131 file_util::Delete(path_, true); |
132 file_util::CreateDirectory(path_); | 132 file_util::CreateDirectory(path_); |
133 } | 133 } |
134 | 134 |
135 TestingProfile::~TestingProfile() { | 135 TestingProfile::~TestingProfile() { |
136 DestroyHistoryService(); | 136 DestroyHistoryService(); |
| 137 DestroyWebDataService(); |
137 file_util::Delete(path_, true); | 138 file_util::Delete(path_, true); |
138 } | 139 } |
139 | 140 |
140 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { | 141 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { |
141 if (history_service_.get()) | 142 if (history_service_.get()) |
142 history_service_->Cleanup(); | 143 history_service_->Cleanup(); |
143 | 144 |
144 history_service_ = NULL; | 145 history_service_ = NULL; |
145 | 146 |
146 if (delete_file) { | 147 if (delete_file) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 bookmark_bar_model_.reset(new BookmarkModel(this)); | 186 bookmark_bar_model_.reset(new BookmarkModel(this)); |
186 if (history_service_.get()) { | 187 if (history_service_.get()) { |
187 history_service_->history_backend_->bookmark_service_ = | 188 history_service_->history_backend_->bookmark_service_ = |
188 bookmark_bar_model_.get(); | 189 bookmark_bar_model_.get(); |
189 history_service_->history_backend_->expirer_.bookmark_service_ = | 190 history_service_->history_backend_->expirer_.bookmark_service_ = |
190 bookmark_bar_model_.get(); | 191 bookmark_bar_model_.get(); |
191 } | 192 } |
192 bookmark_bar_model_->Load(); | 193 bookmark_bar_model_->Load(); |
193 } | 194 } |
194 | 195 |
| 196 void TestingProfile::CreateWebDataService(bool delete_file) { |
| 197 if (web_data_service_.get()) |
| 198 web_data_service_->Shutdown(); |
| 199 |
| 200 if (delete_file) { |
| 201 FilePath path = GetPath(); |
| 202 path = path.Append(chrome::kWebDataFilename); |
| 203 file_util::Delete(path, false); |
| 204 } |
| 205 |
| 206 web_data_service_ = new WebDataService; |
| 207 if (web_data_service_.get()) |
| 208 web_data_service_->Init(GetPath()); |
| 209 } |
| 210 |
195 void TestingProfile::BlockUntilBookmarkModelLoaded() { | 211 void TestingProfile::BlockUntilBookmarkModelLoaded() { |
196 DCHECK(bookmark_bar_model_.get()); | 212 DCHECK(bookmark_bar_model_.get()); |
197 if (bookmark_bar_model_->IsLoaded()) | 213 if (bookmark_bar_model_->IsLoaded()) |
198 return; | 214 return; |
199 BookmarkLoadObserver observer; | 215 BookmarkLoadObserver observer; |
200 bookmark_bar_model_->AddObserver(&observer); | 216 bookmark_bar_model_->AddObserver(&observer); |
201 MessageLoop::current()->Run(); | 217 MessageLoop::current()->Run(); |
202 bookmark_bar_model_->RemoveObserver(&observer); | 218 bookmark_bar_model_->RemoveObserver(&observer); |
203 DCHECK(bookmark_bar_model_->IsLoaded()); | 219 DCHECK(bookmark_bar_model_->IsLoaded()); |
204 } | 220 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 void TestingProfile::CreateProfileSyncService() { | 274 void TestingProfile::CreateProfileSyncService() { |
259 if (!profile_sync_service_.get()) { | 275 if (!profile_sync_service_.get()) { |
260 profile_sync_service_.reset(new ProfileSyncService(this)); | 276 profile_sync_service_.reset(new ProfileSyncService(this)); |
261 profile_sync_service_->Initialize(); | 277 profile_sync_service_->Initialize(); |
262 } | 278 } |
263 } | 279 } |
264 | 280 |
265 ProfileSyncService* TestingProfile::GetProfileSyncService() { | 281 ProfileSyncService* TestingProfile::GetProfileSyncService() { |
266 return profile_sync_service_.get(); | 282 return profile_sync_service_.get(); |
267 } | 283 } |
| 284 |
| 285 void TestingProfile::DestroyWebDataService() { |
| 286 if (!web_data_service_.get()) |
| 287 return; |
| 288 |
| 289 web_data_service_->Shutdown(); |
| 290 } |
OLD | NEW |