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

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: 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
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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.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/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/path_service.h"
14 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
15 #include "base/string_util.h" 14 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
17 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 16 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
18 #include "chrome/browser/autofill/personal_data_manager.h" 17 #include "chrome/browser/autofill/personal_data_manager.h"
19 #include "chrome/browser/background/background_contents_service_factory.h" 18 #include "chrome/browser/background/background_contents_service_factory.h"
20 #include "chrome/browser/background/background_mode_manager.h" 19 #include "chrome/browser/background/background_mode_manager.h"
21 #include "chrome/browser/bookmarks/bookmark_model.h" 20 #include "chrome/browser/bookmarks/bookmark_model.h"
22 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/browsing_data_remover.h" 22 #include "chrome/browser/browsing_data_remover.h"
24 #include "chrome/browser/chrome_plugin_service_filter.h" 23 #include "chrome/browser/chrome_plugin_service_filter.h"
25 #include "chrome/browser/content_settings/host_content_settings_map.h" 24 #include "chrome/browser/content_settings/host_content_settings_map.h"
26 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 25 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
27 #include "chrome/browser/defaults.h" 26 #include "chrome/browser/defaults.h"
28 #include "chrome/browser/download/download_service.h" 27 #include "chrome/browser/download/download_service.h"
29 #include "chrome/browser/download/download_service_factory.h" 28 #include "chrome/browser/download/download_service_factory.h"
29 #include "chrome/browser/extensions/component_loader.h"
30 #include "chrome/browser/extensions/extension_devtools_manager.h" 30 #include "chrome/browser/extensions/extension_devtools_manager.h"
31 #include "chrome/browser/extensions/extension_error_reporter.h" 31 #include "chrome/browser/extensions/extension_error_reporter.h"
32 #include "chrome/browser/extensions/extension_event_router.h" 32 #include "chrome/browser/extensions/extension_event_router.h"
33 #include "chrome/browser/extensions/extension_info_map.h" 33 #include "chrome/browser/extensions/extension_info_map.h"
34 #include "chrome/browser/extensions/extension_message_service.h" 34 #include "chrome/browser/extensions/extension_message_service.h"
35 #include "chrome/browser/extensions/extension_navigation_observer.h" 35 #include "chrome/browser/extensions/extension_navigation_observer.h"
36 #include "chrome/browser/extensions/extension_pref_store.h" 36 #include "chrome/browser/extensions/extension_pref_store.h"
37 #include "chrome/browser/extensions/extension_process_manager.h" 37 #include "chrome/browser/extensions/extension_process_manager.h"
38 #include "chrome/browser/extensions/extension_service.h" 38 #include "chrome/browser/extensions/extension_service.h"
39 #include "chrome/browser/extensions/extension_settings_backend.h" 39 #include "chrome/browser/extensions/extension_settings_backend.h"
40 #include "chrome/browser/extensions/extension_special_storage_policy.h" 40 #include "chrome/browser/extensions/extension_special_storage_policy.h"
41 #include "chrome/browser/extensions/unpacked_installer.h"
41 #include "chrome/browser/extensions/user_script_master.h" 42 #include "chrome/browser/extensions/user_script_master.h"
42 #include "chrome/browser/favicon/favicon_service.h" 43 #include "chrome/browser/favicon/favicon_service.h"
43 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" 44 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
44 #include "chrome/browser/history/history.h" 45 #include "chrome/browser/history/history.h"
45 #include "chrome/browser/history/shortcuts_backend.h" 46 #include "chrome/browser/history/shortcuts_backend.h"
46 #include "chrome/browser/history/top_sites.h" 47 #include "chrome/browser/history/top_sites.h"
47 #include "chrome/browser/instant/instant_controller.h" 48 #include "chrome/browser/instant/instant_controller.h"
48 #include "chrome/browser/metrics/metrics_service.h" 49 #include "chrome/browser/metrics/metrics_service.h"
49 #include "chrome/browser/net/chrome_url_request_context.h" 50 #include "chrome/browser/net/chrome_url_request_context.h"
50 #include "chrome/browser/net/gaia/token_service.h" 51 #include "chrome/browser/net/gaia/token_service.h"
(...skipping 25 matching lines...) Expand all
76 #include "chrome/browser/ui/find_bar/find_bar_state.h" 77 #include "chrome/browser/ui/find_bar/find_bar_state.h"
77 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 78 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
78 #include "chrome/browser/ui/webui/extension_icon_source.h" 79 #include "chrome/browser/ui/webui/extension_icon_source.h"
79 #include "chrome/browser/user_style_sheet_watcher.h" 80 #include "chrome/browser/user_style_sheet_watcher.h"
80 #include "chrome/browser/visitedlink/visitedlink_event_listener.h" 81 #include "chrome/browser/visitedlink/visitedlink_event_listener.h"
81 #include "chrome/browser/visitedlink/visitedlink_master.h" 82 #include "chrome/browser/visitedlink/visitedlink_master.h"
82 #include "chrome/browser/web_resource/promo_resource_service.h" 83 #include "chrome/browser/web_resource/promo_resource_service.h"
83 #include "chrome/browser/webdata/web_data_service.h" 84 #include "chrome/browser/webdata/web_data_service.h"
84 #include "chrome/common/chrome_constants.h" 85 #include "chrome/common/chrome_constants.h"
85 #include "chrome/common/chrome_notification_types.h" 86 #include "chrome/common/chrome_notification_types.h"
86 #include "chrome/common/chrome_paths.h"
87 #include "chrome/common/chrome_paths_internal.h" 87 #include "chrome/common/chrome_paths_internal.h"
88 #include "chrome/common/chrome_switches.h" 88 #include "chrome/common/chrome_switches.h"
89 #include "chrome/common/extensions/extension_permission_set.h" 89 #include "chrome/common/extensions/extension_permission_set.h"
90 #include "chrome/common/json_pref_store.h" 90 #include "chrome/common/json_pref_store.h"
91 #include "chrome/common/pref_names.h" 91 #include "chrome/common/pref_names.h"
92 #include "chrome/common/render_messages.h" 92 #include "chrome/common/render_messages.h"
93 #include "chrome/common/spellcheck_messages.h" 93 #include "chrome/common/spellcheck_messages.h"
94 #include "content/browser/appcache/chrome_appcache_service.h" 94 #include "content/browser/appcache/chrome_appcache_service.h"
95 #include "content/browser/browser_thread.h" 95 #include "content/browser/browser_thread.h"
96 #include "content/browser/chrome_blob_storage_context.h" 96 #include "content/browser/chrome_blob_storage_context.h"
97 #include "content/browser/file_system/browser_file_system_helper.h" 97 #include "content/browser/file_system/browser_file_system_helper.h"
98 #include "content/browser/host_zoom_map.h" 98 #include "content/browser/host_zoom_map.h"
99 #include "content/browser/in_process_webkit/webkit_context.h" 99 #include "content/browser/in_process_webkit/webkit_context.h"
100 #include "content/browser/renderer_host/render_process_host.h" 100 #include "content/browser/renderer_host/render_process_host.h"
101 #include "content/browser/speech/speech_input_manager.h" 101 #include "content/browser/speech/speech_input_manager.h"
102 #include "content/browser/ssl/ssl_host_state.h" 102 #include "content/browser/ssl/ssl_host_state.h"
103 #include "content/browser/user_metrics.h" 103 #include "content/browser/user_metrics.h"
104 #include "content/public/browser/notification_service.h" 104 #include "content/public/browser/notification_service.h"
105 #include "grit/browser_resources.h"
106 #include "grit/locale_settings.h" 105 #include "grit/locale_settings.h"
107 #include "net/base/transport_security_state.h" 106 #include "net/base/transport_security_state.h"
108 #include "net/http/http_server_properties.h" 107 #include "net/http/http_server_properties.h"
109 #include "ui/base/resource/resource_bundle.h"
110 #include "webkit/database/database_tracker.h" 108 #include "webkit/database/database_tracker.h"
111 #include "webkit/quota/quota_manager.h" 109 #include "webkit/quota/quota_manager.h"
112 110
113 #if defined(OS_WIN) 111 #if defined(OS_WIN)
114 #include "chrome/browser/instant/promo_counter.h" 112 #include "chrome/browser/instant/promo_counter.h"
115 #include "chrome/browser/password_manager/password_store_win.h" 113 #include "chrome/browser/password_manager/password_store_win.h"
116 #include "chrome/installer/util/install_util.h" 114 #include "chrome/installer/util/install_util.h"
117 #elif defined(OS_MACOSX) 115 #elif defined(OS_MACOSX)
118 #include "chrome/browser/keychain_mac.h" 116 #include "chrome/browser/keychain_mac.h"
119 #include "chrome/browser/mock_keychain_mac.h" 117 #include "chrome/browser/mock_keychain_mac.h"
(...skipping 26 matching lines...) Expand all
146 #if defined(OS_MACOSX) 144 #if defined(OS_MACOSX)
147 // Capacity for mock keychain used for testing. 145 // Capacity for mock keychain used for testing.
148 static const int kMockKeychainSize = 1000; 146 static const int kMockKeychainSize = 1000;
149 #endif 147 #endif
150 148
151 enum ContextType { 149 enum ContextType {
152 kNormalContext, 150 kNormalContext,
153 kMediaContext 151 kMediaContext
154 }; 152 };
155 153
156 typedef std::list<std::pair<FilePath::StringType, int> >
157 ComponentExtensionList;
158
159 #if defined(FILE_MANAGER_EXTENSION)
160 void AddFileManagerExtension(ComponentExtensionList* component_extensions) {
161 #ifndef NDEBUG
162 const CommandLine* command_line = CommandLine::ForCurrentProcess();
163 if (command_line->HasSwitch(switches::kFileManagerExtensionPath)) {
164 FilePath filemgr_extension_path =
165 command_line->GetSwitchValuePath(switches::kFileManagerExtensionPath);
166 component_extensions->push_back(std::make_pair(
167 filemgr_extension_path.value(),
168 IDR_FILEMANAGER_MANIFEST));
169 return;
170 }
171 #endif // NDEBUG
172 component_extensions->push_back(std::make_pair(
173 FILE_PATH_LITERAL("file_manager"),
174 IDR_FILEMANAGER_MANIFEST));
175 }
176 #endif // defined(FILE_MANAGER_EXTENSION)
177
178 // Gets the cache parameters from the command line. |type| is the type of 154 // Gets the cache parameters from the command line. |type| is the type of
179 // request context that we need, |cache_path| will be set to the user provided 155 // request context that we need, |cache_path| will be set to the user provided
180 // path, or will not be touched if there is not an argument. |max_size| will 156 // path, or will not be touched if there is not an argument. |max_size| will
181 // be the user provided value or zero by default. 157 // be the user provided value or zero by default.
182 void GetCacheParameters(ContextType type, FilePath* cache_path, 158 void GetCacheParameters(ContextType type, FilePath* cache_path,
183 int* max_size) { 159 int* max_size) {
184 DCHECK(cache_path); 160 DCHECK(cache_path);
185 DCHECK(max_size); 161 DCHECK(max_size);
186 162
187 // Override the cache location if specified by the user. 163 // Override the cache location if specified by the user.
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 autoupdate_enabled = !command_line->HasSwitch(switches::kGuestSession); 438 autoupdate_enabled = !command_line->HasSwitch(switches::kGuestSession);
463 #endif 439 #endif
464 extension_service_.reset(new ExtensionService( 440 extension_service_.reset(new ExtensionService(
465 this, 441 this,
466 CommandLine::ForCurrentProcess(), 442 CommandLine::ForCurrentProcess(),
467 GetPath().AppendASCII(ExtensionService::kInstallDirectoryName), 443 GetPath().AppendASCII(ExtensionService::kInstallDirectoryName),
468 extension_prefs_.get(), 444 extension_prefs_.get(),
469 autoupdate_enabled, 445 autoupdate_enabled,
470 extensions_enabled)); 446 extensions_enabled));
471 447
472 RegisterComponentExtensions(); 448 extension_service_->component_loader()->RegisterDefaultComponentExtensions();
Aaron Boodman 2011/10/28 22:21:58 For now, if you make the change I suggested to Com
Yoyo Zhou 2011/10/31 21:58:15 +1 I've seen quite a few subtle init bugs, and lo
Yoyo Zhou 2011/10/31 21:58:15 On 2011/10/28 22:21:58, Aaron Boodman wrote: > For
449
473 extension_service_->Init(); 450 extension_service_->Init();
474 451
475 if (extensions_enabled) { 452 if (extensions_enabled) {
476 // Load any extensions specified with --load-extension. 453 // Load any extensions specified with --load-extension.
454 // TODO(yoz): this should move into ExtensionService::Init
477 if (command_line->HasSwitch(switches::kLoadExtension)) { 455 if (command_line->HasSwitch(switches::kLoadExtension)) {
478 FilePath path = command_line->GetSwitchValuePath( 456 FilePath path = command_line->GetSwitchValuePath(
479 switches::kLoadExtension); 457 switches::kLoadExtension);
480 extension_service_->LoadExtensionFromCommandLine(path); 458 extension_service_->MakeUnpackedInstaller()->LoadFromCommandLine(path);
481 } 459 }
482 } 460 }
483 461
484 // Make the chrome://extension-icon/ resource available. 462 // Make the chrome://extension-icon/ resource available.
485 GetChromeURLDataManager()->AddDataSource(new ExtensionIconSource(this)); 463 GetChromeURLDataManager()->AddDataSource(new ExtensionIconSource(this));
486 464
487 // Initialize extension event routers. Note that on Chrome OS, this will 465 // Initialize extension event routers. Note that on Chrome OS, this will
488 // not succeed if the user has not logged in yet, in which case the 466 // not succeed if the user has not logged in yet, in which case the
489 // event routers are initialized in LoginUtilsImpl::CompleteLogin instead. 467 // event routers are initialized in LoginUtilsImpl::CompleteLogin instead.
490 // The InitEventRouters call used to be in BrowserMain, because when bookmark 468 // The InitEventRouters call used to be in BrowserMain, because when bookmark
491 // import happened on first run, the bookmark bar was not being correctly 469 // import happened on first run, the bookmark bar was not being correctly
492 // initialized (see issue 40144). Now that bookmarks aren't imported and 470 // initialized (see issue 40144). Now that bookmarks aren't imported and
493 // the event routers need to be initialized for every profile individually, 471 // the event routers need to be initialized for every profile individually,
494 // initialize them with the extension service. 472 // initialize them with the extension service.
495 // If this profile is being created as part of the import process, never 473 // If this profile is being created as part of the import process, never
496 // initialize the event routers. If import is going to run in a separate 474 // initialize the event routers. If import is going to run in a separate
497 // process (the profile itself is on the main process), wait for import to 475 // process (the profile itself is on the main process), wait for import to
498 // finish before initializing the routers. 476 // finish before initializing the routers.
499 if (!command_line->HasSwitch(switches::kImport) && 477 if (!command_line->HasSwitch(switches::kImport) &&
500 !command_line->HasSwitch(switches::kImportFromFile)) { 478 !command_line->HasSwitch(switches::kImportFromFile)) {
501 if (g_browser_process->profile_manager()->will_import()) { 479 if (g_browser_process->profile_manager()->will_import()) {
502 extension_service_->InitEventRoutersAfterImport(); 480 extension_service_->InitEventRoutersAfterImport();
503 } else { 481 } else {
504 extension_service_->InitEventRouters(); 482 extension_service_->InitEventRouters();
505 } 483 }
506 } 484 }
507 } 485 }
508 486
509 void ProfileImpl::RegisterComponentExtensions() {
510 // Register the component extensions.
511 //
512 // Component extension manifest must contain a 'key' property with a unique
513 // public key, serialized in base64. You can create a suitable value with the
514 // following commands on a unixy system:
515 //
516 // ssh-keygen -t rsa -b 1024 -N '' -f /tmp/key.pem
517 // openssl rsa -pubout -outform DER < /tmp/key.pem 2>/dev/null | base64 -w 0
518 typedef std::list<std::pair<FilePath::StringType, int> >
519 ComponentExtensionList;
520 ComponentExtensionList component_extensions;
521
522 // Bookmark manager.
523 component_extensions.push_back(std::make_pair(
524 FILE_PATH_LITERAL("bookmark_manager"),
525 IDR_BOOKMARKS_MANIFEST));
526
527 #if defined(FILE_MANAGER_EXTENSION)
528 AddFileManagerExtension(&component_extensions);
529 #endif
530
531 #if defined(USE_VIRTUAL_KEYBOARD)
532 component_extensions.push_back(std::make_pair(
533 FILE_PATH_LITERAL("keyboard"),
534 IDR_KEYBOARD_MANIFEST));
535 #endif
536
537 #if defined(OS_CHROMEOS)
538 component_extensions.push_back(std::make_pair(
539 FILE_PATH_LITERAL("/usr/share/chromeos-assets/mobile"),
540 IDR_MOBILE_MANIFEST));
541
542 const CommandLine* command_line = CommandLine::ForCurrentProcess();
543 if (command_line->HasSwitch(switches::kAuthExtensionPath)) {
544 FilePath auth_extension_path =
545 command_line->GetSwitchValuePath(switches::kAuthExtensionPath);
546 component_extensions.push_back(std::make_pair(
547 auth_extension_path.value(),
548 IDR_GAIA_TEST_AUTH_MANIFEST));
549 } else {
550 component_extensions.push_back(std::make_pair(
551 FILE_PATH_LITERAL("/usr/share/chromeos-assets/gaia_auth"),
552 IDR_GAIA_AUTH_MANIFEST));
553 }
554
555 #if defined(OFFICIAL_BUILD)
556 if (browser_defaults::enable_help_app) {
557 component_extensions.push_back(std::make_pair(
558 FILE_PATH_LITERAL("/usr/share/chromeos-assets/helpapp"),
559 IDR_HELP_MANIFEST));
560 }
561 #endif
562 #endif
563
564 // Web Store.
565 component_extensions.push_back(std::make_pair(
566 FILE_PATH_LITERAL("web_store"),
567 IDR_WEBSTORE_MANIFEST));
568
569 #if !defined(OS_CHROMEOS)
570 // Cloud Print component app. Not required on Chrome OS.
571 component_extensions.push_back(std::make_pair(
572 FILE_PATH_LITERAL("cloud_print"),
573 IDR_CLOUDPRINT_MANIFEST));
574 #endif // !defined(OS_CHROMEOS)
575
576 for (ComponentExtensionList::iterator iter = component_extensions.begin();
577 iter != component_extensions.end(); ++iter) {
578 FilePath path(iter->first);
579 if (!path.IsAbsolute()) {
580 if (PathService::Get(chrome::DIR_RESOURCES, &path)) {
581 path = path.Append(iter->first);
582 } else {
583 NOTREACHED();
584 }
585 }
586
587 std::string manifest =
588 ResourceBundle::GetSharedInstance().GetRawDataResource(
589 iter->second).as_string();
590 extension_service_->register_component_extension(
591 ExtensionService::ComponentExtensionInfo(manifest, path));
592 }
593
594 #if defined(OS_CHROMEOS)
595 // Register access extensions only if accessibility is enabled.
596 if (g_browser_process->local_state()->
597 GetBoolean(prefs::kAccessibilityEnabled)) {
598 FilePath path = FilePath(extension_misc::kAccessExtensionPath)
599 .AppendASCII(extension_misc::kChromeVoxDirectoryName);
600 std::string manifest =
601 ResourceBundle::GetSharedInstance().GetRawDataResource(
602 IDR_CHROMEVOX_MANIFEST).as_string();
603 extension_service_->register_component_extension(
604 ExtensionService::ComponentExtensionInfo(manifest, path));
605 }
606 #endif
607 }
608
609 void ProfileImpl::InitPromoResources() { 487 void ProfileImpl::InitPromoResources() {
610 if (promo_resource_service_) 488 if (promo_resource_service_)
611 return; 489 return;
612 490
613 promo_resource_service_ = new PromoResourceService(this); 491 promo_resource_service_ = new PromoResourceService(this);
614 promo_resource_service_->StartAfterDelay(); 492 promo_resource_service_->StartAfterDelay();
615 } 493 }
616 494
617 void ProfileImpl::InitRegisteredProtocolHandlers() { 495 void ProfileImpl::InitRegisteredProtocolHandlers() {
618 if (protocol_handler_registry_) 496 if (protocol_handler_registry_)
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 1555
1678 void ProfileImpl::ClearNetworkingHistorySince(base::Time time) { 1556 void ProfileImpl::ClearNetworkingHistorySince(base::Time time) {
1679 io_data_.ClearNetworkingHistorySince(time); 1557 io_data_.ClearNetworkingHistorySince(time);
1680 } 1558 }
1681 1559
1682 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() { 1560 SpellCheckProfile* ProfileImpl::GetSpellCheckProfile() {
1683 if (!spellcheck_profile_.get()) 1561 if (!spellcheck_profile_.get())
1684 spellcheck_profile_.reset(new SpellCheckProfile(path_)); 1562 spellcheck_profile_.reset(new SpellCheckProfile(path_));
1685 return spellcheck_profile_.get(); 1563 return spellcheck_profile_.get();
1686 } 1564 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698