Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/notifications/platform_notification_service_impl.h" | 5 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 ->GetNotificationUIManager()->CancelById(id, profile_id); | 94 ->GetNotificationUIManager()->CancelById(id, profile_id); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Callback to run once the profile has been loaded in order to perform a | 97 // Callback to run once the profile has been loaded in order to perform a |
| 98 // given |operation| in a notification. | 98 // given |operation| in a notification. |
| 99 void ProfileLoadedCallback( | 99 void ProfileLoadedCallback( |
| 100 PlatformNotificationServiceImpl::NotificationOperation operation, | 100 PlatformNotificationServiceImpl::NotificationOperation operation, |
| 101 const GURL& origin, | 101 const GURL& origin, |
| 102 int64_t persistent_notification_id, | 102 int64_t persistent_notification_id, |
| 103 int action_index, | 103 int action_index, |
| 104 bool incognito, | 104 Profile* profile) { |
| 105 Profile* profile, | 105 if (!profile) |
|
Peter Beverloo
2016/03/11 17:45:15
We should probably log something if the profile co
Miguel Garcia
2016/03/14 18:29:00
Will add a TODO to add the state and UMA to it and
| |
| 106 Profile::CreateStatus status) { | |
| 107 if (status == Profile::CREATE_STATUS_CREATED) { | |
| 108 // This is an intermediate state, we will be also called | |
| 109 // again with CREATE_STATUS_INITIALIZED once everything is ready | |
| 110 // so ignore it. | |
| 111 return; | 106 return; |
| 112 } | |
| 113 if (status != Profile::CREATE_STATUS_INITIALIZED) { | |
| 114 LOG(WARNING) << "Profile not loaded correctly"; | |
| 115 return; | |
| 116 } | |
| 117 DCHECK(profile); | |
| 118 profile = incognito ? profile->GetOffTheRecordProfile() : profile; | |
| 119 | 107 |
| 120 switch (operation) { | 108 switch (operation) { |
| 121 case PlatformNotificationServiceImpl::NOTIFICATION_CLICK: | 109 case PlatformNotificationServiceImpl::NOTIFICATION_CLICK: |
| 122 PlatformNotificationServiceImpl::GetInstance() | 110 PlatformNotificationServiceImpl::GetInstance() |
| 123 ->OnPersistentNotificationClick(profile, persistent_notification_id, | 111 ->OnPersistentNotificationClick(profile, persistent_notification_id, |
| 124 origin, action_index); | 112 origin, action_index); |
| 125 break; | 113 break; |
| 126 case PlatformNotificationServiceImpl::NOTIFICATION_CLOSE: | 114 case PlatformNotificationServiceImpl::NOTIFICATION_CLOSE: |
| 127 PlatformNotificationServiceImpl::GetInstance() | 115 PlatformNotificationServiceImpl::GetInstance() |
| 128 ->OnPersistentNotificationClose(profile, persistent_notification_id, | 116 ->OnPersistentNotificationClose(profile, persistent_notification_id, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 153 void PlatformNotificationServiceImpl::ProcessPersistentNotificationOperation( | 141 void PlatformNotificationServiceImpl::ProcessPersistentNotificationOperation( |
| 154 NotificationOperation operation, | 142 NotificationOperation operation, |
| 155 const std::string& profile_id, | 143 const std::string& profile_id, |
| 156 bool incognito, | 144 bool incognito, |
| 157 const GURL& origin, | 145 const GURL& origin, |
| 158 int64_t persistent_notification_id, | 146 int64_t persistent_notification_id, |
| 159 int action_index) { | 147 int action_index) { |
| 160 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 148 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 161 DCHECK(profile_manager); | 149 DCHECK(profile_manager); |
| 162 | 150 |
| 163 // ProfileManager does not offer a good interface to load a profile or | 151 profile_manager->LoadProfile( |
| 164 // fail. Instead it offers a method to create the profile and simply load it | 152 profile_id, incognito, |
| 165 // if it already exist. We therefore check first that the profile is there | |
| 166 // and fail early otherwise. | |
| 167 const base::FilePath profile_path = | |
| 168 profile_manager->user_data_dir().AppendASCII(profile_id); | |
| 169 | |
| 170 ProfileAttributesEntry* entry = nullptr; | |
| 171 if (!profile_manager->GetProfileAttributesStorage(). | |
| 172 GetProfileAttributesWithPath(profile_path, &entry)) { | |
| 173 LOG(ERROR) << "Loading a path that does not exist"; | |
| 174 return; | |
| 175 } | |
| 176 | |
| 177 profile_manager->CreateProfileAsync( | |
| 178 profile_path, | |
| 179 base::Bind(&ProfileLoadedCallback, operation, origin, | 153 base::Bind(&ProfileLoadedCallback, operation, origin, |
| 180 persistent_notification_id, action_index, incognito), | 154 persistent_notification_id, action_index)); |
| 181 base::string16(), std::string(), std::string()); | |
| 182 } | 155 } |
| 183 | 156 |
| 184 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( | 157 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( |
| 185 BrowserContext* browser_context, | 158 BrowserContext* browser_context, |
| 186 int64_t persistent_notification_id, | 159 int64_t persistent_notification_id, |
| 187 const GURL& origin, | 160 const GURL& origin, |
| 188 int action_index) { | 161 int action_index) { |
| 189 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 162 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 190 blink::WebNotificationPermission permission = | 163 blink::WebNotificationPermission permission = |
| 191 CheckPermissionOnUIThread(browser_context, origin, | 164 CheckPermissionOnUIThread(browser_context, origin, |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 528 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 556 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 529 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
| 557 DCHECK(extension); | 530 DCHECK(extension); |
| 558 | 531 |
| 559 return base::UTF8ToUTF16(extension->name()); | 532 return base::UTF8ToUTF16(extension->name()); |
| 560 } | 533 } |
| 561 #endif | 534 #endif |
| 562 | 535 |
| 563 return base::string16(); | 536 return base::string16(); |
| 564 } | 537 } |
| OLD | NEW |