blob: a8acfb82261d96ee9d9fe8c40ccb65a44533e458 [file] [log] [blame]
skyd196fac2015-10-13 19:01:461// 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.
4
rockot734fb662016-10-15 16:41:305#include "services/service_manager/public/c/main.h"
Scott Violetdd9b7962018-07-18 21:27:346#include "ash/ash_service.h"
7#include "base/feature_list.h"
8#include "base/files/file_path.h"
Scott Violetbef3de42018-08-09 23:11:269#include "base/logging.h"
Scott Violetdd9b7962018-07-18 21:27:3410#include "base/path_service.h"
rockot734fb662016-10-15 16:41:3011#include "services/service_manager/public/cpp/service_runner.h"
Scott Violetdd9b7962018-07-18 21:27:3412#include "ui/base/material_design/material_design_controller.h"
13#include "ui/base/resource/resource_bundle.h"
14#include "ui/base/ui_base_features.h"
skyd196fac2015-10-13 19:01:4615
Scott Violetdd9b7962018-07-18 21:27:3416// This path is only hit in testing, not production. Production launches ash by
17// way of the utility process, which does not use this.
ben438daa52016-07-29 22:02:3518MojoResult ServiceMain(MojoHandle service_request_handle) {
Scott Violetbef3de42018-08-09 23:11:2619 logging::SetLogPrefix("ash");
Scott Violetdd9b7962018-07-18 21:27:3420 // Load ash resources and strings.
21 // TODO: investigate nuking ash_service_resources and use the same resources
22 // that are used when AshService is launched via the utility process.
23 base::FilePath path;
24 base::PathService::Get(base::DIR_MODULE, &path);
25 base::FilePath ash_resources =
26 path.Append(FILE_PATH_LITERAL("ash_service_resources.pak"));
27 ui::ResourceBundle::InitSharedInstanceWithPakPath(ash_resources);
28 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
29 if (ui::ResourceBundle::IsScaleFactorSupported(ui::SCALE_FACTOR_200P)) {
30 base::FilePath ash_resources_200 =
31 path.Append(FILE_PATH_LITERAL("ash_service_resources_200.pak"));
32 rb.AddDataPackFromPath(ash_resources_200, ui::SCALE_FACTOR_200P);
33 }
34
35 // AshService has a distinct code path when running out of process. The out of
36 // process code path is triggered by way of |kMash|. As this code is only run
37 // when ash is out of process it has to force |kMash| to be enabled
38 // (otherwise AshService thinks it's running in process, which does not make
39 // sense, nor work).
40 DCHECK(base::FeatureList::GetInstance());
41 std::string enabled_features;
42 std::string disabled_features;
43 base::FeatureList::GetInstance()->GetCommandLineFeatureOverrides(
44 &enabled_features, &disabled_features);
45 if (!enabled_features.empty())
46 enabled_features += ",";
47 enabled_features += features::kMash.name;
48 // This code path is really only for testing (production code uses the utility
49 // process to launch AshService), so it's ok to use a for-testing function.
50 base::FeatureList::ClearInstanceForTesting();
Scott Violetf76e64ab2018-07-20 05:17:0351 CHECK(base::FeatureList::InitializeInstance(enabled_features,
52 disabled_features));
53 CHECK(base::FeatureList::IsEnabled(features::kMash));
Scott Violetdd9b7962018-07-18 21:27:3454
55 ui::MaterialDesignController::Initialize();
56
57 service_manager::ServiceRunner runner(new ash::AshService);
58 runner.set_message_loop_type(base::MessageLoop::TYPE_UI);
ben438daa52016-07-29 22:02:3559 return runner.Run(service_request_handle);
skyd196fac2015-10-13 19:01:4660}