Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / mojo / shell / network_application_loader.cc
blobdbe70b767c00fd1fef0950fe1d5852a517da7fc9
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"
15 namespace {
16 base::FilePath GetBasePath() {
17 base::FilePath path;
18 CHECK(PathService::Get(base::DIR_TEMP, &path));
19 return path.Append(FILE_PATH_LITERAL("network_service"));
23 namespace mojo {
24 namespace shell {
26 NetworkApplicationLoader::NetworkApplicationLoader() {
29 NetworkApplicationLoader::~NetworkApplicationLoader() {
32 void NetworkApplicationLoader::Load(ApplicationManager* manager,
33 const GURL& url,
34 scoped_refptr<LoadCallbacks> callbacks) {
35 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication();
36 if (!shell_handle.is_valid())
37 return;
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,
48 const GURL& url) {
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);
60 return true;
63 void NetworkApplicationLoader::Create(
64 ApplicationConnection* connection,
65 InterfaceRequest<NetworkService> request) {
66 BindToRequest(new NetworkServiceImpl(connection, context_.get()), &request);
69 } // namespace shell
70 } // namespace mojo