Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: content/common/mojo/static_application_loader.cc

Issue 1743473002: Change Mojo URLs to structured names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@18collapse
Patch Set: . Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/common/mojo/static_application_loader.h ('k') | content/common/url_schemes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/mojo/static_application_loader.h" 5 #include "content/common/mojo/static_application_loader.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/task_runner.h" 12 #include "base/task_runner.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "base/threading/simple_thread.h" 14 #include "base/threading/simple_thread.h"
15 #include "mojo/public/cpp/bindings/interface_request.h" 15 #include "mojo/public/cpp/bindings/interface_request.h"
16 #include "mojo/shell/public/cpp/application_runner.h" 16 #include "mojo/shell/public/cpp/application_runner.h"
17 #include "mojo/shell/public/cpp/shell_client.h" 17 #include "mojo/shell/public/cpp/shell_client.h"
18 #include "mojo/shell/public/interfaces/shell_client.mojom.h" 18 #include "mojo/shell/public/interfaces/shell_client.mojom.h"
19 19
20 namespace content { 20 namespace content {
21 21
22 namespace { 22 namespace {
23 23
24 class RunnerThread : public base::SimpleThread { 24 class RunnerThread : public base::SimpleThread {
25 public: 25 public:
26 RunnerThread(const GURL& url, 26 RunnerThread(const std::string& name,
27 mojo::shell::mojom::ShellClientRequest request, 27 mojo::shell::mojom::ShellClientRequest request,
28 scoped_refptr<base::TaskRunner> exit_task_runner, 28 scoped_refptr<base::TaskRunner> exit_task_runner,
29 const base::Closure& exit_callback, 29 const base::Closure& exit_callback,
30 const StaticApplicationLoader::ApplicationFactory& factory) 30 const StaticApplicationLoader::ApplicationFactory& factory)
31 : base::SimpleThread("Mojo Application: " + url.spec()), 31 : base::SimpleThread("Mojo Application: " + name),
32 request_(std::move(request)), 32 request_(std::move(request)),
33 exit_task_runner_(exit_task_runner), 33 exit_task_runner_(exit_task_runner),
34 exit_callback_(exit_callback), 34 exit_callback_(exit_callback),
35 factory_(factory) {} 35 factory_(factory) {}
36 36
37 void Run() override { 37 void Run() override {
38 scoped_ptr<mojo::ApplicationRunner> runner( 38 scoped_ptr<mojo::ApplicationRunner> runner(
39 new mojo::ApplicationRunner(factory_.Run().release())); 39 new mojo::ApplicationRunner(factory_.Run().release()));
40 runner->Run(request_.PassMessagePipe().release().value(), 40 runner->Run(request_.PassMessagePipe().release().value(),
41 false /* init_base */); 41 false /* init_base */);
(...skipping 21 matching lines...) Expand all
63 const base::Closure& quit_callback) 63 const base::Closure& quit_callback)
64 : factory_(factory), quit_callback_(quit_callback), weak_factory_(this) { 64 : factory_(factory), quit_callback_(quit_callback), weak_factory_(this) {
65 } 65 }
66 66
67 StaticApplicationLoader::~StaticApplicationLoader() { 67 StaticApplicationLoader::~StaticApplicationLoader() {
68 if (thread_) 68 if (thread_)
69 StopAppThread(); 69 StopAppThread();
70 } 70 }
71 71
72 void StaticApplicationLoader::Load( 72 void StaticApplicationLoader::Load(
73 const GURL& url, 73 const std::string& name,
74 mojo::shell::mojom::ShellClientRequest request) { 74 mojo::shell::mojom::ShellClientRequest request) {
75 if (thread_) 75 if (thread_)
76 return; 76 return;
77 77
78 // If the application's thread quits on its own before this loader dies, we 78 // If the application's thread quits on its own before this loader dies, we
79 // reset the Thread object, allowing future Load requests to be fulfilled 79 // reset the Thread object, allowing future Load requests to be fulfilled
80 // with a new app instance. 80 // with a new app instance.
81 auto exit_callback = base::Bind(&StaticApplicationLoader::StopAppThread, 81 auto exit_callback = base::Bind(&StaticApplicationLoader::StopAppThread,
82 weak_factory_.GetWeakPtr()); 82 weak_factory_.GetWeakPtr());
83 thread_.reset(new RunnerThread(url, std::move(request), 83 thread_.reset(new RunnerThread(name, std::move(request),
84 base::ThreadTaskRunnerHandle::Get(), 84 base::ThreadTaskRunnerHandle::Get(),
85 exit_callback, factory_)); 85 exit_callback, factory_));
86 thread_->Start(); 86 thread_->Start();
87 } 87 }
88 88
89 void StaticApplicationLoader::StopAppThread() { 89 void StaticApplicationLoader::StopAppThread() {
90 thread_->Join(); 90 thread_->Join();
91 thread_.reset(); 91 thread_.reset();
92 if (!quit_callback_.is_null()) 92 if (!quit_callback_.is_null())
93 quit_callback_.Run(); 93 quit_callback_.Run();
94 } 94 }
95 95
96 } // namespace content 96 } // namespace content
OLDNEW
« no previous file with comments | « content/common/mojo/static_application_loader.h ('k') | content/common/url_schemes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698