chromium源码阅读

Posted 丹西

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了chromium源码阅读相关的知识,希望对你有一定的参考价值。

linux下chromium的入口函数在文件:src/chrome/app/chrome_exe_main_aura.cc 中

int main(int argc, const char** argv) {
  return ChromeMain(argc, argv);
}

ChromeMain函数在 src/chrome/app/chrome_main.cc 中

base::CommandLine::Init(params.argc, params.argv);

具体函数如下:

bool CommandLine::Init(int argc, const char* const* argv) {
  if (current_process_commandline_) {
    // If this is intentional, Reset() must be called first. If we are using
    // the shared build mode, we have to share a single object across multiple
    // shared libraries.
    return false;
  }

  current_process_commandline_ = new CommandLine(NO_PROGRAM);
#if defined(OS_WIN)
  current_process_commandline_->ParseFromString(::GetCommandLineW());
#elif defined(OS_POSIX)
  current_process_commandline_->InitFromArgv(argc, argv);
#endif

  return true;
}

接下来进入文件: src/headless/app/headless_shell.cc

int HeadlessBrowserMain(
    HeadlessBrowser::Options options,
    const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) {
  DCHECK(!on_browser_start_callback.is_null());
#if DCHECK_IS_ON()
  // The browser can only be initialized once.
  static bool browser_was_initialized;
  DCHECK(!browser_was_initialized);
  browser_was_initialized = true;

  // Child processes should not end up here.
  DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(
      ::switches::kProcessType));
#endif
  return RunContentMain(std::move(options),
                        std::move(on_browser_start_callback));
}

继续:src/content/app/content_main.cc

int ContentMain(const ContentMainParams& params) {
  ContentServiceManagerMainDelegate delegate(params);
  service_manager::MainParams main_params(&delegate);
#if defined(OS_POSIX) && !defined(OS_android)
  main_params.argc = params.argc;
  main_params.argv = params.argv;
#endif
  return service_manager::Main(main_params);
}

继续往下看:src/services/service_manager/embedder/main.cc   int Main(const MainParams& params) 中

switch (process_type) {
    case ProcessType::kDefault:
      NOTREACHED();
      break;

    case ProcessType::kServiceManager:
      exit_code = RunServiceManager(delegate);
      break;

    case ProcessType::kService:
      CommonSubprocessInit();
      exit_code = RunService(delegate);
      break;

    case ProcessType::kEmbedder:
      if (ServiceManagerIsRemote())
        CommonSubprocessInit();
      exit_code = delegate->RunEmbedderProcess();
      break;
  }

继续://src/base/run_loop.cc

void RunLoop::Run() {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

  if (!BeforeRun())
    return;

  // It is okay to access this RunLoop from another sequence while Run() is
  // active as this RunLoop won‘t touch its state until after that returns (if
  // the RunLoop‘s state is accessed while processing Run(), it will be re-bound
  // to the accessing sequence for the remainder of that Run() -- accessing from
  // multiple sequences is still disallowed).
  DETACH_FROM_SEQUENCE(sequence_checker_);

  // Use task stopwatch to exclude the loop run time from the current task, if
  // any.
  tracked_objects::TaskStopwatch stopwatch;
  stopwatch.Start();
  delegate_->Run();
  stopwatch.Stop();

  // Rebind this RunLoop to the current thread after Run().
  DETACH_FROM_SEQUENCE(sequence_checker_);
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

  AfterRun();
}

 

以上是关于chromium源码阅读的主要内容,如果未能解决你的问题,请参考以下文章

chromium源码阅读--进程的Message Loop

chromium源码阅读--HTTP Cache

chromium源码阅读--图片处理

chromium中的GN构建系统

Python代码阅读(第19篇):合并多个字典

如何获取最新chromium源码