-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This CL adds a LanguageProfileController to manage the LanguageProfileDelegate and handle logging while getting preferred languages. To get preferred languages from a background thread call: LanguageProfileController.getLanguagePreferences(accountName) Bug: 1258255 Change-Id: Ibab5ab54eec7240d9b5d74452af9e4081ac3c3fc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3314393 Reviewed-by: Josh Simmons <jds@google.com> Reviewed-by: Anthony Cui <cuianthony@chromium.org> Commit-Queue: Trevor Perrier <perrier@chromium.org> Cr-Commit-Position: refs/heads/main@{#949627}
- Loading branch information
Trevor Perrier
authored and
Chromium LUCI CQ
committed
Dec 8, 2021
1 parent
61b3ace
commit a08d163
Showing
4 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...language/android/java/src/org/chromium/components/language/LanguageProfileController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.components.language; | ||
|
||
import org.chromium.base.Log; | ||
import org.chromium.base.ThreadUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
/** | ||
* Controller to manage getting language preferences from device. | ||
*/ | ||
public final class LanguageProfileController { | ||
private static final String TAG = "ULP"; | ||
private static final int TIMEOUT_IN_SECONDS = 60; | ||
|
||
private LanguageProfileDelegate mDelegate; | ||
|
||
/** | ||
* @param delegate LanguageProfileDelegate to use. | ||
*/ | ||
public LanguageProfileController(LanguageProfileDelegate delegate) { | ||
mDelegate = delegate; | ||
} | ||
|
||
/** | ||
* Get the preferred languages for user. The list is empty if an error occurs. | ||
* This method is blocking and must be called on a background thread. | ||
* @param accountName Account to get profile or null if the default profile should be returned. | ||
* @return A list of language tags ordered by preference for |accountName| | ||
*/ | ||
public List<String> getLanguagePreferences(String accountName) { | ||
ThreadUtils.assertOnBackgroundThread(); | ||
if (!mDelegate.isULPAvailable()) { | ||
// (TODO:https://crbug.com/1258261) Add initiation histogram. | ||
Log.d(TAG, "ULP not available"); | ||
return new ArrayList<String>(); | ||
} | ||
try { | ||
return mDelegate.getLanguagePreferences(accountName, TIMEOUT_IN_SECONDS); | ||
} catch (TimeoutException e) { | ||
// (TODO:https://crbug.com/1258261) Add initiation histogram. | ||
Log.d(TAG, "ULP getLanguagePreferences timed out"); | ||
} catch (Exception e) { | ||
// (TODO:https://crbug.com/1258261) Add initiation histogram. | ||
Log.d(TAG, "ULP getLanguagePreferences threw exception:", e); | ||
} | ||
return new ArrayList<String>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters