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) { |
106 Profile::CreateStatus status) { | 106 // TODO(miguelg): Add UMA for this condition. |
107 if (status == Profile::CREATE_STATUS_CREATED) { | 107 // Perhaps propagate this through PersistentNotificationStatus. |
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; | |
112 } | |
113 if (status != Profile::CREATE_STATUS_INITIALIZED) { | |
114 LOG(WARNING) << "Profile not loaded correctly"; | 108 LOG(WARNING) << "Profile not loaded correctly"; |
115 return; | 109 return; |
116 } | 110 } |
117 DCHECK(profile); | |
118 profile = incognito ? profile->GetOffTheRecordProfile() : profile; | |
119 | 111 |
120 switch (operation) { | 112 switch (operation) { |
121 case PlatformNotificationServiceImpl::NOTIFICATION_CLICK: | 113 case PlatformNotificationServiceImpl::NOTIFICATION_CLICK: |
122 PlatformNotificationServiceImpl::GetInstance() | 114 PlatformNotificationServiceImpl::GetInstance() |
123 ->OnPersistentNotificationClick(profile, persistent_notification_id, | 115 ->OnPersistentNotificationClick(profile, persistent_notification_id, |
124 origin, action_index); | 116 origin, action_index); |
125 break; | 117 break; |
126 case PlatformNotificationServiceImpl::NOTIFICATION_CLOSE: | 118 case PlatformNotificationServiceImpl::NOTIFICATION_CLOSE: |
127 PlatformNotificationServiceImpl::GetInstance() | 119 PlatformNotificationServiceImpl::GetInstance() |
128 ->OnPersistentNotificationClose(profile, persistent_notification_id, | 120 ->OnPersistentNotificationClose(profile, persistent_notification_id, |
(...skipping 24 matching lines...) Expand all Loading... |
153 void PlatformNotificationServiceImpl::ProcessPersistentNotificationOperation( | 145 void PlatformNotificationServiceImpl::ProcessPersistentNotificationOperation( |
154 NotificationOperation operation, | 146 NotificationOperation operation, |
155 const std::string& profile_id, | 147 const std::string& profile_id, |
156 bool incognito, | 148 bool incognito, |
157 const GURL& origin, | 149 const GURL& origin, |
158 int64_t persistent_notification_id, | 150 int64_t persistent_notification_id, |
159 int action_index) { | 151 int action_index) { |
160 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 152 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
161 DCHECK(profile_manager); | 153 DCHECK(profile_manager); |
162 | 154 |
163 // ProfileManager does not offer a good interface to load a profile or | 155 profile_manager->LoadProfile( |
164 // fail. Instead it offers a method to create the profile and simply load it | 156 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, | 157 base::Bind(&ProfileLoadedCallback, operation, origin, |
180 persistent_notification_id, action_index, incognito), | 158 persistent_notification_id, action_index)); |
181 base::string16(), std::string(), std::string()); | |
182 } | 159 } |
183 | 160 |
184 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( | 161 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( |
185 BrowserContext* browser_context, | 162 BrowserContext* browser_context, |
186 int64_t persistent_notification_id, | 163 int64_t persistent_notification_id, |
187 const GURL& origin, | 164 const GURL& origin, |
188 int action_index) { | 165 int action_index) { |
189 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 166 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
190 blink::WebNotificationPermission permission = | 167 blink::WebNotificationPermission permission = |
191 CheckPermissionOnUIThread(browser_context, origin, | 168 CheckPermissionOnUIThread(browser_context, origin, |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 532 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
556 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 533 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
557 DCHECK(extension); | 534 DCHECK(extension); |
558 | 535 |
559 return base::UTF8ToUTF16(extension->name()); | 536 return base::UTF8ToUTF16(extension->name()); |
560 } | 537 } |
561 #endif | 538 #endif |
562 | 539 |
563 return base::string16(); | 540 return base::string16(); |
564 } | 541 } |
OLD | NEW |