| 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" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 const char kUserNotSignedIn[] = "The user is not signed in."; | 39 const char kUserNotSignedIn[] = "The user is not signed in."; |
| 40 const char kTokenServiceNotAvailable[] = "Failed to get token service."; | 40 const char kTokenServiceNotAvailable[] = "Failed to get token service."; |
| 41 } | 41 } |
| 42 | 42 |
| 43 namespace extensions { | 43 namespace extensions { |
| 44 | 44 |
| 45 namespace glue = api::push_messaging; | 45 namespace glue = api::push_messaging; |
| 46 | 46 |
| 47 PushMessagingEventRouter::PushMessagingEventRouter(Profile* profile) | 47 PushMessagingEventRouter::PushMessagingEventRouter(Profile* profile) |
| 48 : profile_(profile) { | 48 : profile_(profile) { |
| 49 } | |
| 50 | |
| 51 PushMessagingEventRouter::~PushMessagingEventRouter() {} | |
| 52 | |
| 53 void PushMessagingEventRouter::Init() { | |
| 54 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile_); | 49 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile_); |
| 55 // This may be NULL; for example, for the ChromeOS guest user. In these cases, | 50 // This may be NULL; for example, for the ChromeOS guest user. In these cases, |
| 56 // just return without setting up anything, since it won't work anyway. | 51 // just return without setting up anything, since it won't work anyway. |
| 57 if (!pss) | 52 if (!pss) |
| 58 return; | 53 return; |
| 59 | 54 |
| 60 const ExtensionSet* extensions = | 55 const ExtensionSet* extensions = |
| 61 ExtensionSystem::Get(profile_)->extension_service()->extensions(); | 56 ExtensionSystem::Get(profile_)->extension_service()->extensions(); |
| 62 std::set<std::string> push_messaging_extensions; | 57 std::set<std::string> push_messaging_extensions; |
| 63 for (ExtensionSet::const_iterator it = extensions->begin(); | 58 for (ExtensionSet::const_iterator it = extensions->begin(); |
| 64 it != extensions->end(); ++it) { | 59 it != extensions->end(); ++it) { |
| 65 const Extension* extension = *it; | 60 const Extension* extension = *it; |
| 66 if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { | 61 if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { |
| 67 push_messaging_extensions.insert(extension->id()); | 62 push_messaging_extensions.insert(extension->id()); |
| 68 } | 63 } |
| 69 } | 64 } |
| 70 handler_.reset(new PushMessagingInvalidationHandler( | 65 handler_.reset(new PushMessagingInvalidationHandler( |
| 71 pss, this, push_messaging_extensions)); | 66 pss, this, push_messaging_extensions)); |
| 72 | 67 |
| 73 // Register for extension load/unload as well, so we can update any | 68 // Register for extension load/unload as well, so we can update any |
| 74 // registrations as appropriate. | 69 // registrations as appropriate. |
| 75 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 70 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 76 content::Source<Profile>(profile_->GetOriginalProfile())); | 71 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 77 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 72 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 78 content::Source<Profile>(profile_->GetOriginalProfile())); | 73 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 79 } | 74 } |
| 80 | 75 |
| 76 PushMessagingEventRouter::~PushMessagingEventRouter() {} |
| 77 |
| 81 void PushMessagingEventRouter::Shutdown() { | 78 void PushMessagingEventRouter::Shutdown() { |
| 82 // We need an explicit Shutdown() due to the dependencies among the various | 79 // We need an explicit Shutdown() due to the dependencies among the various |
| 83 // ProfileKeyedServices. ProfileSyncService depends on ExtensionSystem, so | 80 // ProfileKeyedServices. ProfileSyncService depends on ExtensionSystem, so |
| 84 // it is destroyed before us in the destruction phase of Profile shutdown. | 81 // it is destroyed before us in the destruction phase of Profile shutdown. |
| 85 // As a result, we need to drop any references to it in the Shutdown() phase | 82 // As a result, we need to drop any references to it in the Shutdown() phase |
| 86 // instead. | 83 // instead. |
| 87 handler_.reset(); | 84 handler_.reset(); |
| 88 } | 85 } |
| 89 | 86 |
| 90 void PushMessagingEventRouter::SetMapperForTest( | 87 void PushMessagingEventRouter::SetMapperForTest( |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 // If the error message is blank, see if we can set it from the state. | 284 // If the error message is blank, see if we can set it from the state. |
| 288 if (error_text.empty() && | 285 if (error_text.empty() && |
| 289 (0 != error.state())) { | 286 (0 != error.state())) { |
| 290 error_text = base::IntToString(error.state()); | 287 error_text = base::IntToString(error.state()); |
| 291 } | 288 } |
| 292 | 289 |
| 293 ReportResult(std::string(), error_text); | 290 ReportResult(std::string(), error_text); |
| 294 } | 291 } |
| 295 | 292 |
| 296 } // namespace extensions | 293 } // namespace extensions |
| OLD | NEW |