2012년 3월 27일 화요일

Content Shell 의 구조 - ShellMainDelegate 클래스(3)

Content Shell의 ShellMainDelegate 클래스의 구현에 대해 살펴보자.

shell_main_delegate.cc 파일을 보면 ContentMainDelegate의 많은 추상함수들이
빈 함수로 구현되어 있음을 알 수 있다.

아래는 ShellMainDelegate 클래스에서 실제로 구현한 함수들이다.
PreSandboxStartup()
RunProcess()
ZygoteForked()
InitializeShellContentClient()
InitializeResourceBundle()

PreSandboxStartup() 함수를 살펴보자.


content::SetContentClient() 함수가 이 Content Shell에서 중요한 역할을 하고 있는것 같다.
이전에 언급한 적이 있는것 같은데, Content Module이 Server가 되고, Content Module을 이용하여
구현한 브라우저가 Client가 되는형태라고 말이다.
ShellMainDelegate 클래스를 가볍게 보고나서, ContentMain() 함수를 알아볼 때
이 client 가 언제 어떻게 사용되는지 알 수 있을 것이다.

다음으로 InitializeShellContentClient() 함수를 호출하고 있다.
process_type을 파라미터로 전달해 주는데, 이 type이 무엇일까?
아래의 InitializeShellContentClient() 함수를 보면 process_type을 비교하여 type에 맞는 client 를
설정하고 있다. Content Client 도 세부적으로 browser client, renderer client, plugin client, utility client들이 필요한 것 같다.


type에 맞는 세부 클라이언트들은 content::GetContentClient()->set_XXX 함수를 이용하여 셋팅하고 있다. PreSandboxStartup() 에서 content::SetContentClient()를 이용하여 ShellContentClient 객체를 셋팅하고, content::GetContentClient()는 이 때 설정한 ShellContentClient를 리턴한다.
Content Module은 SetContentClient()를 통해 셋팅된 각각의 포인터를 통해 Embedder의 Client 객체들을 참조하게 될것이다. 여기서 Embedder가 무엇인가? 이제는 바로 답을 할 수 있어야 할 것이다!
다음으로 InitializeResourceBundle() 함수를 호출하고 있다.
이 함수는 content_shell.pak 이라는 pak 파일을 이용하여 ui::ResourceBundle에 초기화를 요청하는것 같다. 이 pak 파일은 content_shell 빌드시 생성된다.

PreSandboxStartup() 함수에 대해 알아보았다. PreSandboxStartup()은 Content Module 이 Embedder에게 Sandbox 초기화전에 할일하라고 알려줄 때 사용되는 추상함수이다. Content Module은 이 추상함수를 호출하고 Sandbox 관련 내용(?)을 초기화 할 것이다. 아마 이 부분은 content::ContentMain() 함수에서 수행될 것이다.

SandboxInitialized() 함수는 빈 함수로 보아 Content Shell 에서는 Sandbox 에 대한부분은 없는것 같다.

RunProcess() 함수를 살펴보자.
이 함수는 process type과 MainFunctionParams 라는 구조체를 파라미터로 전달받고 있고 파라미터 타입이 빈 문자열일 경우에 ShellBrowserMain() 함수를 호출하고 있다.
ShellBrowserMain() 함수는 src/content/shell/shell_browser_main.cc 에 정의되어 있고, 주석을 보면 이 함수가 Content Shell의 Main routine 임을 알 수있다. 이번 포스트는 ShellMainDelegate 클래스에 대한 이야기이므로 ShellBrowserMain은 다음에 알아보자.

마지막으로 ZygoteForked() 함수를 살펴보자. 프로세스가 fork() 된 후,  process type(switchs::kProcessType)을 보고 이 타입에 맞는 Content Client 를 InitializeShellContentClient() 함수에서 초기화하고 있다. 여기서 초기화되는 각각의 클라이언트들은 Content Module 내 프로세스들이 embedder에게 무언가 요청할 때 사용될 것이다.

지금까지 ShellMainDelegate 클래스에 대해 알아보았다. 이 클래스가 하는일은 크게 두가지로 볼 수 있겠다. 첫번째는 Content Module에서 사용되는 프로세스 타입에 맞는 Content Client 들을 초기화하는 일이고 두번째는 ShellBrowserMain을 통해 브라우저 메인 루틴을 실행하는 일이다. 이 두가지 모두 ContentMain() 이 호출되면서 그 안에서 참조되는 것들이다. 이것들의 자세한 내용은 ContentMain()에서 사용될 때 알아보자.

댓글 없음:

댓글 쓰기