| 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 | 8 |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 151 } |
| 152 | 152 |
| 153 ForeignSessionHelper::ForeignSessionHelper(Profile* profile) | 153 ForeignSessionHelper::ForeignSessionHelper(Profile* profile) |
| 154 : profile_(profile), scoped_observer_(this) { | 154 : profile_(profile), scoped_observer_(this) { |
| 155 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> | 155 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> |
| 156 GetForProfile(profile); | 156 GetForProfile(profile); |
| 157 | 157 |
| 158 // NOTE: The ProfileSyncService can be null in tests. | 158 // NOTE: The ProfileSyncService can be null in tests. |
| 159 if (service) | 159 if (service) |
| 160 scoped_observer_.Add(service); | 160 scoped_observer_.Add(service); |
| 161 | |
| 162 registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, | |
| 163 content::Source<Profile>(profile)); | |
| 164 } | 161 } |
| 165 | 162 |
| 166 ForeignSessionHelper::~ForeignSessionHelper() { | 163 ForeignSessionHelper::~ForeignSessionHelper() { |
| 167 } | 164 } |
| 168 | 165 |
| 169 void ForeignSessionHelper::Destroy(JNIEnv* env, jobject obj) { | 166 void ForeignSessionHelper::Destroy(JNIEnv* env, jobject obj) { |
| 170 delete this; | 167 delete this; |
| 171 } | 168 } |
| 172 | 169 |
| 173 jboolean ForeignSessionHelper::IsTabSyncEnabled(JNIEnv* env, jobject obj) { | 170 jboolean ForeignSessionHelper::IsTabSyncEnabled(JNIEnv* env, jobject obj) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 191 } | 188 } |
| 192 | 189 |
| 193 void ForeignSessionHelper::FireForeignSessionCallback() { | 190 void ForeignSessionHelper::FireForeignSessionCallback() { |
| 194 if (callback_.is_null()) | 191 if (callback_.is_null()) |
| 195 return; | 192 return; |
| 196 | 193 |
| 197 JNIEnv* env = AttachCurrentThread(); | 194 JNIEnv* env = AttachCurrentThread(); |
| 198 Java_ForeignSessionCallback_onUpdated(env, callback_.obj()); | 195 Java_ForeignSessionCallback_onUpdated(env, callback_.obj()); |
| 199 } | 196 } |
| 200 | 197 |
| 201 void ForeignSessionHelper::Observe( | |
| 202 int type, const content::NotificationSource& source, | |
| 203 const content::NotificationDetails& details) { | |
| 204 switch (type) { | |
| 205 case chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED: | |
| 206 FireForeignSessionCallback(); | |
| 207 break; | |
| 208 default: | |
| 209 NOTREACHED(); | |
| 210 } | |
| 211 } | |
| 212 | |
| 213 void ForeignSessionHelper::OnSyncConfigurationCompleted() { | 198 void ForeignSessionHelper::OnSyncConfigurationCompleted() { |
| 214 FireForeignSessionCallback(); | 199 FireForeignSessionCallback(); |
| 215 } | 200 } |
| 216 | 201 |
| 202 void ForeignSessionHelper::OnForeignSessionUpdated() { |
| 203 FireForeignSessionCallback(); |
| 204 } |
| 205 |
| 217 jboolean ForeignSessionHelper::GetForeignSessions(JNIEnv* env, | 206 jboolean ForeignSessionHelper::GetForeignSessions(JNIEnv* env, |
| 218 jobject obj, | 207 jobject obj, |
| 219 jobject result) { | 208 jobject result) { |
| 220 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); | 209 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); |
| 221 if (!open_tabs) | 210 if (!open_tabs) |
| 222 return false; | 211 return false; |
| 223 | 212 |
| 224 std::vector<const sync_driver::SyncedSession*> sessions; | 213 std::vector<const sync_driver::SyncedSession*> sessions; |
| 225 if (!open_tabs->GetAllForeignSessions(&sessions)) | 214 if (!open_tabs->GetAllForeignSessions(&sessions)) |
| 226 return false; | 215 return false; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 jstring session_tag) { | 317 jstring session_tag) { |
| 329 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); | 318 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); |
| 330 if (open_tabs) | 319 if (open_tabs) |
| 331 open_tabs->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); | 320 open_tabs->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); |
| 332 } | 321 } |
| 333 | 322 |
| 334 // static | 323 // static |
| 335 bool ForeignSessionHelper::RegisterForeignSessionHelper(JNIEnv* env) { | 324 bool ForeignSessionHelper::RegisterForeignSessionHelper(JNIEnv* env) { |
| 336 return RegisterNativesImpl(env); | 325 return RegisterNativesImpl(env); |
| 337 } | 326 } |
| OLD | NEW |