| OLD | NEW | 
|    1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 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  |    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/bookmarks/bookmark_model.h" |   16 #include "chrome/browser/bookmarks/bookmark_model.h" | 
|   17 #include "chrome/browser/chrome_thread.h" |   17 #include "chrome/browser/chrome_thread.h" | 
|   18 #include "chrome/browser/dom_ui/ntp_resource_cache.h" |   18 #include "chrome/browser/dom_ui/ntp_resource_cache.h" | 
 |   19 #include "chrome/browser/extensions/extensions_service.h" | 
|   19 #include "chrome/browser/favicon_service.h" |   20 #include "chrome/browser/favicon_service.h" | 
|   20 #include "chrome/browser/find_bar_state.h" |   21 #include "chrome/browser/find_bar_state.h" | 
|   21 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |   22 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 
|   22 #include "chrome/browser/geolocation/geolocation_permission_context.h" |   23 #include "chrome/browser/geolocation/geolocation_permission_context.h" | 
|   23 #include "chrome/browser/history/history.h" |   24 #include "chrome/browser/history/history.h" | 
|   24 #include "chrome/browser/history/history_backend.h" |   25 #include "chrome/browser/history/history_backend.h" | 
|   25 #include "chrome/browser/history/top_sites.h" |   26 #include "chrome/browser/history/top_sites.h" | 
|   26 #include "chrome/browser/host_content_settings_map.h" |   27 #include "chrome/browser/host_content_settings_map.h" | 
|   27 #include "chrome/browser/in_process_webkit/webkit_context.h" |   28 #include "chrome/browser/in_process_webkit/webkit_context.h" | 
|   28 #include "chrome/browser/net/gaia/token_service.h" |   29 #include "chrome/browser/net/gaia/token_service.h" | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  159   } |  160   } | 
|  160  |  161  | 
|  161  private: |  162  private: | 
|  162   scoped_refptr<URLRequestContext> context_; |  163   scoped_refptr<URLRequestContext> context_; | 
|  163 }; |  164 }; | 
|  164  |  165  | 
|  165 }  // namespace |  166 }  // namespace | 
|  166  |  167  | 
|  167 TestingProfile::TestingProfile() |  168 TestingProfile::TestingProfile() | 
|  168     : start_time_(Time::Now()), |  169     : start_time_(Time::Now()), | 
 |  170       testing_prefs_(NULL), | 
