[Android] Introduce new UMA action for when user copies Image URL from context menu
[chromium-blink-merge.git] / mojo / services / network / network_service_delegate.cc
blobb3b1c8e8a4bf546bfa4e8ccdc22ddcebc2330811
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
3 // found in the LICENSE file.
5 #include "mojo/services/network/network_service_delegate.h"
7 #include "base/at_exit.h"
8 #include "base/base_paths.h"
9 #include "base/files/file_path.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/path_service.h"
12 #include "mojo/application/public/cpp/application_connection.h"
13 #include "mojo/services/network/network_service_impl.h"
14 #include "mojo/services/network/url_loader_factory_impl.h"
16 NetworkServiceDelegate::NetworkServiceDelegate() : app_(nullptr) {}
18 NetworkServiceDelegate::~NetworkServiceDelegate() {}
20 void NetworkServiceDelegate::Initialize(mojo::ApplicationImpl* app) {
21 app_ = app;
22 base::FilePath base_path;
23 CHECK(PathService::Get(base::DIR_TEMP, &base_path));
24 base_path = base_path.Append(FILE_PATH_LITERAL("network_service"));
25 context_.reset(new mojo::NetworkContext(base_path));
28 bool NetworkServiceDelegate::ConfigureIncomingConnection(
29 mojo::ApplicationConnection* connection) {
30 DCHECK(context_);
31 connection->AddService<mojo::NetworkService>(this);
32 connection->AddService<mojo::URLLoaderFactory>(this);
33 return true;
36 void NetworkServiceDelegate::Quit() {
37 // Destroy the NetworkContext now as it requires MessageLoop::current() upon
38 // destruction and it is the last moment we know for sure that it is
39 // running.
40 context_.reset();
43 void NetworkServiceDelegate::Create(
44 mojo::ApplicationConnection* connection,
45 mojo::InterfaceRequest<mojo::NetworkService> request) {
46 new mojo::NetworkServiceImpl(
47 connection,
48 context_.get(),
49 app_->app_lifetime_helper()->CreateAppRefCount(),
50 request.Pass());
53 void NetworkServiceDelegate::Create(
54 mojo::ApplicationConnection* connection,
55 mojo::InterfaceRequest<mojo::URLLoaderFactory> request) {
56 new mojo::URLLoaderFactoryImpl(
57 connection,
58 context_.get(),
59 app_->app_lifetime_helper()->CreateAppRefCount(),
60 request.Pass());