OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ |
6 #define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | |
9 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
11 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
12 #include "chrome/browser/extensions/api/push_messaging/invalidation_handler_obse rver.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati on_handler_observer.h" | |
15 #include "content/public/browser/notification_observer.h" | |
16 #include "content/public/browser/notification_registrar.h" | |
13 | 17 |
14 class Profile; | 18 class Profile; |
15 | 19 |
16 namespace extensions { | 20 namespace extensions { |
17 | 21 |
22 class PushMessagingInvalidationMapper; | |
23 | |
18 // Observes a single InvalidationHandler and generates onMessage events. | 24 // Observes a single InvalidationHandler and generates onMessage events. |
19 class PushMessagingEventRouter : public InvalidationHandlerObserver { | 25 class PushMessagingEventRouter |
26 : public PushMessagingInvalidationHandlerObserver, | |
27 public content::NotificationObserver { | |
20 public: | 28 public: |
21 explicit PushMessagingEventRouter(Profile* profile); | 29 explicit PushMessagingEventRouter(Profile* profile); |
22 virtual ~PushMessagingEventRouter(); | 30 virtual ~PushMessagingEventRouter(); |
23 | 31 |
24 void Init(); | 32 void Init(); |
33 void Shutdown(); | |
34 | |
35 PushMessagingInvalidationMapper* GetMapperForTest() const { | |
36 return handler_.get(); | |
37 } | |
38 void SetMapperForTest(scoped_ptr<PushMessagingInvalidationMapper> mapper); | |
39 void TriggerMessageForTest(const std::string& extension_id, | |
40 int subchannel, | |
41 const std::string& payload); | |
25 | 42 |
26 private: | 43 private: |
27 FRIEND_TEST_ALL_PREFIXES(PushMessagingApiTest, EventDispatch); | |
28 | |
29 // InvalidationHandlerObserver implementation. | 44 // InvalidationHandlerObserver implementation. |
30 virtual void OnMessage(const std::string& extension_id, | 45 virtual void OnMessage(const std::string& extension_id, |
31 int subchannel, | 46 int subchannel, |
32 const std::string& payload) OVERRIDE; | 47 const std::string& payload) OVERRIDE; |
33 | 48 |
49 // content::NotificationObserver implementation. | |
50 virtual void Observe(int type, | |
51 const content::NotificationSource& source, | |
52 const content::NotificationDetails& details) OVERRIDE; | |
53 | |
54 content::NotificationRegistrar registrar_; | |
34 Profile* profile_; | 55 Profile* profile_; |
akalin
2012/08/20 20:35:01
const pointer?
dcheng
2012/08/20 20:58:21
Done.
| |
56 scoped_ptr<PushMessagingInvalidationMapper> handler_; | |
35 | 57 |
36 DISALLOW_COPY_AND_ASSIGN(PushMessagingEventRouter); | 58 DISALLOW_COPY_AND_ASSIGN(PushMessagingEventRouter); |
37 }; | 59 }; |
38 | 60 |
39 } // namespace extension | 61 } // namespace extension |
40 | 62 |
41 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ | 63 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ |
OLD | NEW |