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

Side by Side Diff: mojo/shell/android/background_application_loader.cc

Issue 1049993002: Get mojo_shell building inside chromium checkout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix presubmit Created 5 years, 8 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
OLDNEW
(Empty)
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.
4
5 #include "mojo/shell/android/background_application_loader.h"
6
7 #include "base/bind.h"
8 #include "base/run_loop.h"
9 #include "mojo/shell/application_manager/application_manager.h"
10
11 namespace mojo {
12 namespace shell {
13
14 BackgroundApplicationLoader::BackgroundApplicationLoader(
15 scoped_ptr<ApplicationLoader> real_loader,
16 const std::string& thread_name,
17 base::MessageLoop::Type message_loop_type)
18 : loader_(real_loader.Pass()),
19 message_loop_type_(message_loop_type),
20 thread_name_(thread_name),
21 message_loop_created_(true, false) {
22 }
23
24 BackgroundApplicationLoader::~BackgroundApplicationLoader() {
25 if (thread_)
26 thread_->Join();
27 }
28
29 void BackgroundApplicationLoader::Load(
30 const GURL& url,
31 InterfaceRequest<Application> application_request) {
32 DCHECK(application_request.is_pending());
33 if (!thread_) {
34 // TODO(tim): It'd be nice if we could just have each Load call
35 // result in a new thread like DynamicService{Loader, Runner}. But some
36 // loaders are creating multiple ApplicationImpls (NetworkApplicationLoader)
37 // sharing a delegate (etc). So we have to keep it single threaded, wait
38 // for the thread to initialize, and post to the TaskRunner for subsequent
39 // Load calls for now.
40 thread_.reset(new base::DelegateSimpleThread(this, thread_name_));
41 thread_->Start();
42 message_loop_created_.Wait();
43 DCHECK(task_runner_.get());
44 }
45
46 task_runner_->PostTask(
47 FROM_HERE,
48 base::Bind(&BackgroundApplicationLoader::LoadOnBackgroundThread,
49 base::Unretained(this), url,
50 base::Passed(&application_request)));
51 }
52
53 void BackgroundApplicationLoader::Run() {
54 base::MessageLoop message_loop(message_loop_type_);
55 base::RunLoop loop;
56 task_runner_ = message_loop.task_runner();
57 quit_closure_ = loop.QuitClosure();
58 message_loop_created_.Signal();
59 loop.Run();
60
61 // Destroy |loader_| on the thread it's actually used on.
62 loader_.reset();
63 }
64
65 void BackgroundApplicationLoader::LoadOnBackgroundThread(
66 const GURL& url,
67 InterfaceRequest<Application> application_request) {
68 DCHECK(task_runner_->RunsTasksOnCurrentThread());
69 loader_->Load(url, application_request.Pass());
70 }
71
72 } // namespace shell
73 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/android/background_application_loader.h ('k') | mojo/shell/android/background_application_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698