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 "base/memory/ref_counted.h"
14 #include "components/gcm_driver/gcm_driver.h"
18 class SequencedTaskRunner
;
23 // GCMDriver implementation for Android, using Android GCM APIs.
24 class GCMDriverAndroid
: public GCMDriver
{
27 const base::FilePath
& store_path
,
28 const scoped_refptr
<base::SequencedTaskRunner
>& blocking_task_runner
);
29 ~GCMDriverAndroid() override
;
31 // Methods called from Java via JNI:
32 void OnRegisterFinished(JNIEnv
* env
,
35 jstring registration_id
,
37 void OnUnregisterFinished(JNIEnv
* env
,
41 void OnMessageReceived(JNIEnv
* env
,
47 jobjectArray data_keys_and_values
);
48 void OnMessagesDeleted(JNIEnv
* env
,
52 // Register JNI methods.
53 static bool RegisterBindings(JNIEnv
* env
);
55 // GCMDriver implementation:
56 void OnSignedIn() override
;
57 void OnSignedOut() override
;
58 void Enable() override
;
59 void AddConnectionObserver(GCMConnectionObserver
* observer
) override
;
60 void RemoveConnectionObserver(GCMConnectionObserver
* observer
) override
;
61 void Disable() override
;
62 GCMClient
* GetGCMClientForTesting() const override
;
63 bool IsStarted() const override
;
64 bool IsConnected() const override
;
65 void GetGCMStatistics(const GetGCMStatisticsCallback
& callback
,
66 bool clear_logs
) override
;
67 void SetGCMRecording(const GetGCMStatisticsCallback
& callback
,
68 bool recording
) override
;
69 void SetAccountTokens(
70 const std::vector
<GCMClient::AccountTokenInfo
>& account_tokens
) override
;
71 void UpdateAccountMapping(const AccountMapping
& account_mapping
) override
;
72 void RemoveAccountMapping(const std::string
& account_id
) override
;
73 base::Time
GetLastTokenFetchTime() override
;
74 void SetLastTokenFetchTime(const base::Time
& time
) override
;
75 void WakeFromSuspendForHeartbeat(bool wake
) override
;
76 InstanceIDHandler
* GetInstanceIDHandler() override
;
77 void AddHeartbeatInterval(const std::string
& scope
, int interval_ms
) override
;
78 void RemoveHeartbeatInterval(const std::string
& scope
) override
;
81 // GCMDriver implementation:
82 GCMClient::Result
EnsureStarted(GCMClient::StartMode start_mode
) override
;
83 void RegisterImpl(const std::string
& app_id
,
84 const std::vector
<std::string
>& sender_ids
) override
;
85 void UnregisterImpl(const std::string
& app_id
) override
;
86 void UnregisterWithSenderIdImpl(const std::string
& app_id
,
87 const std::string
& sender_id
) override
;
88 void SendImpl(const std::string
& app_id
,
89 const std::string
& receiver_id
,
90 const OutgoingMessage
& message
) override
;
93 base::android::ScopedJavaGlobalRef
<jobject
> java_ref_
;
95 DISALLOW_COPY_AND_ASSIGN(GCMDriverAndroid
);
100 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_ANDROID_H