ipc/chromium/src/chrome/common/child_thread.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/chrome/common/child_thread.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +// Copyright (c) 2009 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef CHROME_COMMON_CHILD_THREAD_H_
     1.9 +#define CHROME_COMMON_CHILD_THREAD_H_
    1.10 +
    1.11 +#include "base/thread.h"
    1.12 +#include "chrome/common/ipc_sync_channel.h"
    1.13 +#include "chrome/common/message_router.h"
    1.14 +
    1.15 +class ResourceDispatcher;
    1.16 +
    1.17 +// Child processes's background thread should derive from this class.
    1.18 +class ChildThread : public IPC::Channel::Listener,
    1.19 +                    public IPC::Message::Sender,
    1.20 +                    public base::Thread {
    1.21 + public:
    1.22 +  // Creates the thread.
    1.23 +  ChildThread(Thread::Options options);
    1.24 +  virtual ~ChildThread();
    1.25 +
    1.26 +  // IPC::Message::Sender implementation:
    1.27 +  virtual bool Send(IPC::Message* msg);
    1.28 +
    1.29 +  // See documentation on MessageRouter for AddRoute and RemoveRoute
    1.30 +  void AddRoute(int32_t routing_id, IPC::Channel::Listener* listener);
    1.31 +  void RemoveRoute(int32_t routing_id);
    1.32 +
    1.33 +  MessageLoop* owner_loop() { return owner_loop_; }
    1.34 +
    1.35 + protected:
    1.36 +  friend class ChildProcess;
    1.37 +
    1.38 +  // Starts the thread.
    1.39 +  bool Run();
    1.40 +
    1.41 +  // Overrides the channel name.  Used for --single-process mode.
    1.42 +  void SetChannelName(const std::wstring& name) { channel_name_ = name; }
    1.43 +
    1.44 +  // Called when the process refcount is 0.
    1.45 +  void OnProcessFinalRelease();
    1.46 +
    1.47 + protected:
    1.48 +  // The required stack size if V8 runs on a thread.
    1.49 +  static const size_t kV8StackSize;
    1.50 +
    1.51 +  virtual void OnControlMessageReceived(const IPC::Message& msg) { }
    1.52 +
    1.53 +  // Returns the one child thread.
    1.54 +  static ChildThread* current();
    1.55 +
    1.56 +  IPC::Channel* channel() { return channel_.get(); }
    1.57 +
    1.58 +  // Thread implementation.
    1.59 +  virtual void Init();
    1.60 +  virtual void CleanUp();
    1.61 +
    1.62 + private:
    1.63 +  // IPC::Channel::Listener implementation:
    1.64 +  virtual void OnMessageReceived(const IPC::Message& msg);
    1.65 +  virtual void OnChannelError();
    1.66 +
    1.67 +#ifdef MOZ_NUWA_PROCESS
    1.68 +  static void MarkThread();
    1.69 +#endif
    1.70 +
    1.71 +  // The message loop used to run tasks on the thread that started this thread.
    1.72 +  MessageLoop* owner_loop_;
    1.73 +
    1.74 +  std::wstring channel_name_;
    1.75 +  scoped_ptr<IPC::Channel> channel_;
    1.76 +
    1.77 +  // Used only on the background render thread to implement message routing
    1.78 +  // functionality to the consumers of the ChildThread.
    1.79 +  MessageRouter router_;
    1.80 +
    1.81 +  Thread::Options options_;
    1.82 +
    1.83 +  // If true, checks with the browser process before shutdown.  This avoids race
    1.84 +  // conditions if the process refcount is 0 but there's an IPC message inflight
    1.85 +  // that would addref it.
    1.86 +  bool check_with_browser_before_shutdown_;
    1.87 +
    1.88 +  DISALLOW_EVIL_CONSTRUCTORS(ChildThread);
    1.89 +};
    1.90 +
    1.91 +#endif  // CHROME_COMMON_CHILD_THREAD_H_

mercurial