blob: 41c47b5f6999fe9d613668685ba9b8f7439a4a76 [file] [log] [blame]
[email protected]d8e44d22014-05-15 23:14:051// 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#ifndef COMPONENTS_GCM_DRIVER_GCM_DRIVER_ANDROID_H
6#define COMPONENTS_GCM_DRIVER_GCM_DRIVER_ANDROID_H
7
8#include <jni.h>
9
[email protected]385c64ef2014-06-03 23:16:5410#include "base/android/scoped_java_ref.h"
[email protected]21b77652014-05-31 01:21:0911#include "base/compiler_specific.h"
12#include "base/macros.h"
13#include "components/gcm_driver/gcm_driver.h"
14
[email protected]d8e44d22014-05-15 23:14:0515namespace gcm {
16
[email protected]385c64ef2014-06-03 23:16:5417// GCMDriver implementation for Android, using Android GCM APIs.
[email protected]21b77652014-05-31 01:21:0918class GCMDriverAndroid : public GCMDriver {
[email protected]d8e44d22014-05-15 23:14:0519 public:
[email protected]21b77652014-05-31 01:21:0920 GCMDriverAndroid();
dchenge27b1ef2015-02-04 23:34:1121 ~GCMDriverAndroid() override;
[email protected]21b77652014-05-31 01:21:0922
[email protected]385c64ef2014-06-03 23:16:5423 // Methods called from Java via JNI:
24 void OnRegisterFinished(JNIEnv* env,
25 jobject obj,
26 jstring app_id,
27 jstring registration_id,
28 jboolean success);
29 void OnUnregisterFinished(JNIEnv* env,
30 jobject obj,
31 jstring app_id,
32 jboolean success);
33 void OnMessageReceived(JNIEnv* env,
34 jobject obj,
35 jstring app_id,
36 jstring sender_id,
37 jstring collapse_key,
38 jobjectArray data_keys_and_values);
39 void OnMessagesDeleted(JNIEnv* env,
40 jobject obj,
41 jstring app_id);
42
[email protected]21b77652014-05-31 01:21:0943 // Register JNI methods.
[email protected]d8e44d22014-05-15 23:14:0544 static bool RegisterBindings(JNIEnv* env);
[email protected]21b77652014-05-31 01:21:0945
[email protected]c27c10792014-06-05 15:27:2346 // GCMDriver implementation:
dchenge27b1ef2015-02-04 23:34:1147 void OnSignedIn() override;
48 void OnSignedOut() override;
49 void Enable() override;
50 void AddConnectionObserver(GCMConnectionObserver* observer) override;
51 void RemoveConnectionObserver(GCMConnectionObserver* observer) override;
52 void Disable() override;
53 GCMClient* GetGCMClientForTesting() const override;
54 bool IsStarted() const override;
55 bool IsConnected() const override;
56 void GetGCMStatistics(const GetGCMStatisticsCallback& callback,
57 bool clear_logs) override;
58 void SetGCMRecording(const GetGCMStatisticsCallback& callback,
59 bool recording) override;
60 void SetAccountTokens(
mostynbfe59f482014-10-06 15:04:4661 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) override;
dchenge27b1ef2015-02-04 23:34:1162 void UpdateAccountMapping(const AccountMapping& account_mapping) override;
63 void RemoveAccountMapping(const std::string& account_id) override;
64 base::Time GetLastTokenFetchTime() override;
65 void SetLastTokenFetchTime(const base::Time& time) override;
66 void WakeFromSuspendForHeartbeat(bool wake) override;
[email protected]c27c10792014-06-05 15:27:2367
68 protected:
69 // GCMDriver implementation:
dchenge27b1ef2015-02-04 23:34:1170 GCMClient::Result EnsureStarted(GCMClient::StartMode start_mode) override;
71 void RegisterImpl(const std::string& app_id,
72 const std::vector<std::string>& sender_ids) override;
73 void UnregisterImpl(const std::string& app_id) override;
johnme07b355a2015-02-19 17:00:5174 void UnregisterWithSenderIdImpl(const std::string& app_id,
75 const std::string& sender_id) override;
dchenge27b1ef2015-02-04 23:34:1176 void SendImpl(const std::string& app_id,
77 const std::string& receiver_id,
78 const GCMClient::OutgoingMessage& message) override;
[email protected]c27c10792014-06-05 15:27:2379
[email protected]21b77652014-05-31 01:21:0980 private:
[email protected]385c64ef2014-06-03 23:16:5481 base::android::ScopedJavaGlobalRef<jobject> java_ref_;
82
[email protected]21b77652014-05-31 01:21:0983 DISALLOW_COPY_AND_ASSIGN(GCMDriverAndroid);
[email protected]d8e44d22014-05-15 23:14:0584};
85
86} // namespace gcm
87
[email protected]21b77652014-05-31 01:21:0988#endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_ANDROID_H