Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/externalauth/VerifiedHandler.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
5 package org.chromium.chrome.browser.externalauth;
6
7 import android.content.Context;
8 import android.os.Handler;
9 import android.os.Message;
10 import android.os.Messenger;
11 import android.text.TextUtils;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 /**
17 * Handler class that ignores any messages coming from external caller that does n't meet the given
18 * authentication requirements.
19 */
20 public class VerifiedHandler extends Handler {
21 private final int mAuthRequirements;
22 private final String mCallerPackageToMatch;
23 private final Map<Messenger, Boolean> mClientTrustMap = new HashMap<Messenge r, Boolean>();
24 private final Context mContext;
25
26 /**
27 * Basic constructor for verified handler.
28 * @param context The context to use for accessing the package manager.
29 * @param authRequirements The requirements for authenticating the caller ap plication.
30 */
31 public VerifiedHandler(Context context, int authRequirements) {
32 this(context, authRequirements, "");
33 }
34
35 /**
36 * Constructor with package name requirement.
37 * @param context The context to use for accessing the package manager.
38 * @param authRequirements The requirements for authenticating the caller ap plication.
39 * @param callerPackageToMatch The package name to match to.
40 */
41 public VerifiedHandler(Context context, int authRequirements,
42 String callerPackageToMatch) {
43 mContext = context;
44 mAuthRequirements = authRequirements;
45 mCallerPackageToMatch = callerPackageToMatch;
46 }
47
48 @Override
49 public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
50 Messenger client = msg.replyTo;
51 if (!mClientTrustMap.containsKey(client)) mClientTrustMap.put(client, ch eckCallerIsValid());
52 if (!mClientTrustMap.get(client)) return false;
53
54 return super.sendMessageAtTime(msg, uptimeMillis);
55 }
56
57 /**
58 * @return Whether the calling application is valid given the requirements
59 * set during construction.
60 */
61 public boolean checkCallerIsValid() {
62 if (TextUtils.isEmpty(mCallerPackageToMatch)) {
63 return ExternalAuthUtils.getInstance().isCallerValid(mContext, mAuth Requirements);
64 } else {
65 return ExternalAuthUtils.getInstance().isCallerValidForPackage(
66 mContext, mAuthRequirements, mCallerPackageToMatch);
67 }
68 }
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698