1 // Copyright 2013 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_BROWSER_RENDER_PROCESS_HOST_OBSERVER_H_
6 #define CONTENT_PUBLIC_BROWSER_RENDER_PROCESS_HOST_OBSERVER_H_
7 
8 #include "base/process/kill.h"
9 #include "base/process/process_handle.h"
10 #include "content/common/content_export.h"
11 
12 namespace content {
13 
14 class RenderProcessHost;
15 struct ChildProcessTerminationInfo;
16 
17 // An observer API implemented by classes which are interested
18 // in RenderProcessHost lifecycle events. Note that this does not allow
19 // observing the creation of a RenderProcessHost. There is a separate observer
20 // for that: RenderProcessHostCreationObserver.
21 class CONTENT_EXPORT RenderProcessHostObserver {
22  public:
23   // This method is invoked when the process was launched and the channel was
24   // connected. This is the earliest time it is safe to call Shutdown on the
25   // RenderProcessHost.
RenderProcessReady(RenderProcessHost * host)26   virtual void RenderProcessReady(RenderProcessHost* host) {}
27 
28   // This method is invoked when the process of the observed RenderProcessHost
29   // exits (either normally or with a crash). To determine if the process closed
30   // normally or crashed, examine the |status| parameter.
31   //
32   // A new render process may be spawned for this RenderProcessHost, but there
33   // are no guarantees (e.g. if shutdown is occurring, the HostDestroyed
34   // callback will happen soon and that will be it, but if the renderer crashed
35   // and the user clicks 'reload', a new render process will be spawned).
36   //
37   // This will cause a call to WebContentsObserver::RenderProcessGone() for the
38   // active renderer process for the top-level frame; for code that needs to be
39   // a WebContentsObserver anyway, consider whether that API might be a better
40   // choice.
RenderProcessExited(RenderProcessHost * host,const ChildProcessTerminationInfo & info)41   virtual void RenderProcessExited(RenderProcessHost* host,
42                                    const ChildProcessTerminationInfo& info) {}
43 
44   // This method is invoked when the observed RenderProcessHost itself is
45   // destroyed. This is guaranteed to be the last call made to the observer, so
46   // if the observer is tied to the observed RenderProcessHost, it is safe to
47   // delete it.
RenderProcessHostDestroyed(RenderProcessHost * host)48   virtual void RenderProcessHostDestroyed(RenderProcessHost* host) {}
49 
50  protected:
~RenderProcessHostObserver()51   virtual ~RenderProcessHostObserver() {}
52 };
53 
54 }  // namespace content
55 
56 #endif  // CONTENT_PUBLIC_BROWSER_RENDER_PROCESS_HOST_OBSERVER_H_
57