Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: components/gcm_driver/gcm_driver.h

Issue 324913004: Skeleton GCMAppHandler for Push API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/gcm_driver/gcm_app_handler.h ('k') | components/gcm_driver/gcm_driver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ 5 #ifndef COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_
6 #define COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ 6 #define COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set>
9 #include <string> 10 #include <string>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/callback.h" 13 #include "base/callback.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
15 #include "components/gcm_driver/default_gcm_app_handler.h" 16 #include "components/gcm_driver/default_gcm_app_handler.h"
16 #include "components/gcm_driver/gcm_client.h" 17 #include "components/gcm_driver/gcm_client.h"
17 18
18 namespace gcm { 19 namespace gcm {
19 20
20 class GCMAppHandler; 21 class GCMAppHandler;
21 22
22 // Bridge between GCM users in Chrome and the platform-specific implementation. 23 // Bridge between GCM users in Chrome and the platform-specific implementation.
23 class GCMDriver { 24 class GCMDriver {
24 public: 25 public:
25 typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap; 26 typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap;
27 typedef std::set<GCMWildcardAppHandler*> GCMWildcardAppHandlerSet;
26 typedef base::Callback<void(const std::string& registration_id, 28 typedef base::Callback<void(const std::string& registration_id,
27 GCMClient::Result result)> RegisterCallback; 29 GCMClient::Result result)> RegisterCallback;
28 typedef base::Callback<void(const std::string& message_id, 30 typedef base::Callback<void(const std::string& message_id,
29 GCMClient::Result result)> SendCallback; 31 GCMClient::Result result)> SendCallback;
30 typedef base::Callback<void(GCMClient::Result result)> UnregisterCallback; 32 typedef base::Callback<void(GCMClient::Result result)> UnregisterCallback;
31 typedef base::Callback<void(const GCMClient::GCMStatistics& stats)> 33 typedef base::Callback<void(const GCMClient::GCMStatistics& stats)>
32 GetGCMStatisticsCallback; 34 GetGCMStatisticsCallback;
33 35
34 GCMDriver(); 36 GCMDriver();
35 virtual ~GCMDriver(); 37 virtual ~GCMDriver();
(...skipping 19 matching lines...) Expand all
55 // |app_id|: application ID. 57 // |app_id|: application ID.
56 // |receiver_id|: registration ID of the receiver party. 58 // |receiver_id|: registration ID of the receiver party.
57 // |message|: message to be sent. 59 // |message|: message to be sent.
58 // |callback|: to be called once the asynchronous operation is done. 60 // |callback|: to be called once the asynchronous operation is done.
59 void Send(const std::string& app_id, 61 void Send(const std::string& app_id,
60 const std::string& receiver_id, 62 const std::string& receiver_id,
61 const GCMClient::OutgoingMessage& message, 63 const GCMClient::OutgoingMessage& message,
62 const SendCallback& callback); 64 const SendCallback& callback);
63 65
64 const GCMAppHandlerMap& app_handlers() const { return app_handlers_; } 66 const GCMAppHandlerMap& app_handlers() const { return app_handlers_; }
67 const GCMWildcardAppHandlerSet& wildcard_app_handlers() const {
68 return wildcard_app_handlers_;
69 }
65 70
66 // This method must be called before destroying the GCMDriver. Once it has 71 // This method must be called before destroying the GCMDriver. Once it has
67 // been called, no other GCMDriver methods may be used. 72 // been called, no other GCMDriver methods may be used.
68 virtual void Shutdown(); 73 virtual void Shutdown();
69 74
70 // Adds a handler for a given app. 75 // Add/remove the handler for a given app.
71 virtual void AddAppHandler(const std::string& app_id, GCMAppHandler* handler); 76 virtual void AddAppHandler(const std::string& app_id, GCMAppHandler* handler);
77 virtual void RemoveAppHandler(const std::string& app_id);
72 78
73 // Remove the handler for a given app. 79 // Add/remove a wildcard app handler. These will be asked if they match when
74 virtual void RemoveAppHandler(const std::string& app_id); 80 // there is no matching non-wildcard handler for a given app.
81 virtual void AddWildcardAppHandler(GCMWildcardAppHandler* handler);
jianli 2014/06/13 22:51:47 Having 2 versions of adding app handlers seems to
82 virtual void RemoveWildcardAppHandler(GCMWildcardAppHandler* handler);
75 83
76 // Enables/disables GCM service. 84 // Enables/disables GCM service.
77 virtual void Enable() = 0; 85 virtual void Enable() = 0;
78 virtual void Disable() = 0; 86 virtual void Disable() = 0;
79 87
80 // For testing purpose. Always NULL on Android. 88 // For testing purpose. Always NULL on Android.
81 virtual GCMClient* GetGCMClientForTesting() const = 0; 89 virtual GCMClient* GetGCMClientForTesting() const = 0;
82 90
83 // Returns true if the service was started. 91 // Returns true if the service was started.
84 virtual bool IsStarted() const = 0; 92 virtual bool IsStarted() const = 0;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // Callback map (from app_id to callback) for Unregister. 155 // Callback map (from app_id to callback) for Unregister.
148 std::map<std::string, UnregisterCallback> unregister_callbacks_; 156 std::map<std::string, UnregisterCallback> unregister_callbacks_;
149 157
150 // Callback map (from <app_id, message_id> to callback) for Send. 158 // Callback map (from <app_id, message_id> to callback) for Send.
151 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; 159 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_;
152 160
153 // App handler map (from app_id to handler pointer). 161 // App handler map (from app_id to handler pointer).
154 // The handler is not owned. 162 // The handler is not owned.
155 GCMAppHandlerMap app_handlers_; 163 GCMAppHandlerMap app_handlers_;
156 164
165 // Wildcard app handlers set. These are not owned either.
166 GCMWildcardAppHandlerSet wildcard_app_handlers_;
167
157 // The default handler when no app handler can be found in the map. 168 // The default handler when no app handler can be found in the map.
158 DefaultGCMAppHandler default_app_handler_; 169 DefaultGCMAppHandler default_app_handler_;
159 170
160 DISALLOW_COPY_AND_ASSIGN(GCMDriver); 171 DISALLOW_COPY_AND_ASSIGN(GCMDriver);
161 }; 172 };
162 173
163 } // namespace gcm 174 } // namespace gcm
164 175
165 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_ 176 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_H_
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_app_handler.h ('k') | components/gcm_driver/gcm_driver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698