OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_EXTENSIONS_API_GCM_GCM_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_GCM_GCM_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_GCM_GCM_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_GCM_GCM_API_H_ |
7 | 7 |
8 #include "chrome/browser/services/gcm/gcm_event_router.h" | 8 #include "chrome/browser/services/gcm/gcm_event_router.h" |
9 #include "chrome/common/extensions/api/gcm.h" | 9 #include "chrome/common/extensions/api/gcm.h" |
| 10 #include "extensions/browser/event_router.h" |
10 #include "extensions/browser/extension_function.h" | 11 #include "extensions/browser/extension_function.h" |
11 #include "google_apis/gcm/gcm_client.h" | 12 #include "google_apis/gcm/gcm_client.h" |
12 | 13 |
13 namespace gcm { | 14 namespace gcm { |
14 class GCMProfileService; | 15 class GCMProfileService; |
15 } // namespace gcm | 16 } // namespace gcm |
16 | 17 |
17 class Profile; | 18 class Profile; |
18 | 19 |
19 namespace extensions { | 20 namespace extensions { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 69 |
69 private: | 70 private: |
70 void CompleteFunctionWithResult(const std::string& message_id, | 71 void CompleteFunctionWithResult(const std::string& message_id, |
71 gcm::GCMClient::Result result); | 72 gcm::GCMClient::Result result); |
72 | 73 |
73 // Validates that message data do not carry invalid keys and fit into | 74 // Validates that message data do not carry invalid keys and fit into |
74 // allowable size limits. | 75 // allowable size limits. |
75 bool ValidateMessageData(const gcm::GCMClient::MessageData& data) const; | 76 bool ValidateMessageData(const gcm::GCMClient::MessageData& data) const; |
76 }; | 77 }; |
77 | 78 |
78 class GcmJsEventRouter : public gcm::GCMEventRouter { | 79 class GcmJsEventRouter : public gcm::GCMEventRouter, |
| 80 public EventRouter::Observer { |
79 public: | 81 public: |
80 explicit GcmJsEventRouter(Profile* profile); | 82 explicit GcmJsEventRouter(Profile* profile); |
81 | 83 |
82 virtual ~GcmJsEventRouter(); | 84 virtual ~GcmJsEventRouter(); |
83 | 85 |
84 // GCMEventRouter: | 86 // GCMEventRouter: |
85 virtual void OnMessage( | 87 virtual void OnMessage( |
86 const std::string& app_id, | 88 const std::string& app_id, |
87 const gcm::GCMClient::IncomingMessage& message) OVERRIDE; | 89 const gcm::GCMClient::IncomingMessage& message) OVERRIDE; |
88 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; | 90 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; |
89 virtual void OnSendError(const std::string& app_id, | 91 virtual void OnSendError(const std::string& app_id, |
90 const std::string& message_id, | 92 const std::string& message_id, |
91 gcm::GCMClient::Result result) OVERRIDE; | 93 gcm::GCMClient::Result result) OVERRIDE; |
92 | 94 |
| 95 // EventRouter::Observer: |
| 96 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; |
| 97 |
93 private: | 98 private: |
94 // The application we route the event to is running in context of the | 99 // The application we route the event to is running in context of the |
95 // |profile_| and the latter outlives the event router. | 100 // |profile_| and the latter outlives the event router. |
96 Profile* profile_; | 101 Profile* profile_; |
97 }; | 102 }; |
98 | 103 |
99 } // namespace extensions | 104 } // namespace extensions |
100 | 105 |
101 #endif // CHROME_BROWSER_EXTENSIONS_API_GCM_GCM_API_H_ | 106 #endif // CHROME_BROWSER_EXTENSIONS_API_GCM_GCM_API_H_ |
OLD | NEW |