Home | History | Annotate | Download | only in app
      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.
      4 
      5 #ifndef CONTENT_PUBLIC_APP_CONTENT_MAIN_DELEGATE_H_
      6 #define CONTENT_PUBLIC_APP_CONTENT_MAIN_DELEGATE_H_
      7 
      8 #include <string>
      9 
     10 #include "build/build_config.h"
     11 #include "content/common/content_export.h"
     12 
     13 template <typename>
     14 class ScopedVector;
     15 
     16 namespace content {
     17 
     18 class ContentBrowserClient;
     19 class ContentPluginClient;
     20 class ContentRendererClient;
     21 class ContentUtilityClient;
     22 class ZygoteForkDelegate;
     23 struct MainFunctionParams;
     24 
     25 class CONTENT_EXPORT ContentMainDelegate {
     26  public:
     27   virtual ~ContentMainDelegate() {}
     28 
     29   // Tells the embedder that the absolute basic startup has been done, i.e.
     30   // it's now safe to create singletons and check the command line. Return true
     31   // if the process should exit afterwards, and if so, |exit_code| should be
     32   // set. This is the place for embedder to do the things that must happen at
     33   // the start. Most of its startup code should be in the methods below.
     34   virtual bool BasicStartupComplete(int* exit_code);
     35 
     36   // This is where the embedder puts all of its startup code that needs to run
     37   // before the sandbox is engaged.
     38   virtual void PreSandboxStartup() {}
     39 
     40   // This is where the embedder can add startup code to run after the sandbox
     41   // has been initialized.
     42   virtual void SandboxInitialized(const std::string& process_type) {}
     43 
     44   // Asks the embedder to start a process. Return -1 for the default behavior.
     45   virtual int RunProcess(
     46       const std::string& process_type,
     47       const MainFunctionParams& main_function_params);
     48 
     49   // Called right before the process exits.
     50   virtual void ProcessExiting(const std::string& process_type) {}
     51 
     52 #if defined(OS_MACOSX) && !defined(OS_IOS)
     53   // Returns true if the process registers with the system monitor, so that we
     54   // can allocate an IO port for it before the sandbox is initialized. Embedders
     55   // are called only for process types that content doesn't know about.
     56   virtual bool ProcessRegistersWithSystemProcess(
     57       const std::string& process_type);
     58 
     59   // Used to determine if we should send the mach port to the parent process or
     60   // not. The embedder usually sends it for all child processes, use this to
     61   // override this behavior.
     62   virtual bool ShouldSendMachPort(const std::string& process_type);
     63 
     64   // Allows the embedder to override initializing the sandbox. This is needed
     65   // because some processes might not want to enable it right away or might not
     66   // want it at all.
     67   virtual bool DelaySandboxInitialization(const std::string& process_type);
     68 
     69 #elif defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
     70   // Tells the embedder that the zygote process is starting, and allows it to
     71   // specify one or more zygote delegates if it wishes by storing them in
     72   // |*delegates|.
     73   virtual void ZygoteStarting(ScopedVector<ZygoteForkDelegate>* delegates);
     74 
     75   // Called every time the zygote process forks.
     76   virtual void ZygoteForked() {}
     77 #endif  // OS_MACOSX
     78 
     79   // Allows the embedder to disable termination on heap corruption.
     80   // This is being used to measure the impact of this feature on crash reports.
     81   // Termination on heap corruption is enabled by default.
     82   // TODO(erikwright): Remove this by September 2014 when experimentation is
     83   // complete.
     84   virtual bool ShouldEnableTerminationOnHeapCorruption();
     85 
     86  protected:
     87   friend class ContentClientInitializer;
     88 
     89   // Called once per relevant process type to allow the embedder to customize
     90   // content. If an embedder wants the default (empty) implementation, don't
     91   // override this.
     92   virtual ContentBrowserClient* CreateContentBrowserClient();
     93   virtual ContentPluginClient* CreateContentPluginClient();
     94   virtual ContentRendererClient* CreateContentRendererClient();
     95   virtual ContentUtilityClient* CreateContentUtilityClient();
     96 };
     97 
     98 }  // namespace content
     99 
    100 #endif  // CONTENT_PUBLIC_APP_CONTENT_MAIN_DELEGATE_H_
    101