Chromium Code Reviews| 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 // This file includes the JavaScript interface for Push Messaging | |
|
dcheng
2012/08/16 19:12:43
Unnecessary comment.
Pete Williamson
2012/08/19 22:05:14
Done.
| |
| 6 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ | 7 #ifndef CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ | 8 #define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ |
| 7 | 9 |
| 8 #include <string> | 10 #include <string> |
| 9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 11 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 12 #include "chrome/browser/extensions/api/push_messaging/invalidation_handler_obse rver.h" | 14 #include "chrome/browser/extensions/api/push_messaging/invalidation_handler_obse rver.h" |
| 15 #include "chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetche r.h" | |
| 16 #include "chrome/browser/extensions/extension_function.h" | |
| 13 | 17 |
| 14 class Profile; | 18 class Profile; |
| 15 | 19 |
| 16 namespace extensions { | 20 namespace extensions { |
| 17 | 21 |
| 22 class ObfuscatedGaiaIdFetcher; | |
| 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 : public InvalidationHandlerObserver { |
| 20 public: | 26 public: |
| 21 explicit PushMessagingEventRouter(Profile* profile); | 27 explicit PushMessagingEventRouter(Profile* profile); |
| 22 virtual ~PushMessagingEventRouter(); | 28 virtual ~PushMessagingEventRouter(); |
| 23 | 29 |
| 24 void Init(); | 30 void Init(); |
| 25 | 31 |
| 26 private: | 32 private: |
| 27 FRIEND_TEST_ALL_PREFIXES(PushMessagingApiTest, EventDispatch); | 33 FRIEND_TEST_ALL_PREFIXES(PushMessagingApiTest, EventDispatch); |
| 28 | 34 |
| 29 // InvalidationHandlerObserver implementation. | 35 // InvalidationHandlerObserver implementation. |
| 30 virtual void OnMessage(const std::string& extension_id, | 36 virtual void OnMessage(const std::string& extension_id, |
| 31 int subchannel, | 37 int subchannel, |
| 32 const std::string& payload) OVERRIDE; | 38 const std::string& payload) OVERRIDE; |
| 33 | 39 |
| 34 Profile* profile_; | 40 Profile* profile_; |
| 35 | 41 |
| 36 DISALLOW_COPY_AND_ASSIGN(PushMessagingEventRouter); | 42 DISALLOW_COPY_AND_ASSIGN(PushMessagingEventRouter); |
| 37 }; | 43 }; |
| 38 | 44 |
| 45 // Implements the getChannelId function, callabel from JavaScript | |
| 46 // this relies on the ObfuscatedGaiaIdFetcher to get the GAIA ID | |
| 47 // that we use to build the channel ID. | |
|
dcheng
2012/08/16 19:12:43
I would probably leave out this comment as it mere
Pete Williamson
2012/08/19 22:05:14
Sure, I'll do that, but I have a question on Philo
dcheng
2012/08/19 22:38:35
It's OK to comment on the 'what' if it's something
| |
| 48 class PushMessagingGetChannelIdFunction : public AsyncExtensionFunction { | |
|
Munjal (Google)
2012/08/15 23:04:19
This class should implement the delegate interface
Pete Williamson
2012/08/19 22:05:14
My first implementation did that, but after a disc
| |
| 49 public: | |
|
Munjal (Google)
2012/08/15 23:04:19
Indentation is off. Should be one space for public
Pete Williamson
2012/08/19 22:05:14
Oops, my bad, I let the editor indent "public:" fo
| |
| 50 PushMessagingGetChannelIdFunction(); | |
| 51 virtual void OnObfuscatedGaiaIdFetchSuccess( | |
| 52 const std::string& access_token); | |
| 53 virtual void OnObfuscatedGaiaIdFetchFailure( | |
|
Munjal (Google)
2012/08/15 23:04:19
Move these methods to private once they are in the
Pete Williamson
2012/08/19 22:05:14
Noted. Will fix when we decide the right approach
| |
| 54 const GoogleServiceAuthError& error); | |
| 55 | |
| 56 protected: | |
| 57 virtual ~PushMessagingGetChannelIdFunction(); | |
| 58 | |
| 59 // ExtensionFunction: | |
| 60 virtual bool RunImpl() OVERRIDE; | |
| 61 DECLARE_EXTENSION_FUNCTION_NAME("experimental.pushMessaging.getChannelId"); | |
| 62 | |
| 63 private: | |
| 64 void GetChannelIdOnIOThread(); | |
| 65 void RespondOnUIThread(const std::string& gaiaId, const long status); | |
| 66 void StartGaiaIdFetch(Profile* profile); | |
| 67 ObfuscatedGaiaIdFetcher* fetcher_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(PushMessagingGetChannelIdFunction); | |
| 70 }; | |
| 71 | |
| 39 } // namespace extension | 72 } // namespace extension |
| 40 | 73 |
| 41 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ | 74 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ |
| OLD | NEW |