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 #include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h" | 5 #include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/event_names.h" | 9 #include "chrome/browser/extensions/event_names.h" |
| 10 #include "chrome/browser/extensions/event_router.h" | 10 #include "chrome/browser/extensions/event_router.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/signin/token_service.h" | |
| 13 #include "chrome/browser/signin/token_service_factory.h" | |
| 12 #include "chrome/common/extensions/api/experimental_push_messaging.h" | 14 #include "chrome/common/extensions/api/experimental_push_messaging.h" |
| 13 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 14 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 #include "chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetche r.h" | |
| 18 | |
| 19 using content::BrowserThread; | |
| 15 | 20 |
| 16 namespace extensions { | 21 namespace extensions { |
| 17 | 22 |
| 18 namespace glue = extensions::api::experimental_push_messaging; | 23 namespace glue = extensions::api::experimental_push_messaging; |
| 19 | 24 |
| 20 PushMessagingEventRouter::PushMessagingEventRouter(Profile* profile) | 25 PushMessagingEventRouter::PushMessagingEventRouter(Profile* profile) |
| 21 : profile_(profile) { | 26 : profile_(profile) { |
| 22 } | 27 } |
| 23 | 28 |
| 24 PushMessagingEventRouter::~PushMessagingEventRouter() {} | 29 PushMessagingEventRouter::~PushMessagingEventRouter() {} |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 36 | 41 |
| 37 scoped_ptr<base::ListValue> args(glue::OnMessage::Create(message)); | 42 scoped_ptr<base::ListValue> args(glue::OnMessage::Create(message)); |
| 38 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 43 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
| 39 extension_id, | 44 extension_id, |
| 40 event_names::kOnPushMessage, | 45 event_names::kOnPushMessage, |
| 41 args.Pass(), | 46 args.Pass(), |
| 42 profile_, | 47 profile_, |
| 43 GURL()); | 48 GURL()); |
| 44 } | 49 } |
| 45 | 50 |
| 51 PushMessagingGetChannelIdFunction::PushMessagingGetChannelIdFunction() {} | |
| 52 | |
| 53 PushMessagingGetChannelIdFunction::~PushMessagingGetChannelIdFunction() {} | |
| 54 | |
| 55 bool PushMessagingGetChannelIdFunction::RunImpl() { | |
| 56 // Start the async fetch of the GAIA ID. | |
| 57 StartGaiaIdFetch(); | |
| 58 | |
| 59 // Will finish asynchronously. | |
| 60 return true; | |
| 61 } | |
| 62 | |
| 63 void PushMessagingGetChannelIdFunction::RespondOnUIThread( | |
|
Munjal (Google)
2012/08/20 20:01:25
I still don't understand fully whether we need to
Pete Williamson
2012/08/20 20:53:05
We aren't doing any thread posting anymore. Chang
| |
| 64 const std::string& gaia_id, const long status) { | |
|
dcheng
2012/08/20 19:10:01
Just 'long' instead of 'const long'
Pete Williamson
2012/08/20 20:53:05
Done.
| |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 66 // Unpack the status and GaiaId parameters, and use it to build the | |
| 67 // channel ID here. | |
| 68 std::string channel_id(gaia_id); | |
| 69 if (!gaia_id.empty()) { | |
| 70 channel_id += "."; | |
| 71 channel_id += extension_id(); | |
| 72 } | |
| 73 | |
| 74 // TODO: (after initial checkin) It may be a good idea to further | |
|
dcheng
2012/08/20 19:10:01
TODO(petewil)
Pete Williamson
2012/08/20 20:53:05
Done.
| |
| 75 // obfuscate the channel ID to prevent the user's obfuscated GAIA ID | |
| 76 // from being readily obtained. Security review will tell us if we need to. | |
| 77 | |
| 78 // Create a ChannelId results object and set the fields. | |
| 79 glue::ChannelIdResult result; | |
| 80 result.channel_id = channel_id; | |
| 81 result.status = status; | |
| 82 results_ = glue::GetChannelId::Results::Create(result); | |
| 83 SendResponse(true); | |
| 84 | |
| 85 // Once we have handed off the response, we can allow the | |
| 86 // PushMessagingGetChannelIdFunction object to die. | |
| 87 Release(); | |
| 88 } | |
| 89 | |
| 90 // Member function to start the fetch operation. | |
| 91 // This must be called on the UI thread. | |
| 92 void PushMessagingGetChannelIdFunction::StartGaiaIdFetch() { | |
| 93 net::URLRequestContextGetter* context = profile()->GetRequestContext(); | |
| 94 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); | |
| 95 const std::string& refresh_token = | |
|
dcheng
2012/08/20 19:10:01
One space.
Pete Williamson
2012/08/20 20:53:05
Done.
| |
| 96 token_service->GetOAuth2LoginRefreshToken(); | |
| 97 | |
| 98 fetcher_.reset(new ObfuscatedGaiaIdFetcher(context, this, refresh_token)); | |
| 99 // Keep the PushMessagingGetChannelIdFunction object alive until we get | |
| 100 // a response. | |
| 101 AddRef(); | |
|
dcheng
2012/08/20 19:10:01
My preference would be to move this into RunImpl,
Pete Williamson
2012/08/20 20:53:05
Done. (Actually, I moved the whole function into R
| |
| 102 fetcher_->Start(); | |
| 103 } | |
| 104 | |
| 105 void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchSuccess( | |
| 106 const std::string& gaia_id) { | |
| 107 RespondOnUIThread(gaia_id, 0); | |
| 108 } | |
| 109 | |
| 110 void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchFailure( | |
| 111 const GoogleServiceAuthError& error) { | |
| 112 RespondOnUIThread(std::string(), error.state()); | |
| 113 } | |
| 114 | |
| 46 } // namespace extensions | 115 } // namespace extensions |
| OLD | NEW |