| 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/browser/profile_impl.h" | 5 #include "chrome/browser/profile_impl.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/histogram.h" | 12 #include "base/histogram.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "chrome/browser/appcache/chrome_appcache_service.h" | 17 #include "chrome/browser/appcache/chrome_appcache_service.h" |
| 18 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 18 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 19 #include "chrome/browser/autofill/personal_data_manager.h" | 19 #include "chrome/browser/autofill/personal_data_manager.h" |
| 20 #include "chrome/browser/background_contents_service.h" | 20 #include "chrome/browser/background_contents_service.h" |
| 21 #include "chrome/browser/background_mode_manager.h" | 21 #include "chrome/browser/background_mode_manager.h" |
| 22 #include "chrome/browser/bookmarks/bookmark_model.h" | 22 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 23 #include "chrome/browser/browser_list.h" | 23 #include "chrome/browser/browser_list.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chrome_blob_storage_context.h" | 25 #include "chrome/browser/chrome_blob_storage_context.h" |
| 26 #include "chrome/browser/chrome_thread.h" | 26 #include "chrome/browser/chrome_thread.h" |
| 27 #include "chrome/browser/dom_ui/ntp_resource_cache.h" | 27 #include "chrome/browser/dom_ui/ntp_resource_cache.h" |
| 28 #include "chrome/browser/download/download_manager.h" | 28 #include "chrome/browser/download/download_manager.h" |
| 29 #include "chrome/browser/extensions/default_apps.h" |
| 29 #include "chrome/browser/extensions/extension_devtools_manager.h" | 30 #include "chrome/browser/extensions/extension_devtools_manager.h" |
| 30 #include "chrome/browser/extensions/extension_error_reporter.h" | 31 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 31 #include "chrome/browser/extensions/extension_info_map.h" | 32 #include "chrome/browser/extensions/extension_info_map.h" |
| 32 #include "chrome/browser/extensions/extension_message_service.h" | 33 #include "chrome/browser/extensions/extension_message_service.h" |
| 33 #include "chrome/browser/extensions/extension_process_manager.h" | 34 #include "chrome/browser/extensions/extension_process_manager.h" |
| 34 #include "chrome/browser/extensions/extensions_service.h" | 35 #include "chrome/browser/extensions/extensions_service.h" |
| 35 #include "chrome/browser/extensions/user_script_master.h" | 36 #include "chrome/browser/extensions/user_script_master.h" |
| 36 #include "chrome/browser/favicon_service.h" | 37 #include "chrome/browser/favicon_service.h" |
| 37 #include "chrome/browser/file_system/file_system_host_context.h" | 38 #include "chrome/browser/file_system/file_system_host_context.h" |
| 38 #include "chrome/browser/find_bar_state.h" | 39 #include "chrome/browser/find_bar_state.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 162 |
| 162 FilePath GetMediaCachePath(const FilePath& base) { | 163 FilePath GetMediaCachePath(const FilePath& base) { |
| 163 return base.Append(chrome::kMediaCacheDirname); | 164 return base.Append(chrome::kMediaCacheDirname); |
| 164 } | 165 } |
| 165 | 166 |
| 166 bool HasACacheSubdir(const FilePath &dir) { | 167 bool HasACacheSubdir(const FilePath &dir) { |
| 167 return file_util::PathExists(GetCachePath(dir)) || | 168 return file_util::PathExists(GetCachePath(dir)) || |
| 168 file_util::PathExists(GetMediaCachePath(dir)); | 169 file_util::PathExists(GetMediaCachePath(dir)); |
| 169 } | 170 } |
| 170 | 171 |
| 171 // Returns true if the default apps should be loaded (so that the app panel is | |
| 172 // not empty). | |
| 173 bool IncludeDefaultApps() { | |
| 174 #if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD) | |
| 175 return true; | |
| 176 #endif | |
| 177 return false; | |
| 178 } | |
| 179 | |
| 180 // Simple task to log the size of the current profile. | 172 // Simple task to log the size of the current profile. |
| 181 class ProfileSizeTask : public Task { | 173 class ProfileSizeTask : public Task { |
| 182 public: | 174 public: |
| 183 explicit ProfileSizeTask(const FilePath& path) : path_(path) {} | 175 explicit ProfileSizeTask(const FilePath& path) : path_(path) {} |
| 184 virtual ~ProfileSizeTask() {} | 176 virtual ~ProfileSizeTask() {} |
| 185 | 177 |
| 186 virtual void Run(); | 178 virtual void Run(); |
| 187 private: | 179 private: |
| 188 FilePath path_; | 180 FilePath path_; |
| 189 }; | 181 }; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } // namespace | 225 } // namespace |
| 234 | 226 |
| 235 // static | 227 // static |
| 236 Profile* Profile::CreateProfile(const FilePath& path) { | 228 Profile* Profile::CreateProfile(const FilePath& path) { |
| 237 return new ProfileImpl(path); | 229 return new ProfileImpl(path); |
| 238 } | 230 } |
| 239 | 231 |
| 240 // static | 232 // static |
| 241 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { | 233 void ProfileImpl::RegisterUserPrefs(PrefService* prefs) { |
| 242 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, false); | 234 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, false); |
| 235 DefaultApps::RegisterUserPrefs(prefs); |
| 243 } | 236 } |
| 244 | 237 |
| 245 ProfileImpl::ProfileImpl(const FilePath& path) | 238 ProfileImpl::ProfileImpl(const FilePath& path) |
| 246 : path_(path), | 239 : path_(path), |
| 247 visited_link_event_listener_(new VisitedLinkEventListener()), | 240 visited_link_event_listener_(new VisitedLinkEventListener()), |
| 248 extension_devtools_manager_(NULL), | 241 extension_devtools_manager_(NULL), |
| 249 request_context_(NULL), | 242 request_context_(NULL), |
| 250 media_request_context_(NULL), | 243 media_request_context_(NULL), |
| 251 extensions_request_context_(NULL), | 244 extensions_request_context_(NULL), |
| 252 host_content_settings_map_(NULL), | 245 host_content_settings_map_(NULL), |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 // TODO(aa): We should just remove this functionality, | 361 // TODO(aa): We should just remove this functionality, |
| 369 // since it isn't used anymore. | 362 // since it isn't used anymore. |
| 370 user_script_master_ = new UserScriptMaster(script_dir, this); | 363 user_script_master_ = new UserScriptMaster(script_dir, this); |
| 371 | 364 |
| 372 extensions_service_ = new ExtensionsService( | 365 extensions_service_ = new ExtensionsService( |
| 373 this, | 366 this, |
| 374 CommandLine::ForCurrentProcess(), | 367 CommandLine::ForCurrentProcess(), |
| 375 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName), | 368 GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName), |
| 376 true); | 369 true); |
| 377 | 370 |
| 371 RegisterComponentExtensions(); |
| 372 extensions_service_->Init(); |
| 373 InstallDefaultApps(); |
| 374 |
| 375 // Load any extensions specified with --load-extension. |
| 376 if (command_line->HasSwitch(switches::kLoadExtension)) { |
| 377 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension); |
| 378 extensions_service_->LoadExtension(path); |
| 379 } |
| 380 } |
| 381 |
| 382 void ProfileImpl::RegisterComponentExtensions() { |
| 378 // Register the component extensions. | 383 // Register the component extensions. |
| 379 typedef std::list<std::pair<std::string, int> > ComponentExtensionList; | 384 typedef std::list<std::pair<std::string, int> > ComponentExtensionList; |
| 380 ComponentExtensionList component_extensions; | 385 ComponentExtensionList component_extensions; |
| 381 | 386 |
| 382 // Bookmark manager. | 387 // Bookmark manager. |
| 383 component_extensions.push_back( | 388 component_extensions.push_back( |
| 384 std::make_pair("bookmark_manager", IDR_BOOKMARKS_MANIFEST)); | 389 std::make_pair("bookmark_manager", IDR_BOOKMARKS_MANIFEST)); |
| 385 | 390 |
| 386 #if defined(TOUCH_UI) | 391 #if defined(TOUCH_UI) |
| 387 component_extensions.push_back( | 392 component_extensions.push_back( |
| 388 std::make_pair("keyboard", IDR_KEYBOARD_MANIFEST)); | 393 std::make_pair("keyboard", IDR_KEYBOARD_MANIFEST)); |
| 389 #endif | 394 #endif |
| 390 | 395 |
| 391 // Web Store. | 396 // Web Store. |
| 392 component_extensions.push_back( | 397 component_extensions.push_back( |
| 393 std::make_pair("web_store", IDR_WEBSTORE_MANIFEST)); | 398 std::make_pair("web_store", IDR_WEBSTORE_MANIFEST)); |
| 394 | 399 |
| 395 // Some sample apps to make our lives easier while we are developing extension | |
| 396 // apps. This way we don't have to constantly install these over and over. | |
| 397 if (Extension::AppsAreEnabled() && IncludeDefaultApps()) { | |
| 398 component_extensions.push_back( | |
| 399 std::make_pair("gmail_app", IDR_GMAIL_APP_MANIFEST)); | |
| 400 component_extensions.push_back( | |
| 401 std::make_pair("calendar_app", IDR_CALENDAR_APP_MANIFEST)); | |
| 402 component_extensions.push_back( | |
| 403 std::make_pair("docs_app", IDR_DOCS_APP_MANIFEST)); | |
| 404 } | |
| 405 | |
| 406 #if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD) | 400 #if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD) |
| 407 if (Extension::AppsAreEnabled()) { | 401 component_extensions.push_back( |
| 408 component_extensions.push_back( | 402 std::make_pair("chat_manager", IDR_TALK_APP_MANIFEST)); |
| 409 std::make_pair("chat_manager", IDR_TALK_APP_MANIFEST)); | |
| 410 } | |
| 411 #endif | 403 #endif |
| 412 | 404 |
| 413 for (ComponentExtensionList::iterator iter = component_extensions.begin(); | 405 for (ComponentExtensionList::iterator iter = component_extensions.begin(); |
| 414 iter != component_extensions.end(); ++iter) { | 406 iter != component_extensions.end(); ++iter) { |
| 415 FilePath path; | 407 FilePath path; |
| 416 if (PathService::Get(chrome::DIR_RESOURCES, &path)) { | 408 if (PathService::Get(chrome::DIR_RESOURCES, &path)) { |
| 417 path = path.AppendASCII(iter->first); | 409 path = path.AppendASCII(iter->first); |
| 418 } else { | 410 } else { |
| 419 NOTREACHED(); | 411 NOTREACHED(); |
| 420 } | 412 } |
| 421 | 413 |
| 422 std::string manifest = | 414 std::string manifest = |
| 423 ResourceBundle::GetSharedInstance().GetRawDataResource( | 415 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 424 iter->second).as_string(); | 416 iter->second).as_string(); |
| 425 extensions_service_->register_component_extension( | 417 extensions_service_->register_component_extension( |
| 426 ExtensionsService::ComponentExtensionInfo(manifest, path)); | 418 ExtensionsService::ComponentExtensionInfo(manifest, path)); |
| 427 } | 419 } |
| 420 } |
| 428 | 421 |
| 429 extensions_service_->Init(); | 422 void ProfileImpl::InstallDefaultApps() { |
| 423 #if !defined(OS_CHROMEOS) |
| 424 // On desktop Chrome, we don't have default apps on by, err, default yet. |
| 425 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 426 switches::kEnableDefaultApps)) { |
| 427 return; |
| 428 } |
| 429 #endif |
| 430 | 430 |
| 431 // Load any extensions specified with --load-extension. | 431 // The web store only supports en-US at the moment, so we don't install |
| 432 if (command_line->HasSwitch(switches::kLoadExtension)) { | 432 // default apps in other locales. |
| 433 FilePath path = command_line->GetSwitchValuePath(switches::kLoadExtension); | 433 if (g_browser_process->GetApplicationLocale() != "en-US") |
| 434 extensions_service_->LoadExtension(path); | 434 return; |
| 435 |
| 436 ExtensionsService* extensions_service = GetExtensionsService(); |
| 437 const ExtensionIdSet* app_ids = |
| 438 extensions_service->default_apps()->GetAppsToInstall(); |
| 439 if (!app_ids) |
| 440 return; |
| 441 |
| 442 for (ExtensionIdSet::const_iterator iter = app_ids->begin(); |
| 443 iter != app_ids->end(); ++iter) { |
| 444 extensions_service->AddPendingExtensionFromDefaultAppList(*iter); |
| 435 } | 445 } |
| 436 } | 446 } |
| 437 | 447 |
| 438 void ProfileImpl::InitWebResources() { | 448 void ProfileImpl::InitWebResources() { |
| 439 if (web_resource_service_) | 449 if (web_resource_service_) |
| 440 return; | 450 return; |
| 441 | 451 |
| 442 web_resource_service_ = new WebResourceService(this); | 452 web_resource_service_ = new WebResourceService(this); |
| 443 web_resource_service_->StartAfterDelay(); | 453 web_resource_service_->StartAfterDelay(); |
| 444 } | 454 } |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 #if defined(OS_CHROMEOS) | 1274 #if defined(OS_CHROMEOS) |
| 1265 chromeos::ProxyConfigServiceImpl* | 1275 chromeos::ProxyConfigServiceImpl* |
| 1266 ProfileImpl::GetChromeOSProxyConfigServiceImpl() { | 1276 ProfileImpl::GetChromeOSProxyConfigServiceImpl() { |
| 1267 if (!chromeos_proxy_config_service_impl_) { | 1277 if (!chromeos_proxy_config_service_impl_) { |
| 1268 chromeos_proxy_config_service_impl_ = | 1278 chromeos_proxy_config_service_impl_ = |
| 1269 new chromeos::ProxyConfigServiceImpl(); | 1279 new chromeos::ProxyConfigServiceImpl(); |
| 1270 } | 1280 } |
| 1271 return chromeos_proxy_config_service_impl_; | 1281 return chromeos_proxy_config_service_impl_; |
| 1272 } | 1282 } |
| 1273 #endif // defined(OS_CHROMEOS) | 1283 #endif // defined(OS_CHROMEOS) |
| OLD | NEW |