OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/android/foreign_session_helper.h" | 5 #include "chrome/browser/android/foreign_session_helper.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 using base::android::AttachCurrentThread; | 33 using base::android::AttachCurrentThread; |
34 using base::android::ConvertUTF16ToJavaString; | 34 using base::android::ConvertUTF16ToJavaString; |
35 using base::android::ConvertUTF8ToJavaString; | 35 using base::android::ConvertUTF8ToJavaString; |
36 using base::android::ConvertJavaStringToUTF8; | 36 using base::android::ConvertJavaStringToUTF8; |
37 using sync_sessions::OpenTabsUIDelegate; | 37 using sync_sessions::OpenTabsUIDelegate; |
38 using sync_sessions::SyncedSession; | 38 using sync_sessions::SyncedSession; |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 OpenTabsUIDelegate* GetOpenTabsUIDelegate(Profile* profile) { | 42 OpenTabsUIDelegate* GetOpenTabsUIDelegate(Profile* profile) { |
43 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> | 43 browser_sync::ProfileSyncService* service = |
44 GetForProfile(profile); | 44 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
45 | 45 |
46 // Only return the delegate if it exists and it is done syncing sessions. | 46 // Only return the delegate if it exists and it is done syncing sessions. |
47 if (!service || !service->IsSyncActive()) | 47 if (!service || !service->IsSyncActive()) |
48 return NULL; | 48 return NULL; |
49 | 49 |
50 return service->GetOpenTabsUIDelegate(); | 50 return service->GetOpenTabsUIDelegate(); |
51 } | 51 } |
52 | 52 |
53 bool ShouldSkipTab(const sessions::SessionTab& session_tab) { | 53 bool ShouldSkipTab(const sessions::SessionTab& session_tab) { |
54 if (session_tab.navigations.empty()) | 54 if (session_tab.navigations.empty()) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 static jlong Init(JNIEnv* env, | 142 static jlong Init(JNIEnv* env, |
143 const JavaParamRef<jclass>& clazz, | 143 const JavaParamRef<jclass>& clazz, |
144 const JavaParamRef<jobject>& profile) { | 144 const JavaParamRef<jobject>& profile) { |
145 ForeignSessionHelper* foreign_session_helper = new ForeignSessionHelper( | 145 ForeignSessionHelper* foreign_session_helper = new ForeignSessionHelper( |
146 ProfileAndroid::FromProfileAndroid(profile)); | 146 ProfileAndroid::FromProfileAndroid(profile)); |
147 return reinterpret_cast<intptr_t>(foreign_session_helper); | 147 return reinterpret_cast<intptr_t>(foreign_session_helper); |
148 } | 148 } |
149 | 149 |
150 ForeignSessionHelper::ForeignSessionHelper(Profile* profile) | 150 ForeignSessionHelper::ForeignSessionHelper(Profile* profile) |
151 : profile_(profile), scoped_observer_(this) { | 151 : profile_(profile), scoped_observer_(this) { |
152 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> | 152 browser_sync::ProfileSyncService* service = |
153 GetForProfile(profile); | 153 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
154 | 154 |
155 // NOTE: The ProfileSyncService can be null in tests. | 155 // NOTE: The ProfileSyncService can be null in tests. |
156 if (service) | 156 if (service) |
157 scoped_observer_.Add(service); | 157 scoped_observer_.Add(service); |
158 } | 158 } |
159 | 159 |
160 ForeignSessionHelper::~ForeignSessionHelper() { | 160 ForeignSessionHelper::~ForeignSessionHelper() { |
161 } | 161 } |
162 | 162 |
163 void ForeignSessionHelper::Destroy(JNIEnv* env, | 163 void ForeignSessionHelper::Destroy(JNIEnv* env, |
164 const JavaParamRef<jobject>& obj) { | 164 const JavaParamRef<jobject>& obj) { |
165 delete this; | 165 delete this; |
166 } | 166 } |
167 | 167 |
168 jboolean ForeignSessionHelper::IsTabSyncEnabled( | 168 jboolean ForeignSessionHelper::IsTabSyncEnabled( |
169 JNIEnv* env, | 169 JNIEnv* env, |
170 const JavaParamRef<jobject>& obj) { | 170 const JavaParamRef<jobject>& obj) { |
171 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> | 171 browser_sync::ProfileSyncService* service = |
172 GetForProfile(profile_); | 172 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
173 return service && service->GetActiveDataTypes().Has(syncer::PROXY_TABS); | 173 return service && service->GetActiveDataTypes().Has(syncer::PROXY_TABS); |
174 } | 174 } |
175 | 175 |
176 void ForeignSessionHelper::TriggerSessionSync( | 176 void ForeignSessionHelper::TriggerSessionSync( |
177 JNIEnv* env, | 177 JNIEnv* env, |
178 const JavaParamRef<jobject>& obj) { | 178 const JavaParamRef<jobject>& obj) { |
179 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> | 179 browser_sync::ProfileSyncService* service = |
180 GetForProfile(profile_); | 180 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
181 if (!service) | 181 if (!service) |
182 return; | 182 return; |
183 | 183 |
184 const syncer::ModelTypeSet types(syncer::SESSIONS); | 184 const syncer::ModelTypeSet types(syncer::SESSIONS); |
185 service->TriggerRefresh(types); | 185 service->TriggerRefresh(types); |
186 } | 186 } |
187 | 187 |
188 void ForeignSessionHelper::SetOnForeignSessionCallback( | 188 void ForeignSessionHelper::SetOnForeignSessionCallback( |
189 JNIEnv* env, | 189 JNIEnv* env, |
190 const JavaParamRef<jobject>& obj, | 190 const JavaParamRef<jobject>& obj, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 const JavaParamRef<jstring>& session_tag) { | 321 const JavaParamRef<jstring>& session_tag) { |
322 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); | 322 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); |
323 if (open_tabs) | 323 if (open_tabs) |
324 open_tabs->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); | 324 open_tabs->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); |
325 } | 325 } |
326 | 326 |
327 // static | 327 // static |
328 bool ForeignSessionHelper::RegisterForeignSessionHelper(JNIEnv* env) { | 328 bool ForeignSessionHelper::RegisterForeignSessionHelper(JNIEnv* env) { |
329 return RegisterNativesImpl(env); | 329 return RegisterNativesImpl(env); |
330 } | 330 } |
OLD | NEW |