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 #include "mojo/shell/network_application_loader.h"
7 #include "base/base_paths.h"
8 #include "base/files/file_path.h"
9 #include "base/path_service.h"
10 #include "mojo/public/cpp/application/application_connection.h"
11 #include "mojo/public/cpp/application/application_delegate.h"
12 #include "mojo/public/cpp/application/application_impl.h"
13 #include "mojo/services/network/network_service_impl.h"
16 base::FilePath
GetBasePath() {
18 CHECK(PathService::Get(base::DIR_TEMP
, &path
));
19 return path
.Append(FILE_PATH_LITERAL("network_service"));
26 NetworkApplicationLoader::NetworkApplicationLoader() {
29 NetworkApplicationLoader::~NetworkApplicationLoader() {
32 void NetworkApplicationLoader::Load(ApplicationManager
* manager
,
34 scoped_refptr
<LoadCallbacks
> callbacks
) {
35 ScopedMessagePipeHandle shell_handle
= callbacks
->RegisterApplication();
36 if (!shell_handle
.is_valid())
39 uintptr_t key
= reinterpret_cast<uintptr_t>(manager
);
40 if (apps_
.find(key
) == apps_
.end()) {
41 scoped_ptr
<ApplicationImpl
> app(
42 new ApplicationImpl(this, shell_handle
.Pass()));
43 apps_
.add(key
, app
.Pass());
47 void NetworkApplicationLoader::OnApplicationError(ApplicationManager
* manager
,
49 apps_
.erase(reinterpret_cast<uintptr_t>(manager
));
52 void NetworkApplicationLoader::Initialize(ApplicationImpl
* app
) {
53 // The context must be created on the same thread as the network service.
54 context_
.reset(new NetworkContext(GetBasePath()));
57 bool NetworkApplicationLoader::ConfigureIncomingConnection(
58 ApplicationConnection
* connection
) {
59 connection
->AddService(this);
63 void NetworkApplicationLoader::Create(
64 ApplicationConnection
* connection
,
65 InterfaceRequest
<NetworkService
> request
) {
66 BindToRequest(new NetworkServiceImpl(connection
, context_
.get()), &request
);