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

Side by Side Diff: mojo/application/content_handler_factory.cc

Issue 1174063002: Remove use of MessageLoopProxy (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 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 | « no previous file | mojo/common/handle_watcher.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 2014 The Chromium Authors. All rights reserved. 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 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 "mojo/application/content_handler_factory.h" 5 #include "mojo/application/content_handler_factory.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/thread_task_runner_handle.h"
12 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
13 #include "mojo/application/application_runner_chromium.h" 14 #include "mojo/application/application_runner_chromium.h"
14 #include "mojo/common/message_pump_mojo.h" 15 #include "mojo/common/message_pump_mojo.h"
15 #include "mojo/public/cpp/application/application_connection.h" 16 #include "mojo/public/cpp/application/application_connection.h"
16 #include "mojo/public/cpp/application/application_delegate.h" 17 #include "mojo/public/cpp/application/application_delegate.h"
17 #include "mojo/public/cpp/application/application_impl.h" 18 #include "mojo/public/cpp/application/application_impl.h"
18 #include "mojo/public/cpp/application/interface_factory_impl.h" 19 #include "mojo/public/cpp/application/interface_factory_impl.h"
19 #include "mojo/public/cpp/bindings/strong_binding.h" 20 #include "mojo/public/cpp/bindings/strong_binding.h"
20 #include "mojo/services/content_handler/public/interfaces/content_handler.mojom. h" 21 #include "mojo/services/content_handler/public/interfaces/content_handler.mojom. h"
21 22
22 namespace mojo { 23 namespace mojo {
23 24
24 namespace { 25 namespace {
25 26
26 class ApplicationThread : public base::PlatformThread::Delegate { 27 class ApplicationThread : public base::PlatformThread::Delegate {
27 public: 28 public:
28 ApplicationThread( 29 ApplicationThread(
29 scoped_refptr<base::MessageLoopProxy> handler_thread, 30 scoped_refptr<base::SingleThreadTaskRunner> handler_thread,
30 const base::Callback<void(ApplicationThread*)>& termination_callback, 31 const base::Callback<void(ApplicationThread*)>& termination_callback,
31 ContentHandlerFactory::Delegate* handler_delegate, 32 ContentHandlerFactory::Delegate* handler_delegate,
32 InterfaceRequest<Application> application_request, 33 InterfaceRequest<Application> application_request,
33 URLResponsePtr response) 34 URLResponsePtr response)
34 : handler_thread_(handler_thread), 35 : handler_thread_(handler_thread),
35 termination_callback_(termination_callback), 36 termination_callback_(termination_callback),
36 handler_delegate_(handler_delegate), 37 handler_delegate_(handler_delegate),
37 application_request_(application_request.Pass()), 38 application_request_(application_request.Pass()),
38 response_(response.Pass()) {} 39 response_(response.Pass()) {}
39 40
40 private: 41 private:
41 void ThreadMain() override { 42 void ThreadMain() override {
42 base::PlatformThread::SetName(response_->url); 43 base::PlatformThread::SetName(response_->url);
43 handler_delegate_->RunApplication(application_request_.Pass(), 44 handler_delegate_->RunApplication(application_request_.Pass(),
44 response_.Pass()); 45 response_.Pass());
45 handler_thread_->PostTask(FROM_HERE, 46 handler_thread_->PostTask(FROM_HERE,
46 base::Bind(termination_callback_, this)); 47 base::Bind(termination_callback_, this));
47 } 48 }
48 49
49 scoped_refptr<base::MessageLoopProxy> handler_thread_; 50 scoped_refptr<base::SingleThreadTaskRunner> handler_thread_;
50 base::Callback<void(ApplicationThread*)> termination_callback_; 51 base::Callback<void(ApplicationThread*)> termination_callback_;
51 ContentHandlerFactory::Delegate* handler_delegate_; 52 ContentHandlerFactory::Delegate* handler_delegate_;
52 InterfaceRequest<Application> application_request_; 53 InterfaceRequest<Application> application_request_;
53 URLResponsePtr response_; 54 URLResponsePtr response_;
54 55
55 DISALLOW_COPY_AND_ASSIGN(ApplicationThread); 56 DISALLOW_COPY_AND_ASSIGN(ApplicationThread);
56 }; 57 };
57 58
58 class ContentHandlerImpl : public ContentHandler { 59 class ContentHandlerImpl : public ContentHandler {
59 public: 60 public:
(...skipping 12 matching lines...) Expand all
72 base::PlatformThread::Join(thread.second); 73 base::PlatformThread::Join(thread.second);
73 delete thread.first; 74 delete thread.first;
74 } 75 }
75 } 76 }
76 77
77 private: 78 private:
78 // Overridden from ContentHandler: 79 // Overridden from ContentHandler:
79 void StartApplication(InterfaceRequest<Application> application_request, 80 void StartApplication(InterfaceRequest<Application> application_request,
80 URLResponsePtr response) override { 81 URLResponsePtr response) override {
81 ApplicationThread* thread = new ApplicationThread( 82 ApplicationThread* thread = new ApplicationThread(
82 base::MessageLoopProxy::current(), 83 base::ThreadTaskRunnerHandle::Get(),
83 base::Bind(&ContentHandlerImpl::OnThreadEnd, 84 base::Bind(&ContentHandlerImpl::OnThreadEnd,
84 weak_factory_.GetWeakPtr()), 85 weak_factory_.GetWeakPtr()),
85 delegate_, application_request.Pass(), response.Pass()); 86 delegate_, application_request.Pass(), response.Pass());
86 base::PlatformThreadHandle handle; 87 base::PlatformThreadHandle handle;
87 bool launched = base::PlatformThread::Create(0, thread, &handle); 88 bool launched = base::PlatformThread::Create(0, thread, &handle);
88 DCHECK(launched); 89 DCHECK(launched);
89 active_threads_[thread] = handle; 90 active_threads_[thread] = handle;
90 } 91 }
91 92
92 void OnThreadEnd(ApplicationThread* thread) { 93 void OnThreadEnd(ApplicationThread* thread) {
(...skipping 30 matching lines...) Expand all
123 if (application) 124 if (application)
124 loop.Run(); 125 loop.Run();
125 } 126 }
126 127
127 void ContentHandlerFactory::Create(ApplicationConnection* connection, 128 void ContentHandlerFactory::Create(ApplicationConnection* connection,
128 InterfaceRequest<ContentHandler> request) { 129 InterfaceRequest<ContentHandler> request) {
129 new ContentHandlerImpl(delegate_, request.Pass()); 130 new ContentHandlerImpl(delegate_, request.Pass());
130 } 131 }
131 132
132 } // namespace mojo 133 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/common/handle_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698