| 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" | 
|   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/content_settings/host_content_settings_map.h" |   17 #include "chrome/browser/content_settings/host_content_settings_map.h" | 
|   18 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |   18 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 
|   19 #include "chrome/browser/extensions/extension_pref_value_map.h" |   19 #include "chrome/browser/extensions/extension_pref_value_map.h" | 
|   20 #include "chrome/browser/extensions/extension_service.h" |   20 #include "chrome/browser/extensions/extension_service.h" | 
|   21 #include "chrome/browser/extensions/extension_special_storage_policy.h" |   21 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 
|   22 #include "chrome/browser/favicon_service.h" |   22 #include "chrome/browser/favicon_service.h" | 
|   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/notifications/desktop_notification_service_factory.h" |  | 
|   31 #include "chrome/browser/prefs/browser_prefs.h" |   30 #include "chrome/browser/prefs/browser_prefs.h" | 
|   32 #include "chrome/browser/prefs/testing_pref_store.h" |   31 #include "chrome/browser/prefs/testing_pref_store.h" | 
|   33 #include "chrome/browser/prerender/prerender_manager.h" |   32 #include "chrome/browser/prerender/prerender_manager.h" | 
|   34 #include "chrome/browser/profiles/profile_dependency_manager.h" |   33 #include "chrome/browser/profiles/profile_dependency_manager.h" | 
|   35 #include "chrome/browser/search_engines/template_url_fetcher.h" |   34 #include "chrome/browser/search_engines/template_url_fetcher.h" | 
|   36 #include "chrome/browser/search_engines/template_url_model.h" |   35 #include "chrome/browser/search_engines/template_url_model.h" | 
|   37 #include "chrome/browser/sessions/session_service.h" |   36 #include "chrome/browser/sessions/session_service.h" | 
|   38 #include "chrome/browser/sync/profile_sync_service_mock.h" |   37 #include "chrome/browser/sync/profile_sync_service_mock.h" | 
|   39 #include "chrome/browser/ui/find_bar/find_bar_state.h" |   38 #include "chrome/browser/ui/find_bar/find_bar_state.h" | 
|   40 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |   39 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  135     return context_.get(); |  134     return context_.get(); | 
|  136   } |  135   } | 
|  137   virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { |  136   virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { | 
|  138     return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |  137     return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 
|  139   } |  138   } | 
|  140  |  139  | 
|  141  private: |  140  private: | 
|  142   scoped_refptr<net::URLRequestContext> context_; |  141   scoped_refptr<net::URLRequestContext> context_; | 
|  143 }; |  142 }; | 
|  144  |  143  | 
|  145 ProfileKeyedService* CreateTestDesktopNotificationService(Profile* profile) { |  | 
|  146   return new DesktopNotificationService(profile, NULL); |  | 
|  147 } |  | 
|  148  |  | 
|  149 }  // namespace |  144 }  // namespace | 
|  150  |  145  | 
|  151 TestingProfile::TestingProfile() |  146 TestingProfile::TestingProfile() | 
|  152     : start_time_(Time::Now()), |  147     : start_time_(Time::Now()), | 
|  153       testing_prefs_(NULL), |  148       testing_prefs_(NULL), | 
|  154       incognito_(false), |  149       incognito_(false), | 
|  155       last_session_exited_cleanly_(true), |  150       last_session_exited_cleanly_(true), | 
|  156       profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { |  151       profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { | 
|  157   if (!temp_dir_.CreateUniqueTempDir()) { |  152   if (!temp_dir_.CreateUniqueTempDir()) { | 
|  158     LOG(ERROR) << "Failed to create unique temporary directory."; |  153     LOG(ERROR) << "Failed to create unique temporary directory."; | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|  170     file_util::Delete(fallback_dir, true); |  165     file_util::Delete(fallback_dir, true); | 
|  171     file_util::CreateDirectory(fallback_dir); |  166     file_util::CreateDirectory(fallback_dir); | 
|  172     if (!temp_dir_.Set(fallback_dir)) { |  167     if (!temp_dir_.Set(fallback_dir)) { | 
|  173       // That shouldn't happen, but if it does, try to recover. |  168       // That shouldn't happen, but if it does, try to recover. | 
|  174       LOG(ERROR) << "Failed to use a fallback temporary directory."; |  169       LOG(ERROR) << "Failed to use a fallback temporary directory."; | 
|  175  |  170  | 
|  176       // We're screwed if this fails, see CHECK above. |  171       // We're screwed if this fails, see CHECK above. | 
|  177       CHECK(temp_dir_.Set(system_tmp_dir)); |  172       CHECK(temp_dir_.Set(system_tmp_dir)); | 
|  178     } |  173     } | 
|  179   } |  174   } | 
|  180  |  | 
|  181   // Install profile keyed service factory hooks for dummy/test services |  | 
|  182   DesktopNotificationServiceFactory::GetInstance()->set_test_factory( |  | 
|  183       &CreateTestDesktopNotificationService); |  | 
|  184   DesktopNotificationServiceFactory::GetInstance()->ForceAssociationBetween( |  | 
|  185       this, NULL); |  | 
|  186 } |  175 } | 
|  187  |  176  | 
|  188 TestingProfile::~TestingProfile() { |  177 TestingProfile::~TestingProfile() { | 
|  189   NotificationService::current()->Notify( |  178   NotificationService::current()->Notify( | 
|  190       NotificationType::PROFILE_DESTROYED, |  179       NotificationType::PROFILE_DESTROYED, | 
|  191       Source<Profile>(static_cast<Profile*>(this)), |  180       Source<Profile>(static_cast<Profile*>(this)), | 
|  192       NotificationService::NoDetails()); |  181       NotificationService::NoDetails()); | 
|  193  |  182  | 
|  194   profile_dependency_manager_->DestroyProfileServices(this); |  183   profile_dependency_manager_->DestroyProfileServices(this); | 
|  195  |  184  | 
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  366   return temp_dir_.path(); |  355   return temp_dir_.path(); | 
|  367 } |  356 } | 
|  368  |  357  | 
|  369 TestingPrefService* TestingProfile::GetTestingPrefService() { |  358 TestingPrefService* TestingProfile::GetTestingPrefService() { | 
|  370   if (!prefs_.get()) |  359   if (!prefs_.get()) | 
|  371     CreateTestingPrefService(); |  360     CreateTestingPrefService(); | 
|  372   DCHECK(testing_prefs_); |  361   DCHECK(testing_prefs_); | 
|  373   return testing_prefs_; |  362   return testing_prefs_; | 
|  374 } |  363 } | 
|  375  |  364  | 
 |  365 void TestingProfile::SetProfileDependencyManager( | 
 |  366     ProfileDependencyManager* manager) { | 
 |  367   profile_dependency_manager_ = manager; | 
 |  368 } | 
 |  369  | 
