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

Side by Side Diff: chrome/browser/android/webapps/add_to_homescreen_manager.cc

Issue 2738823008: Fix leaking of AddToHomescreenManager for WebAPKs. (Closed)
Patch Set: Created 3 years, 9 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/android/webapps/add_to_homescreen_manager.h" 5 #include "chrome/browser/android/webapps/add_to_homescreen_manager.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 ScopedJavaLocalRef<jstring> j_user_title = 155 ScopedJavaLocalRef<jstring> j_user_title =
156 base::android::ConvertUTF16ToJavaString(env, user_title); 156 base::android::ConvertUTF16ToJavaString(env, user_title);
157 Java_AddToHomescreenManager_onUserTitleAvailable(env, 157 Java_AddToHomescreenManager_onUserTitleAvailable(env,
158 java_ref_, 158 java_ref_,
159 j_user_title); 159 j_user_title);
160 } 160 }
161 161
162 void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info, 162 void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info,
163 const SkBitmap& primary_icon, 163 const SkBitmap& primary_icon,
164 const SkBitmap& badge_icon) { 164 const SkBitmap& badge_icon) {
165 JNIEnv* env = base::android::AttachCurrentThread();
pkotwicz 2017/03/08 21:57:29 Nit: Can you move this right before you call Java_
Xi Han 2017/03/08 22:13:52 I move it here since both line 175 and 183 use the
165 if (is_webapk_compatible_) { 166 if (is_webapk_compatible_) {
166 // TODO(zpeng): Add badge to WebAPK installation flow. 167 // TODO(zpeng): Add badge to WebAPK installation flow.
167 WebApkInstallService* install_service = 168 WebApkInstallService* install_service =
168 WebApkInstallService::Get( 169 WebApkInstallService::Get(
169 data_fetcher_->web_contents()->GetBrowserContext()); 170 data_fetcher_->web_contents()->GetBrowserContext());
170 if (install_service->IsInstallInProgress(info.manifest_url)) 171 if (install_service->IsInstallInProgress(info.manifest_url))
171 ShortcutHelper::ShowWebApkInstallInProgressToast(); 172 ShortcutHelper::ShowWebApkInstallInProgressToast();
172 else 173 else
173 CreateInfoBarForWebApk(info, primary_icon); 174 CreateInfoBarForWebApk(info, primary_icon);
175 Java_AddToHomescreenManager_finish(env, java_ref_);
174 return; 176 return;
175 } 177 }
176 178
177 JNIEnv* env = base::android::AttachCurrentThread();
178 ScopedJavaLocalRef<jobject> java_bitmap; 179 ScopedJavaLocalRef<jobject> java_bitmap;
179 if (!primary_icon.drawsNothing()) 180 if (!primary_icon.drawsNothing())
180 java_bitmap = gfx::ConvertToJavaBitmap(&primary_icon); 181 java_bitmap = gfx::ConvertToJavaBitmap(&primary_icon);
181 182
182 Java_AddToHomescreenManager_onReadyToAdd(env, java_ref_, java_bitmap); 183 Java_AddToHomescreenManager_onReadyToAdd(env, java_ref_, java_bitmap);
183 184
184 if (add_shortcut_pending_) 185 if (add_shortcut_pending_)
185 AddShortcut(info, primary_icon); 186 AddShortcut(info, primary_icon);
186 } 187 }
187 188
188 void AddToHomescreenManager::CreateInfoBarForWebApk(const ShortcutInfo& info, 189 void AddToHomescreenManager::CreateInfoBarForWebApk(const ShortcutInfo& info,
189 const SkBitmap& icon) { 190 const SkBitmap& icon) {
190 banners::AppBannerInfoBarDelegateAndroid::Create( 191 banners::AppBannerInfoBarDelegateAndroid::Create(
191 data_fetcher_->web_contents(), nullptr, info.user_title, 192 data_fetcher_->web_contents(), nullptr, info.user_title,
192 base::MakeUnique<ShortcutInfo>(info), base::MakeUnique<SkBitmap>(icon), 193 base::MakeUnique<ShortcutInfo>(info), base::MakeUnique<SkBitmap>(icon),
193 -1 /* event_request_id */, webapk::INSTALL_SOURCE_MENU); 194 -1 /* event_request_id */, webapk::INSTALL_SOURCE_MENU);
194 } 195 }
195 196
196 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( 197 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground(
197 const SkBitmap& bitmap, 198 const SkBitmap& bitmap,
198 const GURL& url, 199 const GURL& url,
199 bool* is_generated) { 200 bool* is_generated) {
200 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 201 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
201 202
202 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, 203 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url,
203 is_generated); 204 is_generated);
204 } 205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698