• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
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 
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"
14 
15 namespace gcm {
16 
17 // GCMDriver implementation for Android, using Android GCM APIs.
18 class GCMDriverAndroid : public GCMDriver {
19  public:
20   GCMDriverAndroid();
21   virtual ~GCMDriverAndroid();
22 
23   // 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 
43   // Register JNI methods.
44   static bool RegisterBindings(JNIEnv* env);
45 
46   // GCMDriver implementation:
47   virtual void OnSignedIn() OVERRIDE;
48   virtual void Purge() OVERRIDE;
49   virtual void Enable() OVERRIDE;
50   virtual void Disable() OVERRIDE;
51   virtual GCMClient* GetGCMClientForTesting() const OVERRIDE;
52   virtual bool IsStarted() const OVERRIDE;
53   virtual bool IsConnected() const OVERRIDE;
54   virtual void GetGCMStatistics(const GetGCMStatisticsCallback& callback,
55                                 bool clear_logs) OVERRIDE;
56   virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
57                                bool recording) OVERRIDE;
58 
59  protected:
60   // GCMDriver implementation:
61   virtual GCMClient::Result EnsureStarted() OVERRIDE;
62   virtual void RegisterImpl(
63       const std::string& app_id,
64       const std::vector<std::string>& sender_ids) OVERRIDE;
65   virtual void UnregisterImpl(const std::string& app_id) OVERRIDE;
66   virtual void SendImpl(const std::string& app_id,
67                         const std::string& receiver_id,
68                         const GCMClient::OutgoingMessage& message) OVERRIDE;
69 
70  private:
71   base::android::ScopedJavaGlobalRef<jobject> java_ref_;
72 
73   DISALLOW_COPY_AND_ASSIGN(GCMDriverAndroid);
74 };
75 
76 }  // namespace gcm
77 
78 #endif  // COMPONENTS_GCM_DRIVER_GCM_DRIVER_ANDROID_H
79