1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_APP_CONTENT_MAIN_DELEGATE_H_
6 #define CONTENT_PUBLIC_APP_CONTENT_MAIN_DELEGATE_H_
10 #include "build/build_config.h"
11 #include "content/common/content_export.h"
15 class ContentBrowserClient;
16 class ContentPluginClient;
17 class ContentRendererClient;
18 class ContentUtilityClient;
19 class ZygoteForkDelegate;
20 struct MainFunctionParams;
22 class CONTENT_EXPORT ContentMainDelegate {
24 virtual ~ContentMainDelegate() {}
26 // Tells the embedder that the absolute basic startup has been done, i.e.
27 // it's now safe to create singletons and check the command line. Return true
28 // if the process should exit afterwards, and if so, |exit_code| should be
29 // set. This is the place for embedder to do the things that must happen at
30 // the start. Most of its startup code should be in the methods below.
31 virtual bool BasicStartupComplete(int* exit_code);
33 // This is where the embedder puts all of its startup code that needs to run
34 // before the sandbox is engaged.
35 virtual void PreSandboxStartup() {}
37 // This is where the embedder can add startup code to run after the sandbox
38 // has been initialized.
39 virtual void SandboxInitialized(const std::string& process_type) {}
41 // Asks the embedder to start a process. Return -1 for the default behavior.
42 virtual int RunProcess(
43 const std::string& process_type,
44 const MainFunctionParams& main_function_params);
46 // Called right before the process exits.
47 virtual void ProcessExiting(const std::string& process_type) {}
49 #if defined(OS_MACOSX) && !defined(OS_IOS)
50 // Returns true if the process registers with the system monitor, so that we
51 // can allocate an IO port for it before the sandbox is initialized. Embedders
52 // are called only for process types that content doesn't know about.
53 virtual bool ProcessRegistersWithSystemProcess(
54 const std::string& process_type);
56 // Used to determine if we should send the mach port to the parent process or
57 // not. The embedder usually sends it for all child processes, use this to
58 // override this behavior.
59 virtual bool ShouldSendMachPort(const std::string& process_type);
61 // Allows the embedder to override initializing the sandbox. This is needed
62 // because some processes might not want to enable it right away or might not
64 virtual bool DelaySandboxInitialization(const std::string& process_type);
66 #elif defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
67 // Tells the embedder that the zygote process is starting, and allows it to
68 // specify a zygote delegate if it wishes.
69 virtual ZygoteForkDelegate* ZygoteStarting();
71 // Called every time the zygote process forks.
72 virtual void ZygoteForked() {}
76 friend class ContentClientInitializer;
78 // Called once per relevant process type to allow the embedder to customize
79 // content. If an embedder wants the default (empty) implementation, don't
81 virtual ContentBrowserClient* CreateContentBrowserClient();
82 virtual ContentPluginClient* CreateContentPluginClient();
83 virtual ContentRendererClient* CreateContentRendererClient();
84 virtual ContentUtilityClient* CreateContentUtilityClient();
87 } // namespace content
89 #endif // CONTENT_PUBLIC_APP_CONTENT_MAIN_DELEGATE_H_