Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: chrome/browser/profiles/profile_impl.cc

Issue 8417012: Refactor loading out of ExtensionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: finally Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/profiles/profile_impl.h ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/browser/profiles/profile_impl.h" 5 #include "chrome/browser/profiles/profile_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/bookmarks/bookmark_model.h" 22 #include "chrome/browser/bookmarks/bookmark_model.h"
23 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/browsing_data_remover.h" 24 #include "chrome/browser/browsing_data_remover.h"
25 #include "chrome/browser/chrome_plugin_service_filter.h" 25 #include "chrome/browser/chrome_plugin_service_filter.h"
26 #include "chrome/browser/content_settings/cookie_settings.h" 26 #include "chrome/browser/content_settings/cookie_settings.h"
27 #include "chrome/browser/content_settings/host_content_settings_map.h" 27 #include "chrome/browser/content_settings/host_content_settings_map.h"
28 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 28 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
29 #include "chrome/browser/defaults.h" 29 #include "chrome/browser/defaults.h"
30 #include "chrome/browser/download/download_service.h" 30 #include "chrome/browser/download/download_service.h"
31 #include "chrome/browser/download/download_service_factory.h" 31 #include "chrome/browser/download/download_service_factory.h"
32 #include "chrome/browser/extensions/component_loader.h"
32 #include "chrome/browser/extensions/extension_devtools_manager.h" 33 #include "chrome/browser/extensions/extension_devtools_manager.h"
33 #include "chrome/browser/extensions/extension_error_reporter.h" 34 #include "chrome/browser/extensions/extension_error_reporter.h"
34 #include "chrome/browser/extensions/extension_event_router.h" 35 #include "chrome/browser/extensions/extension_event_router.h"
35 #include "chrome/browser/extensions/extension_info_map.h" 36 #include "chrome/browser/extensions/extension_info_map.h"
36 #include "chrome/browser/extensions/extension_message_service.h" 37 #include "chrome/browser/extensions/extension_message_service.h"
37 #include "chrome/browser/extensions/extension_navigation_observer.h" 38 #include "chrome/browser/extensions/extension_navigation_observer.h"
38 #include "chrome/browser/extensions/extension_pref_store.h" 39 #include "chrome/browser/extensions/extension_pref_store.h"
39 #include "chrome/browser/extensions/extension_process_manager.h" 40 #include "chrome/browser/extensions/extension_process_manager.h"
40 #include "chrome/browser/extensions/extension_service.h" 41 #include "chrome/browser/extensions/extension_service.h"
41 #include "chrome/browser/extensions/extension_settings_backend.h" 42 #include "chrome/browser/extensions/extension_settings_backend.h"
42 #include "chrome/browser/extensions/extension_special_storage_policy.h" 43 #include "chrome/browser/extensions/extension_special_storage_policy.h"
44 #include "chrome/browser/extensions/unpacked_installer.h"
43 #include "chrome/browser/extensions/user_script_master.h" 45 #include "chrome/browser/extensions/user_script_master.h"
44 #include "chrome/browser/favicon/favicon_service.h" 46 #include "chrome/browser/favicon/favicon_service.h"
45 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" 47 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
46 #include "chrome/browser/history/history.h" 48 #include "chrome/browser/history/history.h"
47 #include "chrome/browser/history/shortcuts_backend.h" 49 #include "chrome/browser/history/shortcuts_backend.h"
48 #include "chrome/browser/history/top_sites.h" 50 #include "chrome/browser/history/top_sites.h"
49 #include "chrome/browser/instant/instant_controller.h" 51 #include "chrome/browser/instant/instant_controller.h"
50 #include "chrome/browser/metrics/metrics_service.h" 52 #include "chrome/browser/metrics/metrics_service.h"
51 #include "chrome/browser/net/chrome_url_request_context.h" 53 #include "chrome/browser/net/chrome_url_request_context.h"
52 #include "chrome/browser/net/gaia/token_service.h" 54 #include "chrome/browser/net/gaia/token_service.h"
(...skipping 26 matching lines...) Expand all
79 #include "chrome/browser/ui/find_bar/find_bar_state.h" 81 #include "chrome/browser/ui/find_bar/find_bar_state.h"
80 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 82 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
81 #include "chrome/browser/ui/webui/extension_icon_source.h" 83 #include "chrome/browser/ui/webui/extension_icon_source.h"
82 #include "chrome/browser/user_style_sheet_watcher.h" 84 #include "chrome/browser/user_style_sheet_watcher.h"
83 #include "chrome/browser/visitedlink/visitedlink_event_listener.h" 85 #include "chrome/browser/visitedlink/visitedlink_event_listener.h"
84 #include "chrome/browser/visitedlink/visitedlink_master.h" 86 #include "chrome/browser/visitedlink/visitedlink_master.h"
85 #include "chrome/browser/web_resource/promo_resource_service.h" 87 #include "chrome/browser/web_resource/promo_resource_service.h"
86 #include "chrome/browser/webdata/web_data_service.h" 88 #include "chrome/browser/webdata/web_data_service.h"
87 #include "chrome/common/chrome_constants.h" 89 #include "chrome/common/chrome_constants.h"
88 #include "chrome/common/chrome_notification_types.h" 90 #include "chrome/common/chrome_notification_types.h"
89 #include "chrome/common/chrome_paths.h"
90 #include "chrome/common/chrome_paths_internal.h" 91 #include "chrome/common/chrome_paths_internal.h"
91 #include "chrome/common/chrome_switches.h" 92 #include "chrome/common/chrome_switches.h"
92 #include "chrome/common/extensions/extension_permission_set.h" 93 #include "chrome/common/extensions/extension_permission_set.h"
93 #include "chrome/common/json_pref_store.h" 94 #include "chrome/common/json_pref_store.h"
94 #include "chrome/common/pref_names.h" 95 #include "chrome/common/pref_names.h"
95 #include "chrome/common/render_messages.h" 96 #include "chrome/common/render_messages.h"
96 #include "chrome/common/spellcheck_messages.h" 97 #include "chrome/common/spellcheck_messages.h"
97 #include "chrome/common/url_constants.h" 98 #include "chrome/common/url_constants.h"
98 #include "content/browser/appcache/chrome_appcache_service.h" 99 #include "content/browser/appcache/chrome_appcache_service.h"
99 #include "content/browser/chrome_blob_storage_context.h" 100 #include "content/browser/chrome_blob_storage_context.h"
100 #include "content/browser/file_system/browser_file_system_helper.h" 101 #include "content/browser/file_system/browser_file_system_helper.h"
101 #include "content/browser/host_zoom_map.h" 102 #include "content/browser/host_zoom_map.h"
102 #include "content/browser/in_process_webkit/webkit_context.h" 103 #include "content/browser/in_process_webkit/webkit_context.h"
103 #include "content/browser/renderer_host/render_process_host.h" 104 #include "content/browser/renderer_host/render_process_host.h"
104 #include "content/browser/speech/speech_input_manager.h" 105 #include "content/browser/speech/speech_input_manager.h"
105 #include "content/browser/ssl/ssl_host_state.h" 106 #include "content/browser/ssl/ssl_host_state.h"
106 #include "content/browser/user_metrics.h" 107 #include "content/browser/user_metrics.h"
107 #include "content/public/browser/browser_thread.h" 108 #include "content/public/browser/browser_thread.h"
108 #include "content/public/browser/notification_service.h" 109 #include "content/public/browser/notification_service.h"
109 #include "grit/browser_resources.h"
110 #include "grit/locale_settings.h" 110 #include "grit/locale_settings.h"
111 #include "net/base/transport_security_state.h" 111 #include "net/base/transport_security_state.h"
112 #include "net/http/http_server_properties.h" 112 #include "net/http/http_server_properties.h"
113 #include "ui/base/resource/resource_bundle.h"
114 #include "webkit/database/database_tracker.h" 113 #include "webkit/database/database_tracker.h"
115 #include "webkit/quota/quota_manager.h" 114 #include "webkit/quota/quota_manager.h"
116 115
117 #if defined(OS_WIN) 116 #if defined(OS_WIN)
118 #include "chrome/browser/instant/promo_counter.h" 117 #include "chrome/browser/instant/promo_counter.h"
119 #include "chrome/browser/password_manager/password_store_win.h" 118 #include "chrome/browser/password_manager/password_store_win.h"
120 #include "chrome/installer/util/install_util.h" 119 #include "chrome/installer/util/install_util.h"
121 #elif defined(OS_MACOSX) 120 #elif defined(OS_MACOSX)
122 #include "chrome/browser/keychain_mac.h" 121 #include "chrome/browser/keychain_mac.h"
123 #include "chrome/browser/mock_keychain_mac.h" 122 #include "chrome/browser/mock_keychain_mac.h"
(...skipping 26 matching lines...) Expand all
150 #if defined(OS_MACOSX) 149 #if defined(OS_MACOSX)
151 // Capacity for mock keychain used for testing. 150 // Capacity for mock keychain used for testing.
152 static const int kMockKeychainSize = 1000; 151 static const int kMockKeychainSize = 1000;
153 #endif 152 #endif
154 153
155 enum ContextType { 154 enum ContextType {
156 kNormalContext, 155 kNormalContext,
157 kMediaContext 156 kMediaContext
158 }; 157 };
159 158
160 typedef std::list<std::pair<FilePath::StringType, int> >
161 ComponentExtensionList;
162
163 // Helper method needed because PostTask cannot currently take a Callback 159 // Helper method needed because PostTask cannot currently take a Callback
164 // function with non-void return type. 160 // function with non-void return type.
165 // TODO(jhawkins): Remove once IgnoreReturn is fixed. 161 // TODO(jhawkins): Remove once IgnoreReturn is fixed.
166 void CreateDirectoryNoResult(const FilePath& path) { 162 void CreateDirectoryNoResult(const FilePath& path) {
167 file_util::CreateDirectory(path); 163 file_util::CreateDirectory(path);
168 } 164 }
169 165
170 #if defined(FILE_MANAGER_EXTENSION)
171 void AddFileManagerExtension(ComponentExtensionList* component_extensions) {
172 #ifndef NDEBUG
173 const CommandLine* command_line = CommandLine::ForCurrentProcess();
174 if (command_line->HasSwitch(switches::kFileManagerExtensionPath)) {
175 FilePath filemgr_extension_path =
176 command_line->GetSwitchValuePath(switches::kFileManagerExtensionPath);
177 component_extensions->push_back(std::make_pair(
178 filemgr_extension_path.value(),
179 IDR_FILEMANAGER_MANIFEST));
180 return;
181 }
182 #endif // NDEBUG
183 component_extensions->push_back(std::make_pair(
184 FILE_PATH_LITERAL("file_manager"),
185 IDR_FILEMANAGER_MANIFEST));
186 }
187 #endif // defined(FILE_MANAGER_EXTENSION)
188
189 // Gets the cache parameters from the command line. |type| is the type of 166 // Gets the cache parameters from the command line. |type| is the type of
190 // request context that we need, |cache_path| will be set to the user provided 167 // request context that we need, |cache_path| will be set to the user provided
191 // path, or will not be touched if there is not an argument. |max_size| will 168 // path, or will not be touched if there is not an argument. |max_size| will
192 // be the user provided value or zero by default. 169 // be the user provided value or zero by default.
193 void GetCacheParameters(ContextType type, FilePath* cache_path, 170 void GetCacheParameters(ContextType type, FilePath* cache_path,
194 int* max_size) { 171 int* max_size) {
195 DCHECK(cache_path); 172 DCHECK(cache_path);
196 DCHECK(max_size); 173 DCHECK(max_size);
197 174
198 // Override the cache location if specified by the user. 175 // Override the cache location if specified by the user.
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 autoupdate_enabled = !command_line->HasSwitch(switches::kGuestSession); 448 autoupdate_enabled = !command_line->HasSwitch(switches::kGuestSession);
472 #endif 449 #endif
473 extension_service_.reset(new ExtensionService( 450 extension_service_.reset(new ExtensionService(
474 this, 451 this,
475 CommandLine::ForCurrentProcess(), 452 CommandLine::ForCurrentProcess(),
476 GetPath().AppendASCII(ExtensionService::kInstallDirectoryName), 453 GetPath().AppendASCII(ExtensionService::kInstallDirectoryName),
477 extension_prefs_.get(), 454 extension_prefs_.get(),
478 autoupdate_enabled, 455 autoupdate_enabled,
479 extensions_enabled)); 456 extensions_enabled));
480 457
481 RegisterComponentExtensions(); 458 extension_service_->component_loader()->AddDefaultComponentExtensions();
482 extension_service_->Init(); 459 extension_service_->Init();
483 460
484 if (extensions_enabled) { 461 if (extensions_enabled) {
485 // Load any extensions specified with --load-extension. 462 // Load any extensions specified with --load-extension.
463 // TODO(yoz): Seems like this should move into ExtensionService::Init.
486 if (command_line->HasSwitch(switches::kLoadExtension)) { 464 if (command_line->HasSwitch(switches::kLoadExtension)) {
487 FilePath path = command_line->GetSwitchValuePath( 465 FilePath path = command_line->GetSwitchValuePath(
488 switches::kLoadExtension); 466 switches::kLoadExtension);
489 extension_service_->LoadExtensionFromCommandLine(path); 467 extensions::UnpackedInstaller::Create(extension_service_.get())->
468 LoadFromCommandLine(path);
490 } 469 }
491 } 470 }
492 471
493 // Make the chrome://extension-icon/ resource available. 472 // Make the chrome://extension-icon/ resource available.
494 GetChromeURLDataManager()->AddDataSource(new ExtensionIconSource(this)); 473 GetChromeURLDataManager()->AddDataSource(new ExtensionIconSource(this));
495 474
496 // Initialize extension event routers. Note that on Chrome OS, this will 475 // Initialize extension event routers. Note that on Chrome OS, this will
497 // not succeed if the user has not logged in yet, in which case the 476 // not succeed if the user has not logged in yet, in which case the
498 // event routers are initialized in LoginUtilsImpl::CompleteLogin instead. 477 // event routers are initialized in LoginUtilsImpl::CompleteLogin instead.
499 // The InitEventRouters call used to be in BrowserMain, because when bookmark 478 // The InitEventRouters call used to be in BrowserMain, because when bookmark
500 // import happened on first run, the bookmark bar was not being correctly 479 // import happened on first run, the bookmark bar was not being correctly
501 // initialized (see issue 40144). Now that bookmarks aren't imported and 480 // initialized (see issue 40144). Now that bookmarks aren't imported and
502 // the event routers need to be initialized for every profile individually, 481 // the event routers need to be initialized for every profile individually,
503 // initialize them with the extension service. 482 // initialize them with the extension service.
504 // If this profile is being created as part of the import process, never 483 // If this profile is being created as part of the import process, never
505 // initialize the event routers. If import is going to run in a separate 484 // initialize the event routers. If import is going to run in a separate
506 // process (the profile itself is on the main process), wait for import to 485 // process (the profile itself is on the main process), wait for import to
507 // finish before initializing the routers. 486 // finish before initializing the routers.
508 if (!command_line->HasSwitch(switches::kImport) && 487 if (!command_line->HasSwitch(switches::kImport) &&
509 !command_line->HasSwitch(switches::kImportFromFile)) { 488 !command_line->HasSwitch(switches::kImportFromFile)) {
510 if (g_browser_process->profile_manager()->will_import()) { 489 if (g_browser_process->profile_manager()->will_import()) {
511 extension_service_->InitEventRoutersAfterImport(); 490 extension_service_->InitEventRoutersAfterImport();
512 } else { 491 } else {
513 extension_service_->InitEventRouters(); 492 extension_service_->InitEventRouters();
514 } 493 }
515 } 494 }
516 } 495 }
517 496
518 void ProfileImpl::RegisterComponentExtensions() {
519 // Register the component extensions.
520 //
521 // Component extension manifest must contain a 'key' property with a unique
522 // public key, serialized in base64. You can create a suitable value with the
523 // following commands on a unixy system:
524 //
525 // ssh-keygen -t rsa -b 1024 -N '' -f /tmp/key.pem
526 // openssl rsa -pubout -outform DER < /tmp/key.pem 2>/dev/null | base64 -w 0
527 typedef std::list<std::pair<FilePath::StringType, int> >
528 ComponentExtensionList;
529 ComponentExtensionList component_extensions;
530
531 // Bookmark manager.
532 component_extensions.push_back(std::make_pair(
533 FILE_PATH_LITERAL("bookmark_manager"),
534 IDR_BOOKMARKS_MANIFEST));
535
536 #if defined(FILE_MANAGER_EXTENSION)
537 AddFileManagerExtension(&component_extensions);
538 #endif
539
540 #if defined(USE_VIRTUAL_KEYBOARD)
541 component_extensions.push_back(std::make_pair(
542 FILE_PATH_LITERAL("keyboard"),
543 IDR_KEYBOARD_MANIFEST));
544 #endif
545
546 #if defined(OS_CHROMEOS)
547 component_extensions.push_back(std::make_pair(
548 FILE_PATH_LITERAL("/usr/share/chromeos-assets/mobile"),
549 IDR_MOBILE_MANIFEST));
550
551 const CommandLine* command_line = CommandLine::ForCurrentProcess();
552 if (command_line->HasSwitch(switches::kAuthExtensionPath)) {
553 FilePath auth_extension_path =
554 command_line->GetSwitchValuePath(switches::kAuthExtensionPath);
555 component_extensions.push_back(std::make_pair(
556 auth_extension_path.value(),
557 IDR_GAIA_TEST_AUTH_MANIFEST));
558 } else {
559 component_extensions.push_back(std::make_pair(
560 FILE_PATH_LITERAL("/usr/share/chromeos-assets/gaia_auth"),
561 IDR_GAIA_AUTH_MANIFEST));
562 }
563
564 #if defined(OFFICIAL_BUILD)
565 if (browser_defaults::enable_help_app) {
566 component_extensions.push_back(std::make_pair(
567 FILE_PATH_LITERAL("/usr/share/chromeos-assets/helpapp"),
568 IDR_HELP_MANIFEST));
569 }
570 #endif
571 #endif
572
573 // Web Store.
574 component_extensions.push_back(std::make_pair(
575 FILE_PATH_LITERAL("web_store"),
576 IDR_WEBSTORE_MANIFEST));
577
578 #if !defined(OS_CHROMEOS)
579 // Cloud Print component app. Not required on Chrome OS.
580 component_extensions.push_back(std::make_pair(
581 FILE_PATH_LITERAL("cloud_print"),
582 IDR_CLOUDPRINT_MANIFEST));
583 #endif // !defined(OS_CHROMEOS)
584
585 for (ComponentExtensionList::iterator iter = component_extensions.begin();
586 iter != component_extensions.end(); ++iter) {
587 FilePath path(iter->first);
588 if (!path.IsAbsolute()) {
589 if (PathService::Get(chrome::DIR_RESOURCES, &path)) {
590 path = path.Append(iter->first);
591 } else {
592 NOTREACHED();
593 }
594 }
595
596 std::string manifest =
597 ResourceBundle::GetSharedInstance().GetRawDataResource(
598 iter->second).as_string();
599 extension_service_->register_component_extension(
600 ExtensionService::ComponentExtensionInfo(manifest, path));
601 }
602
603 #if defined(OS_CHROMEOS)
604 // Register access extensions only if accessibility is enabled.
605 if (g_browser_process->local_state()->
606 GetBoolean(prefs::kAccessibilityEnabled)) {
607 FilePath path = FilePath(extension_misc::kAccessExtensionPath)
608 .AppendASCII(extension_misc::kChromeVoxDirectoryName);
609 std::string manifest =
610 ResourceBundle::GetSharedInstance().GetRawDataResource(
611 IDR_CHROMEVOX_MANIFEST).as_string();
612 extension_service_->register_component_extension(
613 ExtensionService::ComponentExtensionInfo(manifest, path));
614 }
615 #endif
616 }
617
618 void ProfileImpl::InitPromoResources() { 497 void ProfileImpl::InitPromoResources() {
619 if (promo_resource_service_) 498 if (promo_resource_service_)
620 return; 499 return;
621 500
622 promo_resource_service_ = new PromoResourceService(this); 501 promo_resource_service_ = new PromoResourceService(this);
623 promo_resource_service_->StartAfterDelay(); 502 promo_resource_service_->StartAfterDelay();
624 } 503 }
625 504
626 void ProfileImpl::InitRegisteredProtocolHandlers() { 505 void ProfileImpl::InitRegisteredProtocolHandlers() {
627 if (protocol_handler_registry_) 506 if (protocol_handler_registry_)
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
1706 if (!home_page.is_valid()) 1585 if (!home_page.is_valid())
1707 return GURL(chrome::kChromeUINewTabURL); 1586 return GURL(chrome::kChromeUINewTabURL);
1708 return home_page; 1587 return home_page;
1709 } 1588 }
1710 1589
1711 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() { 1590 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() {
1712 if (!spellcheck_profile_.get()) 1591 if (!spellcheck_profile_.get())
1713 spellcheck_profile_.reset(new SpellCheckProfile(path_)); 1592 spellcheck_profile_.reset(new SpellCheckProfile(path_));
1714 return spellcheck_profile_.get(); 1593 return spellcheck_profile_.get();
1715 } 1594 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_impl.h ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698