summaryrefslogtreecommitdiffstats
path: root/content/ppapi_plugin/ppapi_webkit_thread.h
blob: a6f338e00d6af0928e8fe611f754edba8eae7b8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2011 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_PPAPI_PLUGIN_PPAPI_WEBKIT_THREAD_H_
#define CONTENT_PPAPI_PLUGIN_PPAPI_WEBKIT_THREAD_H_
#pragma once

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread.h"

class PpapiWebKitClientImpl;

// This creates a WebKit main thread on instantiation on construction and kills
// it on deletion. See also content/browser/in_process_webkit for the
// corresponding concept in the browser process.
class PpapiWebKitThread {
 public:
  PpapiWebKitThread();
  ~PpapiWebKitThread();

  // Posts the given task to the thread, see MessageLoop::PostTask.
  void PostTask(
      const tracked_objects::Location& from_here,
      const base::Closure& task);

 private:
  // Must be private so that we can carefully control its lifetime.
  class InternalWebKitThread : public base::Thread {
   public:
    InternalWebKitThread();
    virtual ~InternalWebKitThread();
    // Does the actual initialization and shutdown of WebKit.  Called at the
    // beginning and end of the thread's lifetime.
    virtual void Init();
    virtual void CleanUp();

   private:
    // The WebKitClient implementation.  Only access on WebKit thread.
    scoped_ptr<PpapiWebKitClientImpl> webkit_client_;
  };

  // Pointer to the actual WebKitThread.
  scoped_ptr<InternalWebKitThread> webkit_thread_;

  DISALLOW_COPY_AND_ASSIGN(PpapiWebKitThread);
};

#endif  // CONTENT_PPAPI_PLUGIN_PPAPI_WEBKIT_THREAD_H_