chromium之extension机制简单分析二:extensionservice创建及初始化
来源:互联网 发布:网络行业都有哪些工作 编辑:程序博客网 时间:2024/06/06 05:29
上一篇中分析了从浏览器初始化到extension框架的依赖图的创建过程,这一过程结束时系统extension框架所需的主要工厂对象及其相互依赖关系已经创建起来了,但是各种具体对象并没有创建起来,这里以extensionservice的创建过程为例进行分析具体service的创建:
从ChromeBrowserMainParts::PreMainMessageLoopRunImpl方法调用PreProfileInit();方法结束开始继续进行分析,以CreatePrimaryProfile方法为入口,大致上可以分为两个过程:ExtensionSystemImpl的创建和ExtensionService的创建及初始化,总体上的时序图如下所示:
这里只关注主要流程,首先是通过ProfileManager::GetProfile获取当前的profile(profile实际上就是一个数据绑定,Chromium has lots of features that hook into aProfile, a bundle of data about the current user and the current chrome session that can span multiple browser windows,其架构可以参见chromium技术文档:http://dev.chromium.org/developers/design-documents/profile-architecture),由于此时还没有创建profile,因此会调用ProfileManager::CreateProfileHelper方法创建此对象:
Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) { TRACE_EVENT0("browser", "ProfileManager::GetProfile") // If the profile is already loaded (e.g., chrome.exe launched twice), just // return it. Profile* profile = GetProfileByPath(profile_dir); if (NULL != profile) return profile; profile = CreateProfileHelper(profile_dir); DCHECK(profile); if (profile) { bool result = AddProfile(profile); DCHECK(result); } return profile;}从这里也就看以看出两个过程:CreateProfileHelper和AddProfile,前一个方法主要完成ExtensionSystemImplement对象的创建,后一个方法则完成对对象的初始化操作,而ExtensionService对象也在第二个过程中完成创建和初始化;
1、在ProfileImpl构造函数中会调用BrowserContextDependencyManager::GetInstance()->RegisterProfilePrefsForServices(this, pref_registry_.get());方法和BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(this);方法,根据已经建立起来的依赖图按顺序创建各自的主服务对象并进行注册:
void BrowserContextDependencyManager::RegisterProfilePrefsForServices( const content::BrowserContext* context, user_prefs::PrefRegistrySyncable* pref_registry) { std::vector<DependencyNode*> construction_order; if (!dependency_graph_.GetConstructionOrder(&construction_order)) { NOTREACHED(); } for (std::vector<DependencyNode*>::const_iterator it = construction_order.begin(); it != construction_order.end(); ++it) { BrowserContextKeyedBaseFactory* factory = static_cast<BrowserContextKeyedBaseFactory*>(*it); factory->RegisterProfilePrefsIfNecessaryForContext(context, pref_registry); }}
void BrowserContextDependencyManager::CreateBrowserContextServices( content::BrowserContext* context) { DoCreateBrowserContextServices(context, false);}
void BrowserContextDependencyManager::DoCreateBrowserContextServices( content::BrowserContext* context, bool is_testing_context) { will_create_browser_context_services_callbacks_.Notify(context); std::vector<DependencyNode*> construction_order; if (!dependency_graph_.GetConstructionOrder(&construction_order)) { NOTREACHED(); } for (size_t i = 0; i < construction_order.size(); i++) { BrowserContextKeyedBaseFactory* factory = static_cast<BrowserContextKeyedBaseFactory*>(construction_order[i]); if (is_testing_context && factory->ServiceIsNULLWhileTesting() && !factory->HasTestingFactory(context)) { factory->SetEmptyTestingFactory(context); } else if (factory->ServiceIsCreatedWithBrowserContext()) { // Create the service. factory->CreateServiceNow(context); } }}在上述方法中如果对应的服务没有创建,则会调用factory->CreateServiceNow(context);方法创建对应的Service,此方法为虚方法,具体实现需要各个节点自己实现,此处则主要完成了ExtensionSystemImplement对象和ExtensionSystemImplement::Shared对象的创建。
2、通过CreateProfileHelpe方法创建对应的profile之后,ProfileManager::AddProfile方法会被调用,进行注册此profile,并进行后续的初始化操作(DoFinalInit-->DoFinalInitForServices-->extensions::ExtensionSystem::Get(profile)->InitForRegularProfile);从时序图中可以看出,InitForRegularProfile方法会调用ExtensionSystemImpl::Shared::Init方法创建extensionservice对象并进行初始化。
void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { const CommandLine* command_line = CommandLine::ForCurrentProcess(); extension_service_.reset(new ExtensionService( profile_, CommandLine::ForCurrentProcess(), profile_->GetPath().AppendASCII(extensions::kInstallDirectoryName), ExtensionPrefs::Get(profile_), blacklist_.get(), autoupdate_enabled, extensions_enabled, &ready_));</span> ...... extension_service_->Init(); ......}在ExtensionService::Init方法中会通过component_loader_和extensions::InstalledLoader加载系统默认的和已经安装的扩展程序。
- chromium之extension机制简单分析二:extensionservice创建及初始化
- chromium之extension机制简单分析一:extension初始化
- chromium之extension机制简单分析三:webstore API实现
- Chromium扩展(Extension)通信机制分析
- WebKit之chromium进程创建过程分析
- chromium之content_shell源代码分析(二)
- chromium之content_shell源代码分析(二)
- Chromium扩展(Extension)加载过程分析
- Chromium 多线程机制分析
- chromium 进程创建分析
- Chromium扩展(Extension)机制简要介绍和学习计划
- Chromium contentshell启动分析之sandox process创建历程(chromium:tag28)
- Qemu-KVM虚拟机初始化及创建过程源码简要分析(二)
- Chromium扩展(Extension)的Content Script加载过程分析
- Chromium扩展(Extension)的Content Script加载过程分析
- Linux中断机制之二:初始化
- Linux中断机制之二:初始化
- handler机制分析之二
- Linux ADF 理解
- USACO 2.1 Sorting a Three-Valued Sequence
- unity与手机相关吧
- android camera(四):camera 驱动 GT2005
- PHP处理Checkbox复选框表单提交
- chromium之extension机制简单分析二:extensionservice创建及初始化
- android camera(三):camera V4L2 FIMC
- CSS背景图像位置属性background-position百分比详解
- android camera(二):摄像头工作原理、s5PV310 摄像头接口(CAMIF)
- linux tar
- CSS透明opacity和IE各版本透明度滤镜filter的最准确用法
- 拦截器的执行顺序
- POJ 4007:计算字符串距离
- android camera(一):camera模组CMM介绍