1 // Copyright 2014 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 MOJO_APPS_JS_JS_APP_H_
6 #define MOJO_APPS_JS_JS_APP_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/threading/thread.h"
11 #include "gin/public/isolate_holder.h"
12 #include "gin/shell_runner.h"
13 #include "mojo/apps/js/mojo_runner_delegate.h"
14 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.h"
20 class ApplicationDelegateImpl;
22 // Each JavaScript app started by content handler runs on its own thread and
23 // in its own V8 isolate. This class represents one running JS app.
25 // The lifetime of this class is defined by the content handler's internal
30 JSApp(ApplicationDelegateImpl* content_handler_app,
31 const std::string& url,
32 URLResponsePtr content);
37 Handle ConnectToService(const std::string& application_url,
38 const std::string& interface_name);
44 // Used to CHECK that we're running on the correct thread.
45 bool on_content_handler_thread() const;
46 bool on_js_app_thread() const;
48 ApplicationDelegateImpl* content_handler_app_;
50 URLResponsePtr content_;
52 scoped_refptr<base::SingleThreadTaskRunner> content_handler_task_runner_;
53 scoped_refptr<base::SingleThreadTaskRunner> js_app_task_runner_;
54 MojoRunnerDelegate runner_delegate_;
55 scoped_ptr<gin::IsolateHolder> isolate_holder_;
56 scoped_ptr<gin::ShellRunner> shell_runner_;
58 DISALLOW_COPY_AND_ASSIGN(JSApp);
64 #endif // MOJO_APPS_JS_JS_APP_H_