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 virtual ~GCMDriverAndroid();
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 virtual void OnSignedIn() override
;
48 virtual void OnSignedOut() override
;
49 virtual void Enable() override
;
50 virtual void AddConnectionObserver(GCMConnectionObserver
* observer
) override
;
51 virtual void RemoveConnectionObserver(
52 GCMConnectionObserver
* observer
) override
;
53 virtual void Disable() override
;
54 virtual GCMClient
* GetGCMClientForTesting() const override
;
55 virtual bool IsStarted() const override
;
56 virtual bool IsConnected() const override
;
57 virtual void GetGCMStatistics(const GetGCMStatisticsCallback
& callback
,
58 bool clear_logs
) override
;
59 virtual void SetGCMRecording(const GetGCMStatisticsCallback
& callback
,
60 bool recording
) override
;
61 virtual void SetAccountTokens(
62 const std::vector
<GCMClient::AccountTokenInfo
>& account_tokens
) override
;
63 virtual void UpdateAccountMapping(
64 const AccountMapping
& account_mapping
) override
;
65 virtual void RemoveAccountMapping(const std::string
& account_id
) override
;
66 virtual base::Time
GetLastTokenFetchTime() override
;
67 virtual void SetLastTokenFetchTime(const base::Time
& time
) override
;
68 virtual void WakeFromSuspendForHeartbeat(bool wake
) override
;
71 // GCMDriver implementation:
72 virtual GCMClient::Result
EnsureStarted(
73 GCMClient::StartMode start_mode
) override
;
74 virtual void RegisterImpl(
75 const std::string
& app_id
,
76 const std::vector
<std::string
>& sender_ids
) override
;
77 virtual void UnregisterImpl(const std::string
& app_id
) override
;
78 virtual void SendImpl(const std::string
& app_id
,
79 const std::string
& receiver_id
,
80 const GCMClient::OutgoingMessage
& message
) override
;
83 base::android::ScopedJavaGlobalRef
<jobject
> java_ref_
;
85 DISALLOW_COPY_AND_ASSIGN(GCMDriverAndroid
);
90 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_ANDROID_H