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

Side by Side Diff: chrome/browser/ui/android/tab_model/tab_model_jni_bridge.cc

Issue 583373002: Break apart the TabModelBase's JNI calls into its own class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Breaking apart the bridge Created 6 years, 2 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 2014 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 "chrome/browser/ui/android/tab_model/tab_model_jni_bridge.h"
6
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_weak_ref.h"
9 #include "chrome/browser/android/tab_android.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_android.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/ui/android/tab_model/tab_model_list.h"
15 #include "jni/TabModelJniBridge_jni.h"
16
17 using base::android::AttachCurrentThread;
18
19 namespace {
20
21 static Profile* FindProfile(jboolean is_incognito) {
22 if (g_browser_process == NULL ||
23 g_browser_process->profile_manager() == NULL) {
24 LOG(ERROR) << "Browser process or profile manager not initialized";
25 return NULL;
26 }
27 Profile* profile = ProfileManager::GetActiveUserProfile();
28 if (is_incognito)
29 return profile->GetOffTheRecordProfile();
30 return profile;
31 }
32
33 } // namespace
34
35 TabModelJniBridge::TabModelJniBridge(JNIEnv* env,
36 jobject jobj,
37 bool is_incognito)
38 : TabModel(FindProfile(is_incognito)),
39 java_object_(env, env->NewWeakGlobalRef(jobj)) {
40 TabModelList::AddTabModel(this);
41 Java_TabModelJniBridge_setNativePtr(env,
42 jobj,
43 reinterpret_cast<intptr_t>(this));
44 }
45
46 void TabModelJniBridge::Destroy(JNIEnv* env, jobject obj) {
47 TabModelList::RemoveTabModel(this);
David Trainor- moved to gerrit 2014/10/09 20:43:42 Should this go in the destructor? Might make more
gone 2014/10/10 22:39:19 Done.
48 delete this;
49 }
50
51 ScopedJavaLocalRef<jobject> TabModelJniBridge::GetProfileAndroid(JNIEnv* env,
52 jobject obj) {
53 ProfileAndroid* profile_android = ProfileAndroid::FromProfile(GetProfile());
54 if (!profile_android)
55 return ScopedJavaLocalRef<jobject>();
56 return profile_android->GetJavaObject();
57 }
58
59 void TabModelJniBridge::TabAddedToModel(JNIEnv* env,
60 jobject obj,
61 jobject jtab) {
62 TabAndroid* tab = TabAndroid::GetNativeTab(env, jtab);
63
64 // Tab#initialize() should have been called by now otherwise we can't push
65 // the window id.
66 DCHECK(tab);
67
68 tab->SetWindowSessionID(GetSessionId());
69 }
70
71 int TabModelJniBridge::GetTabCount() const {
72 JNIEnv* env = AttachCurrentThread();
73 return Java_TabModelJniBridge_getCount(env, java_object_.get(env).obj());
74 }
75
76 int TabModelJniBridge::GetActiveIndex() const {
77 JNIEnv* env = AttachCurrentThread();
78 return Java_TabModelJniBridge_index(env, java_object_.get(env).obj());
79 }
80
81 void TabModelJniBridge::CreateTab(content::WebContents* web_contents,
82 int parent_tab_id) {
83 JNIEnv* env = AttachCurrentThread();
84 Java_TabModelJniBridge_createTabWithNativeContents(
85 env, java_object_.get(env).obj(),
86 web_contents->GetBrowserContext()->IsOffTheRecord(),
87 reinterpret_cast<intptr_t>(web_contents), parent_tab_id);
88 }
89
90 content::WebContents* TabModelJniBridge::GetWebContentsAt(int index) const {
91 TabAndroid* tab = GetTabAt(index);
92 return tab == NULL ? NULL : tab->web_contents();
93 }
94
95 void TabModelJniBridge::SetActiveIndex(int index) {
96 JNIEnv* env = AttachCurrentThread();
97 Java_TabModelJniBridge_setIndex(env, java_object_.get(env).obj(), index);
98 }
99
100 bool TabModelJniBridge::IsSessionRestoreInProgress() const {
101 JNIEnv* env = AttachCurrentThread();
102 return Java_TabModelJniBridge_isSessionRestoreInProgress(
103 env, java_object_.get(env).obj());
104 }
105
106 void TabModelJniBridge::BroadcastSessionRestoreComplete(JNIEnv* env,
107 jobject obj) {
108 TabModel::BroadcastSessionRestoreComplete();
109 }
110
111 TabModelJniBridge::~TabModelJniBridge() {
112 JNIEnv* env = AttachCurrentThread();
113 Java_TabModelJniBridge_clearNativePtr(env, java_object_.get(env).obj());
114 }
115
116 bool TabModelJniBridge::Register(JNIEnv* env) {
117 return RegisterNativesImpl(env);
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698