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

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

Issue 2156113002: Replace AppBannerDataFetcher with InstallableManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@banner-refactor
Patch Set: Naming, includes Created 4 years, 4 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_android.h" 5 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.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/guid.h" 9 #include "base/guid.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/memory/ptr_util.h"
11 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.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_data_fetcher.h" 17 #include "chrome/browser/banners/app_banner_manager.h"
17 #include "chrome/browser/banners/app_banner_metrics.h" 18 #include "chrome/browser/banners/app_banner_metrics.h"
18 #include "chrome/browser/banners/app_banner_settings_helper.h" 19 #include "chrome/browser/banners/app_banner_settings_helper.h"
19 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/infobars/infobar_service.h" 21 #include "chrome/browser/infobars/infobar_service.h"
21 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" 22 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h"
22 #include "chrome/common/render_messages.h" 23 #include "chrome/common/render_messages.h"
23 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
24 #include "components/rappor/rappor_utils.h" 25 #include "components/rappor/rappor_utils.h"
25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/render_frame_host.h" 27 #include "content/public/browser/render_frame_host.h"
27 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
28 #include "content/public/common/manifest.h" 29 #include "content/public/common/manifest.h"
29 #include "jni/AppBannerInfoBarDelegateAndroid_jni.h" 30 #include "jni/AppBannerInfoBarDelegateAndroid_jni.h"
30 #include "ui/gfx/android/java_bitmap.h" 31 #include "ui/gfx/android/java_bitmap.h"
31 #include "url/gurl.h" 32 #include "url/gurl.h"
32 33
33 using base::android::ConvertJavaStringToUTF8; 34 using base::android::ConvertJavaStringToUTF8;
34 using base::android::ConvertJavaStringToUTF16; 35 using base::android::ConvertJavaStringToUTF16;
35 using base::android::ConvertUTF8ToJavaString; 36 using base::android::ConvertUTF8ToJavaString;
36 using base::android::ConvertUTF16ToJavaString; 37 using base::android::ConvertUTF16ToJavaString;
37 using base::android::JavaParamRef; 38 using base::android::JavaParamRef;
38 using base::android::ScopedJavaLocalRef; 39 using base::android::ScopedJavaLocalRef;
39 40
40 namespace banners { 41 namespace banners {
41 42
42 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( 43 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid(
43 int event_request_id, 44 base::WeakPtr<AppBannerManager> weak_manager,
44 scoped_refptr<AppBannerDataFetcherAndroid> data_fetcher,
45 const base::string16& app_title, 45 const base::string16& app_title,
46 const GURL& app_icon_url,
47 SkBitmap* app_icon,
48 const GURL& manifest_url, 46 const GURL& manifest_url,
49 const content::Manifest& manifest) 47 const content::Manifest& manifest,
50 : data_fetcher_(data_fetcher), 48 const GURL& icon_url,
49 std::unique_ptr<SkBitmap> icon,
50 int event_request_id)
51 : weak_manager_(weak_manager),
51 app_title_(app_title), 52 app_title_(app_title),
52 app_icon_url_(app_icon_url),
53 app_icon_(app_icon),
54 event_request_id_(event_request_id),
55 manifest_url_(manifest_url), 53 manifest_url_(manifest_url),
56 manifest_(manifest), 54 manifest_(manifest),
55 icon_url_(icon_url),
56 icon_(std::move(icon)),
57 event_request_id_(event_request_id),
57 has_user_interaction_(false) { 58 has_user_interaction_(false) {
58 DCHECK(!manifest.IsEmpty()); 59 DCHECK(!manifest.IsEmpty());
59 CreateJavaDelegate(); 60 CreateJavaDelegate();
60 } 61 }
61 62
62 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( 63 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid(
63 int event_request_id,
64 const base::string16& app_title, 64 const base::string16& app_title,
65 SkBitmap* app_icon,
66 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, 65 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data,
66 std::unique_ptr<SkBitmap> icon,
67 const std::string& native_app_package, 67 const std::string& native_app_package,
68 const std::string& referrer) 68 const std::string& referrer,
69 int event_request_id)
69 : app_title_(app_title), 70 : app_title_(app_title),
70 app_icon_(app_icon),
71 event_request_id_(event_request_id),
72 native_app_data_(native_app_data), 71 native_app_data_(native_app_data),
72 icon_(std::move(icon)),
73 native_app_package_(native_app_package), 73 native_app_package_(native_app_package),
74 referrer_(referrer), 74 referrer_(referrer),
75 event_request_id_(event_request_id),
75 has_user_interaction_(false) { 76 has_user_interaction_(false) {
76 DCHECK(!native_app_data_.is_null()); 77 DCHECK(!native_app_data_.is_null());
77 CreateJavaDelegate(); 78 CreateJavaDelegate();
78 } 79 }
79 80
80 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { 81 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() {
81 if (!has_user_interaction_) { 82 if (!has_user_interaction_) {
82 if (!native_app_data_.is_null()) 83 if (!native_app_data_.is_null())
83 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED); 84 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED);
84 else if (!manifest_.IsEmpty()) 85 else if (!manifest_.IsEmpty())
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 InfoBarService::WebContentsFromInfoBar(infobar()); 118 InfoBarService::WebContentsFromInfoBar(infobar());
118 if (!web_contents) 119 if (!web_contents)
119 return; 120 return;
120 121
121 if (jis_installing) { 122 if (jis_installing) {
122 AppBannerSettingsHelper::RecordBannerEvent( 123 AppBannerSettingsHelper::RecordBannerEvent(
123 web_contents, 124 web_contents,
124 web_contents->GetURL(), 125 web_contents->GetURL(),
125 native_app_package_, 126 native_app_package_,
126 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, 127 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
127 AppBannerDataFetcher::GetCurrentTime()); 128 AppBannerManager::GetCurrentTime());
128 129
129 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_STARTED); 130 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_STARTED);
130 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), 131 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
131 "AppBanner.NativeApp.Installed", 132 "AppBanner.NativeApp.Installed",
132 web_contents->GetURL()); 133 web_contents->GetURL());
133 } 134 }
134 135
135 UpdateInstallState(env, obj); 136 UpdateInstallState(env, obj);
136 } 137 }
137 138
(...skipping 29 matching lines...) Expand all
167 event_request_id_, 168 event_request_id_,
168 platform)); 169 platform));
169 } 170 }
170 171
171 infobars::InfoBarDelegate::InfoBarIdentifier 172 infobars::InfoBarDelegate::InfoBarIdentifier
172 AppBannerInfoBarDelegateAndroid::GetIdentifier() const { 173 AppBannerInfoBarDelegateAndroid::GetIdentifier() const {
173 return APP_BANNER_INFOBAR_DELEGATE_ANDROID; 174 return APP_BANNER_INFOBAR_DELEGATE_ANDROID;
174 } 175 }
175 176
176 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const { 177 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const {
177 return gfx::Image::CreateFrom1xBitmap(*app_icon_.get()); 178 return gfx::Image::CreateFrom1xBitmap(*icon_.get());
178 } 179 }
179 180
180 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { 181 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() {
181 has_user_interaction_ = true; 182 has_user_interaction_ = true;
182 183
183 content::WebContents* web_contents = 184 content::WebContents* web_contents =
184 InfoBarService::WebContentsFromInfoBar(infobar()); 185 InfoBarService::WebContentsFromInfoBar(infobar());
185 if (!web_contents) 186 if (!web_contents)
186 return; 187 return;
187 188
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 247 }
247 SendBannerAccepted(web_contents, "play"); 248 SendBannerAccepted(web_contents, "play");
248 return was_opened; 249 return was_opened;
249 } else if (!manifest_.IsEmpty()) { 250 } else if (!manifest_.IsEmpty()) {
250 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); 251 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
251 252
252 AppBannerSettingsHelper::RecordBannerInstallEvent( 253 AppBannerSettingsHelper::RecordBannerInstallEvent(
253 web_contents, manifest_.start_url.spec(), 254 web_contents, manifest_.start_url.spec(),
254 AppBannerSettingsHelper::WEB); 255 AppBannerSettingsHelper::WEB);
255 256
256 ShortcutInfo info(GURL::EmptyGURL()); 257 if (weak_manager_) {
257 info.UpdateFromManifest(manifest_); 258 ShortcutInfo info(GURL::EmptyGURL());
258 info.manifest_url = manifest_url_; 259 info.UpdateFromManifest(manifest_);
259 info.icon_url = app_icon_url_; 260 info.manifest_url = manifest_url_;
260 info.UpdateSource(ShortcutInfo::SOURCE_APP_BANNER); 261 info.icon_url = icon_url_;
262 info.UpdateSource(ShortcutInfo::SOURCE_APP_BANNER);
261 263
262 const std::string& uid = base::GenerateGUID(); 264 const std::string& uid = base::GenerateGUID();
263 content::BrowserThread::PostTask( 265 content::BrowserThread::PostTask(
264 content::BrowserThread::IO, FROM_HERE, 266 content::BrowserThread::IO, FROM_HERE,
265 base::Bind(&ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap, 267 base::Bind(&ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap,
266 web_contents->GetBrowserContext(), info, uid, 268 web_contents->GetBrowserContext(), info, uid, *icon_.get(),
267 *app_icon_.get(), 269 weak_manager_->FetchWebappSplashScreenImageCallback(uid)));
268 data_fetcher_->FetchWebappSplashScreenImageCallback(uid))); 270 }
269 271
270 SendBannerAccepted(web_contents, "web"); 272 SendBannerAccepted(web_contents, "web");
271 return true; 273 return true;
272 } 274 }
273 275
274 return true; 276 return true;
275 } 277 }
276 278
277 bool AppBannerInfoBarDelegateAndroid::LinkClicked( 279 bool AppBannerInfoBarDelegateAndroid::LinkClicked(
278 WindowOpenDisposition disposition) { 280 WindowOpenDisposition disposition) {
(...skipping 19 matching lines...) Expand all
298 300
299 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); 301 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK);
300 return true; 302 return true;
301 } 303 }
302 304
303 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { 305 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) {
304 return RegisterNativesImpl(env); 306 return RegisterNativesImpl(env);
305 } 307 }
306 308
307 } // namespace banners 309 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698