1 // 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.
5 #ifndef COMPONENTS_GCM_DRIVER_GCM_DRIVER_ANDROID_H
6 #define COMPONENTS_GCM_DRIVER_GCM_DRIVER_ANDROID_H
10 #include "base/android/scoped_java_ref.h"
11 #include "base/compiler_specific.h"
12 #include "base/macros.h"
13 #include "components/gcm_driver/gcm_driver.h"
17 // GCMDriver implementation for Android, using Android GCM APIs.
18 class GCMDriverAndroid
: public GCMDriver
{
21 ~GCMDriverAndroid() override
;
23 // Methods called from Java via JNI:
24 void OnRegisterFinished(JNIEnv
* env
,
27 jstring registration_id
,
29 void OnUnregisterFinished(JNIEnv
* env
,
33 void OnMessageReceived(JNIEnv
* env
,
38 jobjectArray data_keys_and_values
);
39 void OnMessagesDeleted(JNIEnv
* env
,
43 // Register JNI methods.
44 static bool RegisterBindings(JNIEnv
* env
);
46 // GCMDriver implementation:
47 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(
61 const std::vector
<GCMClient::AccountTokenInfo
>& account_tokens
) override
;
62 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
;
67 InstanceIDHandler
* GetInstanceIDHandler() override
;
68 void AddHeartbeatInterval(const std::string
& scope
, int interval_ms
) override
;
69 void RemoveHeartbeatInterval(const std::string
& scope
) override
;
72 // GCMDriver implementation:
73 GCMClient::Result
EnsureStarted(GCMClient::StartMode start_mode
) override
;
74 void RegisterImpl(const std::string
& app_id
,
75 const std::vector
<std::string
>& sender_ids
) override
;
76 void UnregisterImpl(const std::string
& app_id
) override
;
77 void UnregisterWithSenderIdImpl(const std::string
& app_id
,
78 const std::string
& sender_id
) override
;
79 void SendImpl(const std::string
& app_id
,
80 const std::string
& receiver_id
,
81 const GCMClient::OutgoingMessage
& message
) override
;
84 base::android::ScopedJavaGlobalRef
<jobject
> java_ref_
;
86 DISALLOW_COPY_AND_ASSIGN(GCMDriverAndroid
);
91 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_ANDROID_H