summaryrefslogtreecommitdiffstats
path: root/chrome/browser/android/foreign_session_helper.h
blob: 501fa121aad4e85baba073e733aeec8a6d9579f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ANDROID_FOREIGN_SESSION_HELPER_H_
#define CHROME_BROWSER_ANDROID_FOREIGN_SESSION_HELPER_H_

#include <jni.h>

#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "components/sync_driver/sync_service_observer.h"

using base::android::ScopedJavaLocalRef;

struct SessionWindow;

namespace browser_sync {
struct SyncedSession;
}  // namespace browser_sync

namespace sync_driver {
class SyncService;
}  // namespace sync_driver

class ForeignSessionHelper : public sync_driver::SyncServiceObserver {
 public:
  explicit ForeignSessionHelper(Profile* profile);
  void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
  jboolean IsTabSyncEnabled(JNIEnv* env,
                            const base::android::JavaParamRef<jobject>& obj);
  void TriggerSessionSync(JNIEnv* env,
                          const base::android::JavaParamRef<jobject>& obj);
  void SetOnForeignSessionCallback(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& obj,
      const base::android::JavaParamRef<jobject>& callback);
  jboolean GetForeignSessions(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& obj,
      const base::android::JavaParamRef<jobject>& result);
  jboolean OpenForeignSessionTab(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& obj,
      const base::android::JavaParamRef<jobject>& j_tab,
      const base::android::JavaParamRef<jstring>& session_tag,
      jint tab_id,
      jint disposition);
  void DeleteForeignSession(
      JNIEnv* env,
      const base::android::JavaParamRef<jobject>& obj,
      const base::android::JavaParamRef<jstring>& session_tag);

  // sync_driver::SyncServiceObserver implementation
  void OnStateChanged() override {}
  void OnSyncConfigurationCompleted() override;
  void OnForeignSessionUpdated() override;

  static bool RegisterForeignSessionHelper(JNIEnv* env);

 private:
  ~ForeignSessionHelper() override;

  // Fires |callback_| if it is not null.
  void FireForeignSessionCallback();

  Profile* profile_;  // weak
  base::android::ScopedJavaGlobalRef<jobject> callback_;
  ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver>
      scoped_observer_;

  DISALLOW_COPY_AND_ASSIGN(ForeignSessionHelper);
};

#endif  // CHROME_BROWSER_ANDROID_FOREIGN_SESSION_HELPER_H_