| 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 #ifndef CHROME_BROWSER_ANDROID_FOREIGN_SESSION_HELPER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_FOREIGN_SESSION_HELPER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_FOREIGN_SESSION_HELPER_H_ | 6 #define CHROME_BROWSER_ANDROID_FOREIGN_SESSION_HELPER_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 | 9 |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/scoped_observer.h" | 11 #include "base/scoped_observer.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "components/sync_driver/sync_service_observer.h" | 13 #include "components/sync_driver/sync_service_observer.h" |
| 14 #include "content/public/browser/notification_observer.h" | |
| 15 #include "content/public/browser/notification_registrar.h" | |
| 16 | 14 |
| 17 using base::android::ScopedJavaLocalRef; | 15 using base::android::ScopedJavaLocalRef; |
| 18 | 16 |
| 19 struct SessionWindow; | 17 struct SessionWindow; |
| 20 | 18 |
| 21 namespace browser_sync { | 19 namespace browser_sync { |
| 22 struct SyncedSession; | 20 struct SyncedSession; |
| 23 } // namespace browser_sync | 21 } // namespace browser_sync |
| 24 | 22 |
| 25 namespace sync_driver { | 23 namespace sync_driver { |
| 26 class SyncService; | 24 class SyncService; |
| 27 } // namespace sync_driver | 25 } // namespace sync_driver |
| 28 | 26 |
| 29 class ForeignSessionHelper : public content::NotificationObserver, | 27 class ForeignSessionHelper : public sync_driver::SyncServiceObserver { |
| 30 public sync_driver::SyncServiceObserver { | |
| 31 public: | 28 public: |
| 32 explicit ForeignSessionHelper(Profile* profile); | 29 explicit ForeignSessionHelper(Profile* profile); |
| 33 void Destroy(JNIEnv* env, jobject obj); | 30 void Destroy(JNIEnv* env, jobject obj); |
| 34 jboolean IsTabSyncEnabled(JNIEnv* env, jobject obj); | 31 jboolean IsTabSyncEnabled(JNIEnv* env, jobject obj); |
| 35 void TriggerSessionSync(JNIEnv* env, jobject obj); | 32 void TriggerSessionSync(JNIEnv* env, jobject obj); |
| 36 void SetOnForeignSessionCallback(JNIEnv* env, jobject obj, jobject callback); | 33 void SetOnForeignSessionCallback(JNIEnv* env, jobject obj, jobject callback); |
| 37 jboolean GetForeignSessions(JNIEnv* env, jobject obj, jobject result); | 34 jboolean GetForeignSessions(JNIEnv* env, jobject obj, jobject result); |
| 38 jboolean OpenForeignSessionTab(JNIEnv* env, | 35 jboolean OpenForeignSessionTab(JNIEnv* env, |
| 39 jobject obj, | 36 jobject obj, |
| 40 jobject j_tab, | 37 jobject j_tab, |
| 41 jstring session_tag, | 38 jstring session_tag, |
| 42 jint tab_id, | 39 jint tab_id, |
| 43 jint disposition); | 40 jint disposition); |
| 44 void DeleteForeignSession(JNIEnv* env, jobject obj, jstring session_tag); | 41 void DeleteForeignSession(JNIEnv* env, jobject obj, jstring session_tag); |
| 45 | 42 |
| 46 // NotificationObserver implemenation | |
| 47 void Observe(int type, | |
| 48 const content::NotificationSource& source, | |
| 49 const content::NotificationDetails& details) override; | |
| 50 | |
| 51 // sync_driver::SyncServiceObserver implementation | 43 // sync_driver::SyncServiceObserver implementation |
| 52 void OnStateChanged() override {} | 44 void OnStateChanged() override {} |
| 53 void OnSyncConfigurationCompleted() override; | 45 void OnSyncConfigurationCompleted() override; |
| 46 void OnForeignSessionUpdated() override; |
| 54 | 47 |
| 55 static bool RegisterForeignSessionHelper(JNIEnv* env); | 48 static bool RegisterForeignSessionHelper(JNIEnv* env); |
| 56 | 49 |
| 57 private: | 50 private: |
| 58 ~ForeignSessionHelper() override; | 51 ~ForeignSessionHelper() override; |
| 59 | 52 |
| 60 // Fires |callback_| if it is not null. | 53 // Fires |callback_| if it is not null. |
| 61 void FireForeignSessionCallback(); | 54 void FireForeignSessionCallback(); |
| 62 | 55 |
| 63 Profile* profile_; // weak | 56 Profile* profile_; // weak |
| 64 base::android::ScopedJavaGlobalRef<jobject> callback_; | 57 base::android::ScopedJavaGlobalRef<jobject> callback_; |
| 65 content::NotificationRegistrar registrar_; | |
| 66 ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver> | 58 ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver> |
| 67 scoped_observer_; | 59 scoped_observer_; |
| 68 | 60 |
| 69 DISALLOW_COPY_AND_ASSIGN(ForeignSessionHelper); | 61 DISALLOW_COPY_AND_ASSIGN(ForeignSessionHelper); |
| 70 }; | 62 }; |
| 71 | 63 |
| 72 #endif // CHROME_BROWSER_ANDROID_FOREIGN_SESSION_HELPER_H_ | 64 #endif // CHROME_BROWSER_ANDROID_FOREIGN_SESSION_HELPER_H_ |
| OLD | NEW |