Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_dialog_helper.h" | 5 #include "chrome/browser/android/webapps/add_to_homescreen_dialog_helper.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 AddToHomescreenDialogHelper::AddToHomescreenDialogHelper( | 37 AddToHomescreenDialogHelper::AddToHomescreenDialogHelper( |
| 38 JNIEnv* env, | 38 JNIEnv* env, |
| 39 jobject obj, | 39 jobject obj, |
| 40 content::WebContents* web_contents) | 40 content::WebContents* web_contents) |
| 41 : add_shortcut_pending_(false), | 41 : add_shortcut_pending_(false), |
| 42 data_fetcher_(new AddToHomescreenDataFetcher(web_contents, | 42 data_fetcher_(new AddToHomescreenDataFetcher(web_contents, |
| 43 ShortcutHelper::GetIdealHomescreenIconSizeInDp(), | 43 ShortcutHelper::GetIdealHomescreenIconSizeInDp(), |
| 44 ShortcutHelper::GetMinimumHomescreenIconSizeInDp(), | 44 ShortcutHelper::GetMinimumHomescreenIconSizeInDp(), |
| 45 ShortcutHelper::GetIdealSplashImageSizeInDp(), | 45 ShortcutHelper::GetIdealSplashImageSizeInDp(), |
| 46 ShortcutHelper::GetMinimumSplashImageSizeInDp(), | 46 ShortcutHelper::GetMinimumSplashImageSizeInDp(), |
| 47 this)) { | 47 this)), |
| 48 browser_context_(web_contents->GetBrowserContext()) { | |
|
dominickn
2016/08/02 04:24:24
Instead of adding this extra member, can you just
pkotwicz
2016/08/02 20:49:29
It is possible for the tab that a user requested b
dominickn
2016/08/02 23:41:58
If a tab is closed before add to homescreen finish
pkotwicz
2016/08/03 01:25:31
I have added the early exit to AddToHomescreenDial
| |
| 48 java_ref_.Reset(env, obj); | 49 java_ref_.Reset(env, obj); |
| 49 } | 50 } |
| 50 | 51 |
| 51 AddToHomescreenDialogHelper::~AddToHomescreenDialogHelper() { | 52 AddToHomescreenDialogHelper::~AddToHomescreenDialogHelper() { |
| 52 data_fetcher_->set_weak_observer(nullptr); | 53 data_fetcher_->set_weak_observer(nullptr); |
| 53 data_fetcher_ = nullptr; | 54 data_fetcher_ = nullptr; |
| 54 } | 55 } |
| 55 | 56 |
| 56 void AddToHomescreenDialogHelper::OnUserTitleAvailable( | 57 void AddToHomescreenDialogHelper::OnUserTitleAvailable( |
| 57 const base::string16& user_title) { | 58 const base::string16& user_title) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 DCHECK(add_shortcut_pending_); | 116 DCHECK(add_shortcut_pending_); |
| 116 if (!add_shortcut_pending_) | 117 if (!add_shortcut_pending_) |
| 117 return; | 118 return; |
| 118 add_shortcut_pending_ = false; | 119 add_shortcut_pending_ = false; |
| 119 | 120 |
| 120 RecordAddToHomescreen(); | 121 RecordAddToHomescreen(); |
| 121 | 122 |
| 122 const std::string& uid = base::GenerateGUID(); | 123 const std::string& uid = base::GenerateGUID(); |
| 123 content::BrowserThread::PostTask( | 124 content::BrowserThread::PostTask( |
| 124 content::BrowserThread::IO, FROM_HERE, | 125 content::BrowserThread::IO, FROM_HERE, |
| 125 base::Bind(&ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap, info, | 126 base::Bind(&ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap, |
| 126 uid, icon, | 127 browser_context_, info, uid, icon, |
| 127 data_fetcher_->FetchSplashScreenImageCallback(uid))); | 128 data_fetcher_->FetchSplashScreenImageCallback(uid))); |
| 128 } | 129 } |
| 129 | 130 |
| 130 bool AddToHomescreenDialogHelper::RegisterAddToHomescreenDialogHelper( | 131 bool AddToHomescreenDialogHelper::RegisterAddToHomescreenDialogHelper( |
| 131 JNIEnv* env) { | 132 JNIEnv* env) { |
| 132 return RegisterNativesImpl(env); | 133 return RegisterNativesImpl(env); |
| 133 } | 134 } |
| 134 | 135 |
| 135 void AddToHomescreenDialogHelper::RecordAddToHomescreen() { | 136 void AddToHomescreenDialogHelper::RecordAddToHomescreen() { |
| 136 // Record that the shortcut has been added, so no banners will be shown | 137 // Record that the shortcut has been added, so no banners will be shown |
| 137 // for this app. | 138 // for this app. |
| 138 content::WebContents* web_contents = data_fetcher_->web_contents(); | 139 content::WebContents* web_contents = data_fetcher_->web_contents(); |
| 139 if (!web_contents) | 140 if (!web_contents) |
| 140 return; | 141 return; |
| 141 | 142 |
| 142 AppBannerSettingsHelper::RecordBannerEvent( | 143 AppBannerSettingsHelper::RecordBannerEvent( |
| 143 web_contents, web_contents->GetURL(), | 144 web_contents, web_contents->GetURL(), |
| 144 data_fetcher_->shortcut_info().url.spec(), | 145 data_fetcher_->shortcut_info().url.spec(), |
| 145 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | 146 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
| 146 base::Time::Now()); | 147 base::Time::Now()); |
| 147 } | 148 } |
| OLD | NEW |