diff options
author | marshall@chromium.org <marshall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 15:58:52 +0000 |
---|---|---|
committer | marshall@chromium.org <marshall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 15:58:52 +0000 |
commit | f573ed6b419616e8d2ff7932d931be3c57105e14 (patch) | |
tree | 2b0e957536241765f67b5b2b6a532f342b802fa2 /content/public/app | |
parent | 0818ff1493b5acc658b881b0e7709f5440b3aef4 (diff) | |
download | chromium_src-f573ed6b419616e8d2ff7932d931be3c57105e14.zip chromium_src-f573ed6b419616e8d2ff7932d931be3c57105e14.tar.gz chromium_src-f573ed6b419616e8d2ff7932d931be3c57105e14.tar.bz2 |
Support sharing of ContentMain and BrowserMain code with embedded use cases (try #3).
For the browser use case it is convenient to have a single ContentMain entry point function that handles all initialization, run and shutdown. For embedded use cases it is often necessary to integrate with existing application message loops where initialization and shutdown must be handled separately.
To support sharing of this code the following changes were required:
1. Refactor the ContentMain function to create a ContentMainRunner class containing separate initialization, run and shutdown functions.
2. Refactor the BrowserMain function and BrowserMainLoop class to create a BrowserMainRunner class containing separate initialization, run and shutdown functions.
3. Add a new BrowserMainParts::GetMainMessageLoop method. This is necessary to support creation of a custom MessageLoop implementation while sharing BrowserMainRunner initialization and shutdown code.
BUG=112507
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9375017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121454 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/public/app')
-rw-r--r-- | content/public/app/content_main.h | 43 | ||||
-rw-r--r-- | content/public/app/content_main_delegate.h | 4 | ||||
-rw-r--r-- | content/public/app/content_main_runner.h | 57 |
3 files changed, 102 insertions, 2 deletions
diff --git a/content/public/app/content_main.h b/content/public/app/content_main.h new file mode 100644 index 0000000..6c58a8a --- /dev/null +++ b/content/public/app/content_main.h @@ -0,0 +1,43 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_PUBLIC_APP_CONTENT_MAIN_H_ +#define CONTENT_PUBLIC_APP_CONTENT_MAIN_H_ +#pragma once + +#include "build/build_config.h" +#include "content/common/content_export.h" + +#if defined(OS_WIN) +#include <windows.h> +#endif + +namespace sandbox { +struct SandboxInterfaceInfo; +} + +namespace content { + +class ContentMainDelegate; + +// ContentMain should be called from the embedder's main() function to do the +// initial setup for every process. The embedder has a chance to customize +// startup using the ContentMainDelegate interface. The embedder can also pass +// in NULL for |delegate| if they don't want to override default startup. +#if defined(OS_WIN) + +// |sandbox_info| should be initialized using InitializeSandboxInfo from +// content_main_win.h +CONTENT_EXPORT int ContentMain(HINSTANCE instance, + sandbox::SandboxInterfaceInfo* sandbox_info, + ContentMainDelegate* delegate); +#else +CONTENT_EXPORT int ContentMain(int argc, + const char** argv, + ContentMainDelegate* delegate); +#endif + +} // namespace content + +#endif // CONTENT_PUBLIC_APP_CONTENT_MAIN_H_ diff --git a/content/public/app/content_main_delegate.h b/content/public/app/content_main_delegate.h index 6fd40b0..c7c6bd6 100644 --- a/content/public/app/content_main_delegate.h +++ b/content/public/app/content_main_delegate.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -34,7 +34,7 @@ class ContentMainDelegate { // has been initialized. virtual void SandboxInitialized(const std::string& process_type) = 0; - // Asks the embedder to start a process that content doesn't know about. + // Asks the embedder to start a process. Return -1 for the default behavior. virtual int RunProcess( const std::string& process_type, const content::MainFunctionParams& main_function_params) = 0; diff --git a/content/public/app/content_main_runner.h b/content/public/app/content_main_runner.h new file mode 100644 index 0000000..af9d05f --- /dev/null +++ b/content/public/app/content_main_runner.h @@ -0,0 +1,57 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_PUBLIC_APP_CONTENT_MAIN_RUNNER_H_ +#define CONTENT_PUBLIC_APP_CONTENT_MAIN_RUNNER_H_ +#pragma once + +#include <string> + +#include "build/build_config.h" + +#if defined(OS_WIN) +#include <windows.h> +#endif + +namespace sandbox { +struct SandboxInterfaceInfo; +} + +namespace content { + +class ContentMainDelegate; + +// This class is responsible for content initialization, running and shutdown. +class ContentMainRunner { + public: + virtual ~ContentMainRunner() {} + + // Create a new ContentMainRunner object. + static ContentMainRunner* Create(); + + // Initialize all necessary content state. +#if defined(OS_WIN) + // The |sandbox_info| and |delegate| objects must outlive this class. + // |sandbox_info| should be initialized using InitializeSandboxInfo from + // content_main_win.h. + virtual int Initialize(HINSTANCE instance, + sandbox::SandboxInterfaceInfo* sandbox_info, + ContentMainDelegate* delegate) = 0; +#else + // The |delegate| object must outlive this class. + virtual int Initialize(int argc, + const char** argv, + ContentMainDelegate* delegate) = 0; +#endif + + // Perform the default run logic. + virtual int Run() = 0; + + // Shut down the content state. + virtual void Shutdown() = 0; +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_APP_CONTENT_MAIN_RUNNER_H_ |