1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
9 #include "mozilla/java/GeckoProcessManagerWrappers.h"
10 #include "mozilla/java/GeckoProcessTypeWrappers.h"
11 #include "mozilla/java/ServiceAllocatorWrappers.h"
13 using namespace mozilla::hal
;
16 * Bucket the Gecko HAL process priority level into one of the three Android
19 static mozilla::java::ServiceAllocator::PriorityLevel::LocalRef
20 ToJavaPriorityLevel(const ProcessPriority aPriority
) {
21 if (aPriority
>= PROCESS_PRIORITY_FOREGROUND
) {
22 return mozilla::java::ServiceAllocator::PriorityLevel::FOREGROUND();
23 } else if (aPriority
<= PROCESS_PRIORITY_PREALLOC
&&
24 aPriority
>= PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE
) {
25 return mozilla::java::ServiceAllocator::PriorityLevel::BACKGROUND();
28 return mozilla::java::ServiceAllocator::PriorityLevel::IDLE();
34 void SetProcessPriority(int aPid
, ProcessPriority aPriority
) {
35 if (aPriority
== PROCESS_PRIORITY_PARENT_PROCESS
) {
36 // This is the parent process itself, which we do not control.
40 const int32_t intPriority
= static_cast<int32_t>(aPriority
);
41 if (intPriority
< 0 || intPriority
>= NUM_PROCESS_PRIORITY
) {
45 auto contentProcType
= java::GeckoProcessType::CONTENT();
47 java::GeckoProcessManager::Selector::New(contentProcType
, aPid
);
48 auto priorityLevel
= ToJavaPriorityLevel(aPriority
);
50 // To Android, a lower-valued integer is a higher relative priority.
51 // We take the integer value of the enum and subtract it from the value
52 // of the highest Gecko priority level to obtain a 0-based indicator of
53 // the relative priority within the Java PriorityLevel.
54 const int32_t relativeImportance
=
55 (static_cast<int32_t>(NUM_PROCESS_PRIORITY
) - 1) - intPriority
;
57 java::GeckoProcessManager::SetProcessPriority(selector
, priorityLevel
,
61 } // namespace hal_impl
62 } // namespace mozilla