Commit d3d7f623 authored by Erik Chen's avatar Erik Chen Committed by Commit Bot

lacros: Use generated MinVersion enums rather than raw ints.

This CL is a refactor with no intended behavior change.

The implementation of LacrosChromeServiceImpl depends on many version
checks against AshChromeServiceVersion. New code can easily set the
wrong version due to a rebase. Using gneerated MinVersion enums
sidesteps this failure case.

Change-Id: I350dc69f430e7dab81eceaeb118ecdd5687be7dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2547789
Commit-Queue: Erik Chen <erikchen@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828958}
parent 596462f5
......@@ -14,6 +14,8 @@
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "url/gurl.h"
using AshChromeService = crosapi::mojom::AshChromeService;
namespace chromeos {
namespace {
......@@ -390,39 +392,65 @@ void LacrosChromeServiceImpl::DisableCrosapiForTests() {
}
bool LacrosChromeServiceImpl::IsMessageCenterAvailable() {
return AshChromeServiceVersion() >= 0;
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version &&
version.value() >=
AshChromeService::MethodMinVersions::kBindMessageCenterMinVersion;
}
bool LacrosChromeServiceImpl::IsSelectFileAvailable() {
return AshChromeServiceVersion() >= 0;
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version &&
version.value() >=
AshChromeService::MethodMinVersions::kBindSelectFileMinVersion;
}
bool LacrosChromeServiceImpl::IsKeystoreServiceAvailable() {
return AshChromeServiceVersion() >= 0;
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version && version.value() >= AshChromeService::MethodMinVersions::
kBindKeystoreServiceMinVersion;
}
bool LacrosChromeServiceImpl::IsHidManagerAvailable() {
return AshChromeServiceVersion() >= 0;
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version &&
version.value() >=
AshChromeService::MethodMinVersions::kBindHidManagerMinVersion;
}
bool LacrosChromeServiceImpl::IsFeedbackAvailable() {
return AshChromeServiceVersion() >= 3;
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version &&
version.value() >=
AshChromeService::MethodMinVersions::kBindFeedbackMinVersion;
}
bool LacrosChromeServiceImpl::IsAccountManagerAvailable() {
return AshChromeServiceVersion() >= 4;
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version &&
version.value() >=
AshChromeService::MethodMinVersions::kBindAccountManagerMinVersion;
}
bool LacrosChromeServiceImpl::IsFileManagerAvailable() {
return AshChromeServiceVersion() >= 5;
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version &&
version.value() >=
AshChromeService::MethodMinVersions::kBindFileManagerMinVersion;
}
bool LacrosChromeServiceImpl::IsScreenManagerAvailable() {
return AshChromeServiceVersion() >= 0;
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version &&
version.value() >=
AshChromeService::MethodMinVersions::kBindScreenManagerMinVersion;
}
bool LacrosChromeServiceImpl::IsMediaSessionAudioFocusAvailable() {
return AshChromeServiceVersion() >= 6;
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version && version.value() >=
AshChromeService::MethodMinVersions::
kBindMediaSessionAudioFocusMinVersion;
}
void LacrosChromeServiceImpl::BindAudioFocusManager(
......@@ -437,7 +465,10 @@ void LacrosChromeServiceImpl::BindAudioFocusManager(
}
bool LacrosChromeServiceImpl::IsMediaSessionAudioFocusDebugAvailable() {
return AshChromeServiceVersion() >= 6;
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version && version.value() >=
AshChromeService::MethodMinVersions::
kBindMediaSessionAudioFocusDebugMinVersion;
}
void LacrosChromeServiceImpl::BindAudioFocusManagerDebug(
......@@ -453,7 +484,10 @@ void LacrosChromeServiceImpl::BindAudioFocusManagerDebug(
}
bool LacrosChromeServiceImpl::IsMediaSessionControllerAvailable() {
return AshChromeServiceVersion() >= 6;
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version && version.value() >=
AshChromeService::MethodMinVersions::
kBindMediaSessionControllerMinVersion;
}
void LacrosChromeServiceImpl::BindMediaControllerManager(
......@@ -469,7 +503,10 @@ void LacrosChromeServiceImpl::BindMediaControllerManager(
}
bool LacrosChromeServiceImpl::IsOnLacrosStartupAvailable() {
return AshChromeServiceVersion() >= 3;
base::Optional<uint32_t> version = AshChromeServiceVersion();
return version &&
version.value() >=
AshChromeService::MethodMinVersions::kOnLacrosStartupMinVersion;
}
int LacrosChromeServiceImpl::GetInterfaceVersion(
......@@ -519,9 +556,9 @@ void LacrosChromeServiceImpl::GetActiveTabUrlAffineSequence(
delegate_->GetActiveTabUrl(std::move(callback));
}
int LacrosChromeServiceImpl::AshChromeServiceVersion() {
base::Optional<uint32_t> LacrosChromeServiceImpl::AshChromeServiceVersion() {
if (g_disable_all_crosapi_for_tests)
return -1;
return base::nullopt;
DCHECK(did_bind_receiver_);
return init_params_->ash_chrome_service_version;
}
......
......@@ -10,6 +10,7 @@
#include "base/component_export.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h"
#include "chromeos/crosapi/mojom/account_manager.mojom.h"
......@@ -234,7 +235,7 @@ class COMPONENT_EXPORT(CHROMEOS_LACROS) LacrosChromeServiceImpl {
// Returns ash's version of the AshChromeService mojo interface version. This
// determines which interface methods are available. This is safe to call from
// any sequence. This can only be called after BindReceiver().
int AshChromeServiceVersion();
base::Optional<uint32_t> AshChromeServiceVersion();
// Delegate instance to inject Chrome dependent code. Must only be used on the
// affine sequence.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment