android_intent_helper.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2019 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. #include "ash/public/cpp/android_intent_helper.h"
  5. #include "base/check_op.h"
  6. #include "base/strings/string_util.h"
  7. namespace ash {
  8. namespace {
  9. AndroidIntentHelper* g_android_intent_helper = nullptr;
  10. // Scheme of the Android intent url.
  11. constexpr char kAndroidIntentScheme[] = "intent";
  12. // Prefix of the Android intent ref fragment.
  13. constexpr char kAndroidIntentPrefix[] = "Intent;";
  14. } // namespace
  15. // static
  16. AndroidIntentHelper* AndroidIntentHelper::GetInstance() {
  17. return g_android_intent_helper;
  18. }
  19. AndroidIntentHelper::AndroidIntentHelper() {
  20. DCHECK(!g_android_intent_helper);
  21. g_android_intent_helper = this;
  22. }
  23. AndroidIntentHelper::~AndroidIntentHelper() {
  24. DCHECK_EQ(g_android_intent_helper, this);
  25. g_android_intent_helper = nullptr;
  26. }
  27. bool IsAndroidIntent(const GURL& url) {
  28. return url.SchemeIs(kAndroidIntentScheme) ||
  29. base::StartsWith(url.ref(), kAndroidIntentPrefix,
  30. base::CompareCase::SENSITIVE);
  31. }
  32. } // namespace ash