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

Side by Side Diff: chrome/browser/android/banners/app_banner_infobar_delegate.cc

Issue 914403006: [App banners] Start adding unit tets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments Created 5 years, 10 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/banners/app_banner_infobar_delegate.h" 5 #include "chrome/browser/android/banners/app_banner_infobar_delegate.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/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/worker_pool.h" 12 #include "base/threading/worker_pool.h"
13 #include "chrome/browser/android/banners/app_banner_manager.h"
13 #include "chrome/browser/android/shortcut_helper.h" 14 #include "chrome/browser/android/shortcut_helper.h"
14 #include "chrome/browser/android/shortcut_info.h" 15 #include "chrome/browser/android/shortcut_info.h"
15 #include "chrome/browser/android/tab_android.h" 16 #include "chrome/browser/android/tab_android.h"
16 #include "chrome/browser/banners/app_banner_settings_helper.h" 17 #include "chrome/browser/banners/app_banner_settings_helper.h"
17 #include "chrome/browser/infobars/infobar_service.h" 18 #include "chrome/browser/infobars/infobar_service.h"
18 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h" 19 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h"
19 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
20 #include "components/infobars/core/infobar.h" 21 #include "components/infobars/core/infobar.h"
21 #include "components/infobars/core/infobar_manager.h" 22 #include "components/infobars/core/infobar_manager.h"
22 #include "content/public/common/manifest.h" 23 #include "content/public/common/manifest.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 void AppBannerInfoBarDelegate::InfoBarDismissed() { 108 void AppBannerInfoBarDelegate::InfoBarDismissed() {
108 content::WebContents* web_contents = 109 content::WebContents* web_contents =
109 InfoBarService::WebContentsFromInfoBar(infobar()); 110 InfoBarService::WebContentsFromInfoBar(infobar());
110 if (!web_contents) 111 if (!web_contents)
111 return; 112 return;
112 113
113 if (!native_app_data_.is_null()) { 114 if (!native_app_data_.is_null()) {
114 AppBannerSettingsHelper::RecordBannerEvent( 115 AppBannerSettingsHelper::RecordBannerEvent(
115 web_contents, web_contents->GetURL(), 116 web_contents, web_contents->GetURL(),
116 native_app_package_, 117 native_app_package_,
117 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, base::Time::Now()); 118 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK,
119 AppBannerManager::GetCurrentTime());
118 } else if (!web_app_data_.IsEmpty()) { 120 } else if (!web_app_data_.IsEmpty()) {
119 AppBannerSettingsHelper::RecordBannerEvent( 121 AppBannerSettingsHelper::RecordBannerEvent(
120 web_contents, web_contents->GetURL(), 122 web_contents, web_contents->GetURL(),
121 web_app_data_.start_url.spec(), 123 web_app_data_.start_url.spec(),
122 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, base::Time::Now()); 124 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK,
125 AppBannerManager::GetCurrentTime());
123 } 126 }
124 } 127 }
125 128
126 bool AppBannerInfoBarDelegate::Accept() { 129 bool AppBannerInfoBarDelegate::Accept() {
127 content::WebContents* web_contents = 130 content::WebContents* web_contents =
128 InfoBarService::WebContentsFromInfoBar(infobar()); 131 InfoBarService::WebContentsFromInfoBar(infobar());
129 if (!web_contents) 132 if (!web_contents)
130 return true; 133 return true;
131 134
132 if (!native_app_data_.is_null()) { 135 if (!native_app_data_.is_null()) {
133 JNIEnv* env = base::android::AttachCurrentThread(); 136 JNIEnv* env = base::android::AttachCurrentThread();
134 137
135 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); 138 TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
136 if (tab == nullptr) 139 if (tab == nullptr)
137 return true; 140 return true;
138 141
139 return Java_AppBannerInfoBarDelegate_installOrOpenNativeApp( 142 return Java_AppBannerInfoBarDelegate_installOrOpenNativeApp(
140 env, 143 env,
141 java_delegate_.obj(), 144 java_delegate_.obj(),
142 tab->GetJavaObject().obj(), 145 tab->GetJavaObject().obj(),
143 native_app_data_.obj()); 146 native_app_data_.obj());
144 } else if (!web_app_data_.IsEmpty()) { 147 } else if (!web_app_data_.IsEmpty()) {
145 AppBannerSettingsHelper::RecordBannerEvent( 148 AppBannerSettingsHelper::RecordBannerEvent(
146 web_contents, web_contents->GetURL(), 149 web_contents, web_contents->GetURL(),
147 web_app_data_.start_url.spec(), 150 web_app_data_.start_url.spec(),
148 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, 151 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
149 base::Time::Now()); 152 AppBannerManager::GetCurrentTime());
150 153
151 ShortcutInfo info; 154 ShortcutInfo info;
152 info.UpdateFromManifest(web_app_data_); 155 info.UpdateFromManifest(web_app_data_);
153 base::WorkerPool::PostTask( 156 base::WorkerPool::PostTask(
154 FROM_HERE, 157 FROM_HERE,
155 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithSkBitmap, 158 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithSkBitmap,
156 info, 159 info,
157 *app_icon_.get()), 160 *app_icon_.get()),
158 true); 161 true);
159 return true; 162 return true;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 InfoBarService::WebContentsFromInfoBar(infobar()); 197 InfoBarService::WebContentsFromInfoBar(infobar());
195 if (!web_contents) 198 if (!web_contents)
196 return; 199 return;
197 200
198 if (jis_installing) { 201 if (jis_installing) {
199 AppBannerSettingsHelper::RecordBannerEvent( 202 AppBannerSettingsHelper::RecordBannerEvent(
200 web_contents, 203 web_contents,
201 web_contents->GetURL(), 204 web_contents->GetURL(),
202 native_app_package_, 205 native_app_package_,
203 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, 206 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
204 base::Time::Now()); 207 AppBannerManager::GetCurrentTime());
205 } 208 }
206 209
207 UpdateInstallState(env, obj); 210 UpdateInstallState(env, obj);
208 } 211 }
209 212
210 void AppBannerInfoBarDelegate::OnInstallFinished(JNIEnv* env, 213 void AppBannerInfoBarDelegate::OnInstallFinished(JNIEnv* env,
211 jobject obj, 214 jobject obj,
212 jboolean success) { 215 jboolean success) {
213 if (!infobar()) 216 if (!infobar())
214 return; 217 return;
(...skipping 15 matching lines...) Expand all
230 native_app_data_.obj()); 233 native_app_data_.obj());
231 static_cast<AppBannerInfoBar*>(infobar())->OnInstallStateChanged(newState); 234 static_cast<AppBannerInfoBar*>(infobar())->OnInstallStateChanged(newState);
232 } 235 }
233 236
234 237
235 bool RegisterAppBannerInfoBarDelegate(JNIEnv* env) { 238 bool RegisterAppBannerInfoBarDelegate(JNIEnv* env) {
236 return RegisterNativesImpl(env); 239 return RegisterNativesImpl(env);
237 } 240 }
238 241
239 } // namespace banners 242 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698