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

Side by Side Diff: base/android/context_utils.cc

Issue 2847523002: Android: Remove GetApplicationContext part 4 (Closed)
Patch Set: Rebase and fix build Created 3 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
« no previous file with comments | « base/android/context_utils.h ('k') | base/android/java/src/org/chromium/base/ContextUtils.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "base/android/context_utils.h"
6
7 #include <jni.h>
8
9 #include "base/android/scoped_java_ref.h"
10 #include "base/lazy_instance.h"
11 #include "jni/ContextUtils_jni.h"
12
13 using base::android::JavaRef;
14
15 namespace base {
16 namespace android {
17
18 namespace {
19
20 // Leak the global app context, as it is used from a non-joinable worker thread
21 // that may still be running at shutdown. There is no harm in doing this.
22 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject>>::Leaky
23 g_application_context = LAZY_INSTANCE_INITIALIZER;
24
25 void SetNativeApplicationContext(JNIEnv* env, const JavaRef<jobject>& context) {
26 if (env->IsSameObject(g_application_context.Get().obj(), context.obj())) {
27 // It's safe to set the context more than once if it's the same context.
28 return;
29 }
30 DCHECK(g_application_context.Get().is_null());
31 g_application_context.Get().Reset(context);
32 }
33
34 } // namespace
35
36 const JavaRef<jobject>& GetApplicationContext() {
37 DCHECK(!g_application_context.Get().is_null());
38 return g_application_context.Get();
39 }
40
41 static void InitNativeSideApplicationContext(
42 JNIEnv* env,
43 const JavaParamRef<jclass>& clazz,
44 const JavaParamRef<jobject>& context) {
45 SetNativeApplicationContext(env, context);
46 }
47
48 bool RegisterContextUtils(JNIEnv* env) {
49 return RegisterNativesImpl(env);
50 }
51
52 } // namespace android
53 } // namespace base
OLDNEW
« no previous file with comments | « base/android/context_utils.h ('k') | base/android/java/src/org/chromium/base/ContextUtils.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698