|  376 ProfileId TestingProfile::GetRuntimeId() { |  370 ProfileId TestingProfile::GetRuntimeId() { | 
|  377     return reinterpret_cast<ProfileId>(this); |  371     return reinterpret_cast<ProfileId>(this); | 
|  378   } |  372   } | 
|  379  |  373  | 
|  380 bool TestingProfile::IsOffTheRecord() { |  374 bool TestingProfile::IsOffTheRecord() { | 
|  381   return incognito_; |  375   return incognito_; | 
|  382 } |  376 } | 
|  383  |  377  | 
|  384 void TestingProfile::SetOffTheRecordProfile(Profile* profile) { |  378 void TestingProfile::SetOffTheRecordProfile(Profile* profile) { | 
|  385   incognito_profile_.reset(profile); |  379   incognito_profile_.reset(profile); | 
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  692 WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() { |  686 WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() { | 
|  693   return NULL; |  687   return NULL; | 
|  694 } |  688 } | 
|  695  |  689  | 
|  696 NTPResourceCache* TestingProfile::GetNTPResourceCache() { |  690 NTPResourceCache* TestingProfile::GetNTPResourceCache() { | 
|  697   if (!ntp_resource_cache_.get()) |  691   if (!ntp_resource_cache_.get()) | 
|  698     ntp_resource_cache_.reset(new NTPResourceCache(this)); |  692     ntp_resource_cache_.reset(new NTPResourceCache(this)); | 
|  699   return ntp_resource_cache_.get(); |  693   return ntp_resource_cache_.get(); | 
|  700 } |  694 } | 
|  701  |  695  | 
 |  696 DesktopNotificationService* TestingProfile::GetDesktopNotificationService() { | 
 |  697   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
 |  698   if (!desktop_notification_service_.get()) { | 
 |  699     desktop_notification_service_.reset(new DesktopNotificationService( | 
 |  700         this, NULL)); | 
 |  701   } | 
 |  702   return desktop_notification_service_.get(); | 
 |  703 } | 
 |  704  | 
|  702 BackgroundContentsService* |  705 BackgroundContentsService* | 
|  703 TestingProfile::GetBackgroundContentsService() const { |  706 TestingProfile::GetBackgroundContentsService() const { | 
|  704   return NULL; |  707   return NULL; | 
|  705 } |  708 } | 
|  706  |  709  | 
|  707 StatusTray* TestingProfile::GetStatusTray() { |  710 StatusTray* TestingProfile::GetStatusTray() { | 
|  708   return NULL; |  711   return NULL; | 
|  709 } |  712 } | 
|  710  |  713  | 
|  711 FilePath TestingProfile::last_selected_directory() { |  714 FilePath TestingProfile::last_selected_directory() { | 
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  805 } |  808 } | 
|  806  |  809  | 
|  807 DerivedTestingProfile::DerivedTestingProfile(Profile* profile) |  810 DerivedTestingProfile::DerivedTestingProfile(Profile* profile) | 
|  808     : original_profile_(profile) {} |  811     : original_profile_(profile) {} | 
|  809  |  812  | 
|  810 DerivedTestingProfile::~DerivedTestingProfile() {} |  813 DerivedTestingProfile::~DerivedTestingProfile() {} | 
|  811  |  814  | 
|  812 ProfileId DerivedTestingProfile::GetRuntimeId() { |  815 ProfileId DerivedTestingProfile::GetRuntimeId() { | 
|  813   return original_profile_->GetRuntimeId(); |  816   return original_profile_->GetRuntimeId(); | 
|  814 } |  817 } | 
| OLD | NEW |