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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 void AddToHomescreenDialogHelper::AddShortcut(const ShortcutInfo& info, | 115 void AddToHomescreenDialogHelper::AddShortcut(const ShortcutInfo& info, |
116 const SkBitmap& icon) { | 116 const SkBitmap& icon) { |
117 DCHECK(add_shortcut_pending_); | 117 DCHECK(add_shortcut_pending_); |
118 if (!add_shortcut_pending_) | 118 if (!add_shortcut_pending_) |
119 return; | 119 return; |
120 add_shortcut_pending_ = false; | 120 add_shortcut_pending_ = false; |
121 | 121 |
| 122 content::WebContents* web_contents = data_fetcher_->web_contents(); |
| 123 if (!web_contents) |
| 124 return; |
| 125 |
122 RecordAddToHomescreen(); | 126 RecordAddToHomescreen(); |
123 | 127 |
124 const std::string& uid = base::GenerateGUID(); | 128 const std::string& uid = base::GenerateGUID(); |
125 content::BrowserThread::PostTask( | 129 content::BrowserThread::PostTask( |
126 content::BrowserThread::IO, FROM_HERE, | 130 content::BrowserThread::IO, FROM_HERE, |
127 base::Bind(&ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap, info, | 131 base::Bind(&ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap, |
128 uid, icon, | 132 web_contents->GetBrowserContext(), info, uid, icon, |
129 data_fetcher_->FetchSplashScreenImageCallback(uid))); | 133 data_fetcher_->FetchSplashScreenImageCallback(uid))); |
130 } | 134 } |
131 | 135 |
132 bool AddToHomescreenDialogHelper::RegisterAddToHomescreenDialogHelper( | 136 bool AddToHomescreenDialogHelper::RegisterAddToHomescreenDialogHelper( |
133 JNIEnv* env) { | 137 JNIEnv* env) { |
134 return RegisterNativesImpl(env); | 138 return RegisterNativesImpl(env); |
135 } | 139 } |
136 | 140 |
137 void AddToHomescreenDialogHelper::RecordAddToHomescreen() { | 141 void AddToHomescreenDialogHelper::RecordAddToHomescreen() { |
138 // Record that the shortcut has been added, so no banners will be shown | 142 // Record that the shortcut has been added, so no banners will be shown |
139 // for this app. | 143 // for this app. |
140 content::WebContents* web_contents = data_fetcher_->web_contents(); | 144 content::WebContents* web_contents = data_fetcher_->web_contents(); |
141 if (!web_contents) | 145 if (!web_contents) |
142 return; | 146 return; |
143 | 147 |
144 AppBannerSettingsHelper::RecordBannerEvent( | 148 AppBannerSettingsHelper::RecordBannerEvent( |
145 web_contents, web_contents->GetURL(), | 149 web_contents, web_contents->GetURL(), |
146 data_fetcher_->shortcut_info().url.spec(), | 150 data_fetcher_->shortcut_info().url.spec(), |
147 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | 151 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
148 base::Time::Now()); | 152 base::Time::Now()); |
149 } | 153 } |
OLD | NEW |