Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: chrome/browser/notifications/notification_ui_manager_android.cc

Issue 1814923002: Nuke NotificationUIManager from PlatformNotificationServiceImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@profile_manager_load
Patch Set: Review comments + unique_ptr rename Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/notification_ui_manager_android.h" 5 #include "chrome/browser/notifications/notification_ui_manager_android.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/android/context_utils.h" 10 #include "base/android/context_utils.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 // Called by the Java side when a notification event has been received, but the 60 // Called by the Java side when a notification event has been received, but the
61 // NotificationUIManager has not been initialized yet. Enforce initialization of 61 // NotificationUIManager has not been initialized yet. Enforce initialization of
62 // the class. 62 // the class.
63 static void InitializeNotificationUIManager(JNIEnv* env, 63 static void InitializeNotificationUIManager(JNIEnv* env,
64 const JavaParamRef<jclass>& clazz) { 64 const JavaParamRef<jclass>& clazz) {
65 g_browser_process->notification_ui_manager(); 65 g_browser_process->notification_ui_manager();
66 } 66 }
67 67
68 // static 68 // static
69 NotificationUIManager* NotificationUIManager::Create(PrefService* local_state) { 69 NotificationBridge* NotificationBridge::Create() {
70 return new NotificationUIManagerAndroid(); 70 return new NotificationUIManagerAndroid();
71 } 71 }
72 72
73 // static
74 NotificationUIManager*
75 NotificationUIManager::CreateNativeNotificationManager() {
76 return nullptr;
77 }
78
79 NotificationUIManagerAndroid::NotificationUIManagerAndroid() { 73 NotificationUIManagerAndroid::NotificationUIManagerAndroid() {
80 java_object_.Reset( 74 java_object_.Reset(
81 Java_NotificationUIManager_create( 75 Java_NotificationUIManager_create(
82 AttachCurrentThread(), 76 AttachCurrentThread(),
83 reinterpret_cast<intptr_t>(this), 77 reinterpret_cast<intptr_t>(this),
84 base::android::GetApplicationContext())); 78 base::android::GetApplicationContext()));
85 } 79 }
86 80
87 NotificationUIManagerAndroid::~NotificationUIManagerAndroid() { 81 NotificationUIManagerAndroid::~NotificationUIManagerAndroid() {
88 Java_NotificationUIManager_destroy(AttachCurrentThread(), 82 Java_NotificationUIManager_destroy(AttachCurrentThread(),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 std::string tag = ConvertJavaStringToUTF8(env, java_tag); 119 std::string tag = ConvertJavaStringToUTF8(env, java_tag);
126 120
127 // The notification was closed by the platform, so clear all local state. 121 // The notification was closed by the platform, so clear all local state.
128 regenerated_notification_infos_.erase(persistent_notification_id); 122 regenerated_notification_infos_.erase(persistent_notification_id);
129 PlatformNotificationServiceImpl::GetInstance() 123 PlatformNotificationServiceImpl::GetInstance()
130 ->ProcessPersistentNotificationOperation( 124 ->ProcessPersistentNotificationOperation(
131 PlatformNotificationServiceImpl::NOTIFICATION_CLOSE, profile_id, 125 PlatformNotificationServiceImpl::NOTIFICATION_CLOSE, profile_id,
132 incognito, origin, persistent_notification_id, -1); 126 incognito, origin, persistent_notification_id, -1);
133 } 127 }
134 128
135 void NotificationUIManagerAndroid::Add(const Notification& notification, 129 void NotificationUIManagerAndroid::Display(const std::string& notification_id,
136 Profile* profile) { 130 const std::string& profile_id,
137 DCHECK(profile); 131 bool incognito,
132 const Notification& notification) {
138 JNIEnv* env = AttachCurrentThread(); 133 JNIEnv* env = AttachCurrentThread();
139 134
140 // The Android notification UI manager only supports Web Notifications, which 135 // The Android notification UI manager only supports Web Notifications, which
141 // have a PersistentNotificationDelegate. The persistent id of the 136 // have a PersistentNotificationDelegate. The persistent id of the
142 // notification is exposed through it's interface. 137 // notification is exposed through it's interface.
143 // 138 //
144 // TODO(peter): When content/ passes a message_center::Notification to the 139 // TODO(peter): When content/ passes a message_center::Notification to the
145 // chrome/ layer, the persistent notification id should be captured as a 140 // chrome/ layer, the persistent notification id should be captured as a
146 // property on that object instead, making this cast unnecessary. 141 // property on that object instead, making this cast unnecessary.
147 PersistentNotificationDelegate* delegate = 142 PersistentNotificationDelegate* delegate =
(...skipping 27 matching lines...) Expand all
175 action_titles_vector.push_back(button.title); 170 action_titles_vector.push_back(button.title);
176 ScopedJavaLocalRef<jobjectArray> action_titles = 171 ScopedJavaLocalRef<jobjectArray> action_titles =
177 base::android::ToJavaArrayOfStrings(env, action_titles_vector); 172 base::android::ToJavaArrayOfStrings(env, action_titles_vector);
178 173
179 ScopedJavaLocalRef<jobjectArray> action_icons = 174 ScopedJavaLocalRef<jobjectArray> action_icons =
180 ConvertToJavaBitmaps(notification.buttons()); 175 ConvertToJavaBitmaps(notification.buttons());
181 176
182 ScopedJavaLocalRef<jintArray> vibration_pattern = 177 ScopedJavaLocalRef<jintArray> vibration_pattern =
183 base::android::ToJavaIntArray(env, notification.vibration_pattern()); 178 base::android::ToJavaIntArray(env, notification.vibration_pattern());
184 179
185 ScopedJavaLocalRef<jstring> profile_id = 180 ScopedJavaLocalRef<jstring> j_profile_id =
186 ConvertUTF8ToJavaString(env, profile->GetPath().BaseName().value()); 181 ConvertUTF8ToJavaString(env, profile_id);
187 182
188 Java_NotificationUIManager_displayNotification( 183 Java_NotificationUIManager_displayNotification(
189 env, java_object_.obj(), persistent_notification_id, origin.obj(), 184 env, java_object_.obj(), persistent_notification_id, origin.obj(),
190 profile_id.obj(), profile->IsOffTheRecord(), tag.obj(), title.obj(), 185 j_profile_id.obj(), incognito, tag.obj(), title.obj(), body.obj(),
191 body.obj(), notification_icon.obj(), badge.obj(), vibration_pattern.obj(), 186 notification_icon.obj(), badge.obj(), vibration_pattern.obj(),
192 notification.timestamp().ToJavaTime(), notification.renotify(), 187 notification.timestamp().ToJavaTime(), notification.renotify(),
193 notification.silent(), action_titles.obj(), action_icons.obj()); 188 notification.silent(), action_titles.obj(), action_icons.obj());
194 189
195 regenerated_notification_infos_[persistent_notification_id] = 190 regenerated_notification_infos_[persistent_notification_id] =
196 std::make_pair(origin_url.spec(), notification.tag()); 191 std::make_pair(origin_url.spec(), notification.tag());
197 192
198 notification.delegate()->Display(); 193 notification.delegate()->Display();
199 } 194 }
200 195
201 bool NotificationUIManagerAndroid::Update(const Notification& notification, 196 void NotificationUIManagerAndroid::Close(const std::string& profile_id,
202 Profile* profile) { 197 const std::string& notification_id) {
203 NOTREACHED();
204 return false;
205 }
206
207 const Notification* NotificationUIManagerAndroid::FindById(
208 const std::string& delegate_id,
209 ProfileID profile_id) const {
210 NOTREACHED();
211 return nullptr;
212 }
213
214 bool NotificationUIManagerAndroid::CancelById(const std::string& delegate_id,
215 ProfileID profile_id) {
216 int64_t persistent_notification_id = 0; 198 int64_t persistent_notification_id = 0;
217 199
218 // TODO(peter): Use the |delegate_id| directly when notification ids are being 200 // TODO(peter): Use the |delegate_id| directly when notification ids are being
219 // generated by content/ instead of us. 201 // generated by content/ instead of us.
220 if (!base::StringToInt64(delegate_id, &persistent_notification_id)) 202 if (!base::StringToInt64(notification_id, &persistent_notification_id)) {
221 return false; 203 LOG(WARNING) << "Unable to decode notification_id " << notification_id;
204 return;
205 }
222 206
223 const auto iterator = 207 const auto iterator =
224 regenerated_notification_infos_.find(persistent_notification_id); 208 regenerated_notification_infos_.find(persistent_notification_id);
225 if (iterator == regenerated_notification_infos_.end()) 209 if (iterator == regenerated_notification_infos_.end())
226 return false; 210 return;
227 211
228 const RegeneratedNotificationInfo& notification_info = iterator->second; 212 const RegeneratedNotificationInfo& notification_info = iterator->second;
229 213
230 JNIEnv* env = AttachCurrentThread(); 214 JNIEnv* env = AttachCurrentThread();
231 215
232 ScopedJavaLocalRef<jstring> origin = 216 ScopedJavaLocalRef<jstring> origin =
233 ConvertUTF8ToJavaString(env, notification_info.first); 217 ConvertUTF8ToJavaString(env, notification_info.first);
234 ScopedJavaLocalRef<jstring> tag = 218 ScopedJavaLocalRef<jstring> tag =
235 ConvertUTF8ToJavaString(env, notification_info.second); 219 ConvertUTF8ToJavaString(env, notification_info.second);
220 ScopedJavaLocalRef<jstring> j_profile_id =
221 ConvertUTF8ToJavaString(env, profile_id);
236 222
237 regenerated_notification_infos_.erase(iterator); 223 regenerated_notification_infos_.erase(iterator);
238 224
239 Java_NotificationUIManager_closeNotification(env, 225 Java_NotificationUIManager_closeNotification(
240 java_object_.obj(), 226 env, java_object_.obj(), j_profile_id.obj(), persistent_notification_id,
241 persistent_notification_id, 227 origin.obj(), tag.obj());
242 origin.obj(), 228 }
243 tag.obj()); 229
230 bool NotificationUIManagerAndroid::GetDisplayed(
231 const std::string& profile_id,
232 bool incognito,
233 std::set<std::string>* notifications) const {
234 // TODO(miguelg): This can actually be implemented for M+
235 return false;
236 }
237
238 bool NotificationUIManagerAndroid::SupportsNotificationCenter() const {
244 return true; 239 return true;
245 } 240 }
246 241
247 std::set<std::string> 242 bool NotificationUIManagerAndroid::RegisterNotificationBridge(JNIEnv* env) {
248 NotificationUIManagerAndroid::GetAllIdsByProfileAndSourceOrigin(
249 ProfileID profile_id,
250 const GURL& source) {
251 NOTREACHED();
252 return std::set<std::string>();
253 }
254
255 std::set<std::string> NotificationUIManagerAndroid::GetAllIdsByProfile(
256 ProfileID profile_id) {
257 NOTREACHED();
258 return std::set<std::string>();
259 }
260
261 bool NotificationUIManagerAndroid::CancelAllBySourceOrigin(
262 const GURL& source_origin) {
263 NOTREACHED();
264 return false;
265 }
266
267 bool NotificationUIManagerAndroid::CancelAllByProfile(ProfileID profile_id) {
268 NOTREACHED();
269 return false;
270 }
271
272 void NotificationUIManagerAndroid::CancelAll() {
273 NOTREACHED();
274 }
275
276 bool NotificationUIManagerAndroid::RegisterNotificationUIManager(JNIEnv* env) {
277 return RegisterNativesImpl(env); 243 return RegisterNativesImpl(env);
278 } 244 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698