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

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: 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
69 bool IsInstallabilityCheckCompleted(
70 InstallableMetrics::InstallabilityCheckStatus status) {
71 return status == InstallableMetrics::COMPLETE_PWA ||
72 status == InstallableMetrics::COMPLETE_NON_PWA;
73 }
74
64 } // namespace 75 } // namespace
65 76
66 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager); 77 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager);
67 78
68 struct InstallableManager::ManifestProperty { 79 struct InstallableManager::ManifestProperty {
69 InstallableStatusCode error = NO_ERROR_DETECTED; 80 InstallableStatusCode error = NO_ERROR_DETECTED;
70 GURL url; 81 GURL url;
71 content::Manifest manifest; 82 content::Manifest manifest;
72 bool fetched = false; 83 bool fetched = false;
73 }; 84 };
(...skipping 13 matching lines...) Expand all
87 InstallableStatusCode error = NO_ERROR_DETECTED; 98 InstallableStatusCode error = NO_ERROR_DETECTED;
88 GURL url; 99 GURL url;
89 std::unique_ptr<SkBitmap> icon; 100 std::unique_ptr<SkBitmap> icon;
90 bool fetched; 101 bool fetched;
91 102
92 private: 103 private:
93 // This class contains a std::unique_ptr and therefore must be move-only. 104 // This class contains a std::unique_ptr and therefore must be move-only.
94 DISALLOW_COPY_AND_ASSIGN(IconProperty); 105 DISALLOW_COPY_AND_ASSIGN(IconProperty);
95 }; 106 };
96 107
97
98 InstallableManager::InstallableManager(content::WebContents* web_contents) 108 InstallableManager::InstallableManager(content::WebContents* web_contents)
99 : content::WebContentsObserver(web_contents), 109 : content::WebContentsObserver(web_contents),
100 manifest_(new ManifestProperty()), 110 manifest_(new ManifestProperty()),
101 installable_(new InstallableProperty()), 111 installable_(new InstallableProperty()),
112 status_(InstallableMetrics::NOT_STARTED),
113 menu_opened_count_(0),
114 menu_item_add_to_homescreen_count_(0),
102 is_active_(false), 115 is_active_(false),
103 weak_factory_(this) { } 116 weak_factory_(this) {}
104 117
105 InstallableManager::~InstallableManager() = default; 118 InstallableManager::~InstallableManager() = default;
106 119
107 // static 120 // static
108 bool InstallableManager::IsContentSecure(content::WebContents* web_contents) { 121 bool InstallableManager::IsContentSecure(content::WebContents* web_contents) {
109 if (!web_contents) 122 if (!web_contents)
110 return false; 123 return false;
111 124
112 // Whitelist localhost. Check the VisibleURL to match what the 125 // Whitelist localhost. Check the VisibleURL to match what the
113 // SecurityStateTabHelper looks at. 126 // 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 146 // Return immediately if we're already working on a task. The new task will be
134 // looked at once the current task is finished. 147 // looked at once the current task is finished.
135 tasks_.push_back({params, callback}); 148 tasks_.push_back({params, callback});
136 if (is_active_) 149 if (is_active_)
137 return; 150 return;
138 151
139 is_active_ = true; 152 is_active_ = true;
140 StartNextTask(); 153 StartNextTask();
141 } 154 }
142 155
156 void InstallableManager::RecordMenuOpenHistogram() {
157 if (IsInstallabilityCheckCompleted(status_)) {
158 InstallableMetrics::RecordMenuOpenHistogram(status_);
159 } else {
160 ++menu_opened_count_;
161 }
162 }
163
164 void InstallableManager::RecordMenuItemAddToHomescreenHistogram() {
165 if (IsInstallabilityCheckCompleted(status_)) {
166 InstallableMetrics::RecordMenuItemAddToHomescreenHistogram(status_);
167 } else {
168 ++menu_item_add_to_homescreen_count_;
169 }
170 }
171
143 InstallableManager::IconParams InstallableManager::ParamsForPrimaryIcon( 172 InstallableManager::IconParams InstallableManager::ParamsForPrimaryIcon(
144 const InstallableParams& params) const { 173 const InstallableParams& params) const {
145 return std::make_tuple(params.ideal_primary_icon_size_in_px, 174 return std::make_tuple(params.ideal_primary_icon_size_in_px,
146 params.minimum_primary_icon_size_in_px, 175 params.minimum_primary_icon_size_in_px,
147 IconPurpose::ANY); 176 IconPurpose::ANY);
148 } 177 }
149 178
150 InstallableManager::IconParams InstallableManager::ParamsForBadgeIcon( 179 InstallableManager::IconParams InstallableManager::ParamsForBadgeIcon(
151 const InstallableParams& params) const { 180 const InstallableParams& params) const {
152 return std::make_tuple(params.ideal_badge_icon_size_in_px, 181 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 || 254 (!params.fetch_valid_badge_icon ||
226 IsIconFetched(ParamsForBadgeIcon(params))); 255 IsIconFetched(ParamsForBadgeIcon(params)));
227 } 256 }
228 257
229 void InstallableManager::Reset() { 258 void InstallableManager::Reset() {
230 // Prevent any outstanding callbacks to or from this object from being called. 259 // Prevent any outstanding callbacks to or from this object from being called.
231 weak_factory_.InvalidateWeakPtrs(); 260 weak_factory_.InvalidateWeakPtrs();
232 tasks_.clear(); 261 tasks_.clear();
233 icons_.clear(); 262 icons_.clear();
234 263
264 status_ = InstallableMetrics::NOT_STARTED;
265 menu_opened_count_ = 0;
266 menu_item_add_to_homescreen_count_ = 0;
267
235 manifest_.reset(new ManifestProperty()); 268 manifest_.reset(new ManifestProperty());
236 installable_.reset(new InstallableProperty()); 269 installable_.reset(new InstallableProperty());
237 270
238 is_active_ = false; 271 is_active_ = false;
239 } 272 }
240 273
241 void InstallableManager::SetManifestDependentTasksComplete() { 274 void InstallableManager::SetManifestDependentTasksComplete() {
242 DCHECK(!tasks_.empty()); 275 DCHECK(!tasks_.empty());
243 const InstallableParams& params = tasks_[0].first; 276 const InstallableParams& params = tasks_[0].first;
244 277
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 317
285 DCHECK(is_active_); 318 DCHECK(is_active_);
286 WorkOnTask(); 319 WorkOnTask();
287 } 320 }
288 321
289 void InstallableManager::WorkOnTask() { 322 void InstallableManager::WorkOnTask() {
290 DCHECK(!tasks_.empty()); 323 DCHECK(!tasks_.empty());
291 const Task& task = tasks_[0]; 324 const Task& task = tasks_[0];
292 const InstallableParams& params = task.first; 325 const InstallableParams& params = task.first;
293 326
327 if (status_ == InstallableMetrics::NOT_STARTED &&
328 IsParamsForPwaCheck(params)) {
329 // Use the NOT_COMPLETE_PWA state to represent the general case of the check
benwells 2017/03/30 08:22:37 You mean IN_PROGRESS_PWA?
dominickn 2017/03/30 23:42:52 Done.
330 // being in progress.
331 status_ = InstallableMetrics::IN_PROGRESS_PWA;
332 }
333
294 InstallableStatusCode code = GetErrorCode(params); 334 InstallableStatusCode code = GetErrorCode(params);
295 if (code != NO_ERROR_DETECTED || IsComplete(params)) { 335 bool check_passed = (code == NO_ERROR_DETECTED);
336 if (!check_passed || IsComplete(params)) {
337 if (status_ == InstallableMetrics::IN_PROGRESS_PWA &&
338 IsParamsForPwaCheck(params)) {
339 status_ = check_passed ? InstallableMetrics::COMPLETE_PWA
340 : InstallableMetrics::COMPLETE_NON_PWA;
341
342 // Compute what the status would have been and record metrics.
benwells 2017/03/30 08:22:37 Nit: 'would have been' -> 'would have been for any
dominickn 2017/03/30 23:42:53 Done.
343 InstallableMetrics::InstallabilityCheckStatus prev_status =
344 check_passed ? InstallableMetrics::IN_PROGRESS_PWA
345 : InstallableMetrics::IN_PROGRESS_NON_PWA;
pkotwicz 2017/03/30 20:48:25 What is the value of having both IN_PROGRESS_PWA a
dominickn 2017/03/30 23:42:52 This is not correct. RecordMenuOpenHistogram() onl
pkotwicz 2017/03/31 04:12:37 I understand. In this case the code on lines 327
dominickn 2017/03/31 04:59:17 Done, thanks!
346 while (menu_opened_count_-- > 0)
347 InstallableMetrics::RecordMenuOpenHistogram(prev_status);
348
349 while (menu_item_add_to_homescreen_count_-- > 0)
350 InstallableMetrics::RecordMenuItemAddToHomescreenHistogram(prev_status);
351
352 menu_opened_count_ = 0;
benwells 2017/03/30 08:22:37 Do you need to reset these two variables? They sho
dominickn 2017/03/30 23:42:52 The while loops may have set them to -1 if they st
benwells 2017/03/31 04:00:35 Ah ... I see. You could use a for loop instead: f
dominickn 2017/03/31 04:59:17 Changed to the for loop, that's a bit nicer.
353 menu_item_add_to_homescreen_count_ = 0;
354 }
355
296 RunCallback(task, code); 356 RunCallback(task, code);
pkotwicz 2017/03/30 20:48:25 I think that it would be clearer if the metrics re
dominickn 2017/03/30 23:42:53 RunCallback() already has to do a bunch of fetchin
pkotwicz 2017/03/31 04:12:37 I still think that RunCallback() is the correct lo
dominickn 2017/03/31 04:59:17 Acknowledged. I prefer it here as WorkOnTask is th
297 tasks_.erase(tasks_.begin()); 357 tasks_.erase(tasks_.begin());
298 StartNextTask(); 358 StartNextTask();
299 return; 359 return;
300 } 360 }
301 361
302 if (!manifest_->fetched) { 362 if (!manifest_->fetched) {
303 FetchManifest(); 363 FetchManifest();
304 } else if (params.check_installable && !installable_->fetched) { 364 } else if (params.check_installable && !installable_->fetched) {
305 CheckInstallable(); 365 CheckInstallable();
306 } else if (params.fetch_valid_primary_icon && 366 } else if (params.fetch_valid_primary_icon &&
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 return manifest_->url; 559 return manifest_->url;
500 } 560 }
501 561
502 const content::Manifest& InstallableManager::manifest() const { 562 const content::Manifest& InstallableManager::manifest() const {
503 return manifest_->manifest; 563 return manifest_->manifest;
504 } 564 }
505 565
506 bool InstallableManager::is_installable() const { 566 bool InstallableManager::is_installable() const {
507 return installable_->installable; 567 return installable_->installable;
508 } 568 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698