| 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 <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler.h" | 12 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler.h" |
| 13 #include "chrome/browser/extensions/event_names.h" | 13 #include "chrome/browser/extensions/event_names.h" |
| 14 #include "chrome/browser/extensions/event_router.h" | 14 #include "chrome/browser/extensions/event_router.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/extension_system.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/sync/profile_sync_service.h" | 18 #include "chrome/browser/sync/profile_sync_service.h" |
| 19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 19 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/extensions/api/experimental_push_messaging.h" | 21 #include "chrome/common/extensions/api/experimental_push_messaging.h" |
| 22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/extensions/extension_set.h" | 23 #include "chrome/common/extensions/extension_set.h" |
| 24 #include "chrome/common/extensions/permissions/api_permission.h" | 24 #include "chrome/common/extensions/permissions/api_permission.h" |
| 25 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
| 26 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
| 27 #include "chrome/browser/profiles/profile_manager.h" |
| 28 #include "chrome/browser/signin/token_service.h" |
| 29 #include "chrome/browser/signin/token_service_factory.h" |
| 30 #include "chrome/common/extensions/api/experimental_push_messaging.h" |
| 31 #include "content/public/browser/browser_thread.h" |
| 27 #include "googleurl/src/gurl.h" | 32 #include "googleurl/src/gurl.h" |
| 33 #include "chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetche
r.h" |
| 34 |
| 35 using content::BrowserThread; |
| 28 | 36 |
| 29 namespace extensions { | 37 namespace extensions { |
| 30 | 38 |
| 31 namespace glue = api::experimental_push_messaging; | 39 namespace glue = api::experimental_push_messaging; |
| 32 | 40 |
| 33 PushMessagingEventRouter::PushMessagingEventRouter(Profile* profile) | 41 PushMessagingEventRouter::PushMessagingEventRouter(Profile* profile) |
| 34 : profile_(profile) { | 42 : profile_(profile) { |
| 35 } | 43 } |
| 36 | 44 |
| 37 PushMessagingEventRouter::~PushMessagingEventRouter() {} | 45 PushMessagingEventRouter::~PushMessagingEventRouter() {} |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { | 127 if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { |
| 120 handler_->UnregisterExtension(extension->id()); | 128 handler_->UnregisterExtension(extension->id()); |
| 121 } | 129 } |
| 122 break; | 130 break; |
| 123 } | 131 } |
| 124 default: | 132 default: |
| 125 NOTREACHED(); | 133 NOTREACHED(); |
| 126 } | 134 } |
| 127 } | 135 } |
| 128 | 136 |
| 137 // GetChannelId class functions |
| 138 |
| 139 PushMessagingGetChannelIdFunction::PushMessagingGetChannelIdFunction() {} |
| 140 |
| 141 PushMessagingGetChannelIdFunction::~PushMessagingGetChannelIdFunction() {} |
| 142 |
| 143 bool PushMessagingGetChannelIdFunction::RunImpl() { |
| 144 // Start the async fetch of the GAIA ID. |
| 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 146 net::URLRequestContextGetter* context = profile()->GetRequestContext(); |
| 147 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); |
| 148 const std::string& refresh_token = |
| 149 token_service->GetOAuth2LoginRefreshToken(); |
| 150 fetcher_.reset(new ObfuscatedGaiaIdFetcher(context, this, refresh_token)); |
| 151 |
| 152 // Balanced in ReportResult() |
| 153 AddRef(); |
| 154 |
| 155 fetcher_->Start(); |
| 156 |
| 157 // Will finish asynchronously. |
| 158 return true; |
| 159 } |
| 160 |
| 161 void PushMessagingGetChannelIdFunction::ReportResult( |
| 162 const std::string& gaia_id, const std::string& error_string) { |
| 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 164 // Unpack the status and GaiaId parameters, and use it to build the |
| 165 // channel ID here. |
| 166 std::string channel_id(gaia_id); |
| 167 if (!gaia_id.empty()) { |
| 168 channel_id += "."; |
| 169 channel_id += extension_id(); |
| 170 } |
| 171 |
| 172 // TODO(petewil): It may be a good idea to further |
| 173 // obfuscate the channel ID to prevent the user's obfuscated GAIA ID |
| 174 // from being readily obtained. Security review will tell us if we need to. |
| 175 |
| 176 // Create a ChannelId results object and set the fields. |
| 177 glue::ChannelIdResult result; |
| 178 result.channel_id = channel_id; |
| 179 SetError(error_string); |
| 180 results_ = glue::GetChannelId::Results::Create(result); |
| 181 SendResponse(true); |
| 182 |
| 183 // Balanced in RunImpl |
| 184 Release(); |
| 185 } |
| 186 |
| 187 void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchSuccess( |
| 188 const std::string& gaia_id) { |
| 189 ReportResult(gaia_id, std::string()); |
| 190 } |
| 191 |
| 192 void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchFailure( |
| 193 const GoogleServiceAuthError& error) { |
| 194 ReportResult(std::string(), error.error_message()); |
| 195 } |
| 196 |
| 129 } // namespace extensions | 197 } // namespace extensions |
| OLD | NEW |