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

Side by Side Diff: chrome/browser/installable/installable_manager.cc

Issue 2778983005: Allow the app banner installability check to run on page load. (Closed)
Patch Set: Address comments Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/installable/installable_manager.h" 5 #include "chrome/browser/installable/installable_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "chrome/browser/manifest/manifest_icon_downloader.h" 10 #include "chrome/browser/manifest/manifest_icon_downloader.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 if (size.width() >= kIconMinimumSizeInPx && 54 if (size.width() >= kIconMinimumSizeInPx &&
55 size.height() >= kIconMinimumSizeInPx) { 55 size.height() >= kIconMinimumSizeInPx) {
56 return true; 56 return true;
57 } 57 }
58 } 58 }
59 } 59 }
60 60
61 return false; 61 return false;
62 } 62 }
63 63
64 // Returns true if |params| specifies a full PWA check.
65 bool IsParamsForPwaCheck(const InstallableParams& params) {
66 return params.check_installable && params.fetch_valid_primary_icon;
67 }
68
64 } // namespace 69 } // namespace
65 70
66 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager); 71 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager);
67 72
68 struct InstallableManager::ManifestProperty { 73 struct InstallableManager::ManifestProperty {
69 InstallableStatusCode error = NO_ERROR_DETECTED; 74 InstallableStatusCode error = NO_ERROR_DETECTED;
70 GURL url; 75 GURL url;
71 content::Manifest manifest; 76 content::Manifest manifest;
72 bool fetched = false; 77 bool fetched = false;
73 }; 78 };
(...skipping 13 matching lines...) Expand all
87 InstallableStatusCode error = NO_ERROR_DETECTED; 92 InstallableStatusCode error = NO_ERROR_DETECTED;
88 GURL url; 93 GURL url;
89 std::unique_ptr<SkBitmap> icon; 94 std::unique_ptr<SkBitmap> icon;
90 bool fetched; 95 bool fetched;
91 96
92 private: 97 private:
93 // This class contains a std::unique_ptr and therefore must be move-only. 98 // This class contains a std::unique_ptr and therefore must be move-only.
94 DISALLOW_COPY_AND_ASSIGN(IconProperty); 99 DISALLOW_COPY_AND_ASSIGN(IconProperty);
95 }; 100 };
96 101
97
98 InstallableManager::InstallableManager(content::WebContents* web_contents) 102 InstallableManager::InstallableManager(content::WebContents* web_contents)
99 : content::WebContentsObserver(web_contents), 103 : content::WebContentsObserver(web_contents),
100 manifest_(new ManifestProperty()), 104 manifest_(new ManifestProperty()),
101 installable_(new InstallableProperty()), 105 installable_(new InstallableProperty()),
106 page_status_(InstallabilityCheckStatus::NOT_STARTED),
107 menu_open_count_(0),
108 menu_item_add_to_homescreen_count_(0),
102 is_active_(false), 109 is_active_(false),
103 weak_factory_(this) { } 110 is_pwa_check_complete_(false),
111 weak_factory_(this) {}
104 112
105 InstallableManager::~InstallableManager() = default; 113 InstallableManager::~InstallableManager() = default;
106 114
107 // static 115 // static
108 bool InstallableManager::IsContentSecure(content::WebContents* web_contents) { 116 bool InstallableManager::IsContentSecure(content::WebContents* web_contents) {
109 if (!web_contents) 117 if (!web_contents)
110 return false; 118 return false;
111 119
112 // Whitelist localhost. Check the VisibleURL to match what the 120 // Whitelist localhost. Check the VisibleURL to match what the
113 // SecurityStateTabHelper looks at. 121 // SecurityStateTabHelper looks at.
(...skipping 19 matching lines...) Expand all
133 // Return immediately if we're already working on a task. The new task will be 141 // Return immediately if we're already working on a task. The new task will be
134 // looked at once the current task is finished. 142 // looked at once the current task is finished.
135 tasks_.push_back({params, callback}); 143 tasks_.push_back({params, callback});
136 if (is_active_) 144 if (is_active_)
137 return; 145 return;
138 146
139 is_active_ = true; 147 is_active_ = true;
140 StartNextTask(); 148 StartNextTask();
141 } 149 }
142 150
151 void InstallableManager::RecordMenuOpenHistogram() {
152 if (is_pwa_check_complete_)
153 InstallableMetrics::RecordMenuOpenHistogram(page_status_);
154 else
155 ++menu_open_count_;
156 }
157
158 void InstallableManager::RecordMenuItemAddToHomescreenHistogram() {
159 if (is_pwa_check_complete_)
160 InstallableMetrics::RecordMenuItemAddToHomescreenHistogram(page_status_);
161 else
162 ++menu_item_add_to_homescreen_count_;
163 }
164
165 void InstallableManager::RecordQueuedMetricsOnTaskCompletion(
166 const InstallableParams& params,
167 bool check_passed) {
168 // Don't do anything if we've already finished the PWA check or if this check
169 // was not for the full PWA params. Once a full check is completed, metrics
170 // will be directly recorded in Record*Histogram since
171 // |is_pwa_check_complete_| will be true.
172 if (is_pwa_check_complete_ || !IsParamsForPwaCheck(params))
173 return;
174
175 is_pwa_check_complete_ = true;
176 page_status_ =
177 check_passed
178 ? InstallabilityCheckStatus::COMPLETE_PROGRESSIVE_WEB_APP
179 : InstallabilityCheckStatus::COMPLETE_NON_PROGRESSIVE_WEB_APP;
180
181 // Compute what the status would have been for any queued calls to
182 // Record*Histogram, and record appropriately.
183 InstallabilityCheckStatus prev_status =
184 check_passed
185 ? InstallabilityCheckStatus::IN_PROGRESS_PROGRESSIVE_WEB_APP
186 : InstallabilityCheckStatus::IN_PROGRESS_NON_PROGRESSIVE_WEB_APP;
187 for (; menu_open_count_ > 0; --menu_open_count_)
188 InstallableMetrics::RecordMenuOpenHistogram(prev_status);
189
190 for (; menu_item_add_to_homescreen_count_ > 0;
191 --menu_item_add_to_homescreen_count_) {
192 InstallableMetrics::RecordMenuItemAddToHomescreenHistogram(prev_status);
193 }
194 }
195
143 InstallableManager::IconParams InstallableManager::ParamsForPrimaryIcon( 196 InstallableManager::IconParams InstallableManager::ParamsForPrimaryIcon(
144 const InstallableParams& params) const { 197 const InstallableParams& params) const {
145 return std::make_tuple(params.ideal_primary_icon_size_in_px, 198 return std::make_tuple(params.ideal_primary_icon_size_in_px,
146 params.minimum_primary_icon_size_in_px, 199 params.minimum_primary_icon_size_in_px,
147 IconPurpose::ANY); 200 IconPurpose::ANY);
148 } 201 }
149 202
150 InstallableManager::IconParams InstallableManager::ParamsForBadgeIcon( 203 InstallableManager::IconParams InstallableManager::ParamsForBadgeIcon(
151 const InstallableParams& params) const { 204 const InstallableParams& params) const {
152 return std::make_tuple(params.ideal_badge_icon_size_in_px, 205 return std::make_tuple(params.ideal_badge_icon_size_in_px,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 (!params.fetch_valid_badge_icon || 278 (!params.fetch_valid_badge_icon ||
226 IsIconFetched(ParamsForBadgeIcon(params))); 279 IsIconFetched(ParamsForBadgeIcon(params)));
227 } 280 }
228 281
229 void InstallableManager::Reset() { 282 void InstallableManager::Reset() {
230 // Prevent any outstanding callbacks to or from this object from being called. 283 // Prevent any outstanding callbacks to or from this object from being called.
231 weak_factory_.InvalidateWeakPtrs(); 284 weak_factory_.InvalidateWeakPtrs();
232 tasks_.clear(); 285 tasks_.clear();
233 icons_.clear(); 286 icons_.clear();
234 287
288 // We may have reset prior to completion, in which case |menu_open_count_| or
289 // |menu_item_add_to_homescreen_count_| will be nonzero. If we completed, then
290 // these values cannot be anything except 0.
291 page_status_ = InstallabilityCheckStatus::NOT_STARTED;
292 is_pwa_check_complete_ = false;
293
294 for (; menu_open_count_ > 0; --menu_open_count_) {
295 InstallableMetrics::RecordMenuOpenHistogram(
296 InstallabilityCheckStatus::STOPPED_BEFORE_COMPLETION);
297 }
298
299 for (; menu_item_add_to_homescreen_count_ > 0;
300 --menu_item_add_to_homescreen_count_) {
301 InstallableMetrics::RecordMenuItemAddToHomescreenHistogram(
302 InstallabilityCheckStatus::STOPPED_BEFORE_COMPLETION);
303 }
304
235 manifest_.reset(new ManifestProperty()); 305 manifest_.reset(new ManifestProperty());
236 installable_.reset(new InstallableProperty()); 306 installable_.reset(new InstallableProperty());
237 307
238 is_active_ = false; 308 is_active_ = false;
239 } 309 }
240 310
241 void InstallableManager::SetManifestDependentTasksComplete() { 311 void InstallableManager::SetManifestDependentTasksComplete() {
242 DCHECK(!tasks_.empty()); 312 DCHECK(!tasks_.empty());
243 const InstallableParams& params = tasks_[0].first; 313 const InstallableParams& params = tasks_[0].first;
244 314
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 DCHECK(is_active_); 355 DCHECK(is_active_);
286 WorkOnTask(); 356 WorkOnTask();
287 } 357 }
288 358
289 void InstallableManager::WorkOnTask() { 359 void InstallableManager::WorkOnTask() {
290 DCHECK(!tasks_.empty()); 360 DCHECK(!tasks_.empty());
291 const Task& task = tasks_[0]; 361 const Task& task = tasks_[0];
292 const InstallableParams& params = task.first; 362 const InstallableParams& params = task.first;
293 363
294 InstallableStatusCode code = GetErrorCode(params); 364 InstallableStatusCode code = GetErrorCode(params);
295 if (code != NO_ERROR_DETECTED || IsComplete(params)) { 365 bool check_passed = (code == NO_ERROR_DETECTED);
366 if (!check_passed || IsComplete(params)) {
367 RecordQueuedMetricsOnTaskCompletion(params, check_passed);
296 RunCallback(task, code); 368 RunCallback(task, code);
297 tasks_.erase(tasks_.begin()); 369 tasks_.erase(tasks_.begin());
298 StartNextTask(); 370 StartNextTask();
299 return; 371 return;
300 } 372 }
301 373
302 if (!manifest_->fetched) { 374 if (!manifest_->fetched) {
303 FetchManifest(); 375 FetchManifest();
304 } else if (params.check_installable && !installable_->fetched) { 376 } else if (params.check_installable && !installable_->fetched) {
305 CheckInstallable(); 377 CheckInstallable();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 return manifest_->url; 571 return manifest_->url;
500 } 572 }
501 573
502 const content::Manifest& InstallableManager::manifest() const { 574 const content::Manifest& InstallableManager::manifest() const {
503 return manifest_->manifest; 575 return manifest_->manifest;
504 } 576 }
505 577
506 bool InstallableManager::is_installable() const { 578 bool InstallableManager::is_installable() const {
507 return installable_->installable; 579 return installable_->installable;
508 } 580 }
OLDNEW
« no previous file with comments | « chrome/browser/installable/installable_manager.h ('k') | chrome/browser/installable/installable_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698