sky | d196fac | 2015-10-13 19:01:46 | [diff] [blame] | 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. |
| 4 | |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 5 | #include "services/service_manager/public/c/main.h" |
Scott Violet | dd9b796 | 2018-07-18 21:27:34 | [diff] [blame] | 6 | #include "ash/ash_service.h" |
| 7 | #include "base/feature_list.h" |
| 8 | #include "base/files/file_path.h" |
Scott Violet | bef3de4 | 2018-08-09 23:11:26 | [diff] [blame] | 9 | #include "base/logging.h" |
Scott Violet | dd9b796 | 2018-07-18 21:27:34 | [diff] [blame] | 10 | #include "base/path_service.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 11 | #include "services/service_manager/public/cpp/service_runner.h" |
Scott Violet | dd9b796 | 2018-07-18 21:27:34 | [diff] [blame] | 12 | #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" |
sky | d196fac | 2015-10-13 19:01:46 | [diff] [blame] | 15 | |
Scott Violet | dd9b796 | 2018-07-18 21:27:34 | [diff] [blame] | 16 | // This path is only hit in testing, not production. Production launches ash by |
| 17 | // way of the utility process, which does not use this. |
ben | 438daa5 | 2016-07-29 22:02:35 | [diff] [blame] | 18 | MojoResult ServiceMain(MojoHandle service_request_handle) { |
Scott Violet | bef3de4 | 2018-08-09 23:11:26 | [diff] [blame] | 19 | logging::SetLogPrefix("ash"); |
Scott Violet | dd9b796 | 2018-07-18 21:27:34 | [diff] [blame] | 20 | // 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 Violet | f76e64ab | 2018-07-20 05:17:03 | [diff] [blame] | 51 | CHECK(base::FeatureList::InitializeInstance(enabled_features, |
| 52 | disabled_features)); |
| 53 | CHECK(base::FeatureList::IsEnabled(features::kMash)); |
Scott Violet | dd9b796 | 2018-07-18 21:27:34 | [diff] [blame] | 54 | |
| 55 | ui::MaterialDesignController::Initialize(); |
| 56 | |
| 57 | service_manager::ServiceRunner runner(new ash::AshService); |
| 58 | runner.set_message_loop_type(base::MessageLoop::TYPE_UI); |
ben | 438daa5 | 2016-07-29 22:02:35 | [diff] [blame] | 59 | return runner.Run(service_request_handle); |
sky | d196fac | 2015-10-13 19:01:46 | [diff] [blame] | 60 | } |