|  169       created_theme_provider_(false), |  171       created_theme_provider_(false), | 
|  170       has_history_service_(false), |  172       has_history_service_(false), | 
|  171       off_the_record_(false), |  173       off_the_record_(false), | 
|  172       last_session_exited_cleanly_(true) { |  174       last_session_exited_cleanly_(true) { | 
|  173   if (!temp_dir_.CreateUniqueTempDir()) { |  175   if (!temp_dir_.CreateUniqueTempDir()) { | 
|  174     LOG(ERROR) << "Failed to create unique temporary directory."; |  176     LOG(ERROR) << "Failed to create unique temporary directory."; | 
|  175  |  177  | 
|  176     // Fallback logic in case we fail to create unique temporary directory. |  178     // Fallback logic in case we fail to create unique temporary directory. | 
|  177     FilePath system_tmp_dir; |  179     FilePath system_tmp_dir; | 
|  178     bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); |  180     bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
|  200       NotificationType::PROFILE_DESTROYED, |  202       NotificationType::PROFILE_DESTROYED, | 
|  201       Source<Profile>(this), |  203       Source<Profile>(this), | 
|  202       NotificationService::NoDetails()); |  204       NotificationService::NoDetails()); | 
|  203   DestroyHistoryService(); |  205   DestroyHistoryService(); | 
|  204   // FaviconService depends on HistoryServce so destroying it later. |  206   // FaviconService depends on HistoryServce so destroying it later. | 
|  205   DestroyFaviconService(); |  207   DestroyFaviconService(); | 
|  206   DestroyWebDataService(); |  208   DestroyWebDataService(); | 
|  207   if (top_sites_.get()) |  209   if (top_sites_.get()) | 
|  208     top_sites_->ClearProfile(); |  210     top_sites_->ClearProfile(); | 
|  209   history::TopSites::DeleteTopSites(top_sites_); |  211   history::TopSites::DeleteTopSites(top_sites_); | 
 |  212   if (extensions_service_.get()) { | 
 |  213     extensions_service_->DestroyingProfile(); | 
 |  214     extensions_service_ = NULL; | 
 |  215   } | 
|  210 } |  216 } | 
|  211  |  217  | 
|  212 void TestingProfile::CreateFaviconService() { |  218 void TestingProfile::CreateFaviconService() { | 
|  213   favicon_service_ = NULL; |  219   favicon_service_ = NULL; | 
|  214   favicon_service_ = new FaviconService(this); |  220   favicon_service_ = new FaviconService(this); | 
|  215 } |  221 } | 
|  216  |  222  | 
|  217 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { |  223 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { | 
|  218   if (history_service_.get()) |  224   if (history_service_.get()) | 
|  219     history_service_->Cleanup(); |  225     history_service_->Cleanup(); | 
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  308 void TestingProfile::CreateTemplateURLModel() { |  314 void TestingProfile::CreateTemplateURLModel() { | 
|  309   template_url_model_.reset(new TemplateURLModel(this)); |  315   template_url_model_.reset(new TemplateURLModel(this)); | 
|  310 } |  316 } | 
|  311  |  317  | 
|  312 void TestingProfile::UseThemeProvider(BrowserThemeProvider* theme_provider) { |  318 void TestingProfile::UseThemeProvider(BrowserThemeProvider* theme_provider) { | 
|  313   theme_provider->Init(this); |  319   theme_provider->Init(this); | 
|  314   created_theme_provider_ = true; |  320   created_theme_provider_ = true; | 
|  315   theme_provider_.reset(theme_provider); |  321   theme_provider_.reset(theme_provider); | 
|  316 } |  322 } | 
|  317  |  323  | 
 |  324 scoped_refptr<ExtensionsService> TestingProfile::CreateExtensionsService( | 
 |  325     const CommandLine* command_line, | 
 |  326     const FilePath& install_directory) { | 
 |  327   extensions_service_ = new ExtensionsService(this, | 
 |  328                                               command_line, | 
 |  329                                               install_directory, | 
 |  330                                               false); | 
 |  331   return extensions_service_; | 
 |  332 } | 
 |  333  | 
|  318 FilePath TestingProfile::GetPath() { |  334 FilePath TestingProfile::GetPath() { | 
|  319   DCHECK(temp_dir_.IsValid());  // TODO(phajdan.jr): do it better. |  335   DCHECK(temp_dir_.IsValid());  // TODO(phajdan.jr): do it better. | 
|  320   return temp_dir_.path(); |  336   return temp_dir_.path(); | 
|  321 } |  337 } | 
|  322  |  338  | 
|  323 TestingPrefService* TestingProfile::GetTestingPrefService() { |  339 TestingPrefService* TestingProfile::GetTestingPrefService() { | 
|  324   return static_cast<TestingPrefService*>(GetPrefs()); |  340   if (!prefs_.get()) | 
 |  341     CreateTestingPrefService(); | 
 |  342   DCHECK(testing_prefs_); | 
 |  343   return testing_prefs_; | 
|  325 } |  344 } | 
|  326  |  345  | 
|  327 webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() { |  346 webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() { | 
|  328   if (!db_tracker_) |  347   if (!db_tracker_) | 
|  329     db_tracker_ = new webkit_database::DatabaseTracker(GetPath(), false); |  348     db_tracker_ = new webkit_database::DatabaseTracker(GetPath(), false); | 
|  330   return db_tracker_; |  349   return db_tracker_; | 
|  331 } |  350 } | 
|  332  |  351  | 
 |  352 ExtensionsService* TestingProfile::GetExtensionsService() { | 
 |  353   return extensions_service_.get(); | 
 |  354 } | 
 |  355  | 
|  333 net::CookieMonster* TestingProfile::GetCookieMonster() { |  356 net::CookieMonster* TestingProfile::GetCookieMonster() { | 
|  334   if (!GetRequestContext()) |  357   if (!GetRequestContext()) | 
|  335     return NULL; |  358     return NULL; | 
|  336   return GetRequestContext()->GetCookieStore()->GetCookieMonster(); |  359   return GetRequestContext()->GetCookieStore()->GetCookieMonster(); | 
|  337 } |  360 } | 
|  338  |  361  | 
|  339 void TestingProfile::InitThemes() { |  362 void TestingProfile::InitThemes() { | 
|  340   if (!created_theme_provider_) { |  363   if (!created_theme_provider_) { | 
|  341 #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) |  364 #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) | 
|  342     theme_provider_.reset(new GtkThemeProvider); |  365     theme_provider_.reset(new GtkThemeProvider); | 
|  343 #else |  366 #else | 
|  344     theme_provider_.reset(new BrowserThemeProvider); |  367     theme_provider_.reset(new BrowserThemeProvider); | 
|  345 #endif |  368 #endif | 
|  346     theme_provider_->Init(this); |  369     theme_provider_->Init(this); | 
|  347     created_theme_provider_ = true; |  370     created_theme_provider_ = true; | 
|  348   } |  371   } | 
|  349 } |  372 } | 
|  350  |  373  | 
 |  374 void TestingProfile::SetPrefService(PrefService* prefs) { | 
 |  375   DCHECK(!prefs_.get()); | 
 |  376   prefs_.reset(prefs); | 
 |  377 } | 
 |  378  | 
 |  379 void TestingProfile::CreateTestingPrefService() { | 
 |  380   DCHECK(!prefs_.get()); | 
 |  381   testing_prefs_ = new TestingPrefService(); | 
 |  382   prefs_.reset(testing_prefs_); | 
 |  383   Profile::RegisterUserPrefs(prefs_.get()); | 
 |  384   browser::RegisterAllPrefs(prefs_.get(), prefs_.get()); | 
 |  385 } | 
 |  386  | 
|  351 PrefService* TestingProfile::GetPrefs() { |  387 PrefService* TestingProfile::GetPrefs() { | 
|  352   if (!prefs_.get()) { |  388   if (!prefs_.get()) { | 
|  353     prefs_.reset(new TestingPrefService()); |  389     CreateTestingPrefService(); | 
|  354     Profile::RegisterUserPrefs(prefs_.get()); |  | 
|  355     browser::RegisterAllPrefs(prefs_.get(), prefs_.get()); |  | 
|  356   } |  390   } | 
|  357   return prefs_.get(); |  391   return prefs_.get(); | 
|  358 } |  392 } | 
|  359  |  393  | 
|  360 history::TopSites* TestingProfile::GetTopSites() { |  394 history::TopSites* TestingProfile::GetTopSites() { | 
|  361   if (!top_sites_.get()) { |  395   if (!top_sites_.get()) { | 
|  362     top_sites_ = new history::TopSites(this); |  396     top_sites_ = new history::TopSites(this); | 
|  363     FilePath file_name = temp_dir_.path().AppendASCII("TopSites.db"); |  397     FilePath file_name = temp_dir_.path().AppendASCII("TopSites.db"); | 
|  364     top_sites_->Init(file_name); |  398     top_sites_->Init(file_name); | 
|  365   } |  399   } | 
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  467   } |  501   } | 
|  468   return profile_sync_service_.get(); |  502   return profile_sync_service_.get(); | 
|  469 } |  503 } | 
|  470  |  504  | 
|  471 void TestingProfile::DestroyWebDataService() { |  505 void TestingProfile::DestroyWebDataService() { | 
|  472   if (!web_data_service_.get()) |  506   if (!web_data_service_.get()) | 
|  473     return; |  507     return; | 
|  474  |  508  | 
|  475   web_data_service_->Shutdown(); |  509   web_data_service_->Shutdown(); | 
|  476 } |  510 } | 
| OLD | NEW |