Chromium Code Reviews| Index: chrome/browser/installable/installable_manager.cc |
| diff --git a/chrome/browser/installable/installable_manager.cc b/chrome/browser/installable/installable_manager.cc |
| index b0bf4496513b77bdd42977cfe2e53435a498d2dc..9199d8eb3903e6ce4e9eea01ad92fed9cbfc5c8f 100644 |
| --- a/chrome/browser/installable/installable_manager.cc |
| +++ b/chrome/browser/installable/installable_manager.cc |
| @@ -61,6 +61,17 @@ bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) { |
| return false; |
| } |
| +// Returns true if |params| specifies a full PWA check. |
| +bool IsParamsForPwaCheck(const InstallableParams& params) { |
| + return params.check_installable && params.fetch_valid_primary_icon; |
| +} |
| + |
| +bool IsInstallabilityCheckCompleted( |
| + InstallableMetrics::InstallabilityCheckStatus status) { |
| + return status == InstallableMetrics::COMPLETE_PWA || |
| + status == InstallableMetrics::COMPLETE_NON_PWA; |
| +} |
| + |
| } // namespace |
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager); |
| @@ -94,13 +105,15 @@ struct InstallableManager::IconProperty { |
| DISALLOW_COPY_AND_ASSIGN(IconProperty); |
| }; |
| - |
| InstallableManager::InstallableManager(content::WebContents* web_contents) |
| : content::WebContentsObserver(web_contents), |
| manifest_(new ManifestProperty()), |
| installable_(new InstallableProperty()), |
| + status_(InstallableMetrics::NOT_STARTED), |
| + menu_opened_count_(0), |
| + menu_item_add_to_homescreen_count_(0), |
| is_active_(false), |
| - weak_factory_(this) { } |
| + weak_factory_(this) {} |
| InstallableManager::~InstallableManager() = default; |
| @@ -140,6 +153,22 @@ void InstallableManager::GetData(const InstallableParams& params, |
| StartNextTask(); |
| } |
| +void InstallableManager::RecordMenuOpenHistogram() { |
| + if (IsInstallabilityCheckCompleted(status_)) { |
| + InstallableMetrics::RecordMenuOpenHistogram(status_); |
| + } else { |
| + ++menu_opened_count_; |
| + } |
| +} |
| + |
| +void InstallableManager::RecordMenuItemAddToHomescreenHistogram() { |
| + if (IsInstallabilityCheckCompleted(status_)) { |
| + InstallableMetrics::RecordMenuItemAddToHomescreenHistogram(status_); |
| + } else { |
| + ++menu_item_add_to_homescreen_count_; |
| + } |
| +} |
| + |
| InstallableManager::IconParams InstallableManager::ParamsForPrimaryIcon( |
| const InstallableParams& params) const { |
| return std::make_tuple(params.ideal_primary_icon_size_in_px, |
| @@ -232,6 +261,10 @@ void InstallableManager::Reset() { |
| tasks_.clear(); |
| icons_.clear(); |
| + status_ = InstallableMetrics::NOT_STARTED; |
| + menu_opened_count_ = 0; |
| + menu_item_add_to_homescreen_count_ = 0; |
| + |
| manifest_.reset(new ManifestProperty()); |
| installable_.reset(new InstallableProperty()); |
| @@ -291,8 +324,35 @@ void InstallableManager::WorkOnTask() { |
| const Task& task = tasks_[0]; |
| const InstallableParams& params = task.first; |
| + if (status_ == InstallableMetrics::NOT_STARTED && |
| + IsParamsForPwaCheck(params)) { |
| + // 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.
|
| + // being in progress. |
| + status_ = InstallableMetrics::IN_PROGRESS_PWA; |
| + } |
| + |
| InstallableStatusCode code = GetErrorCode(params); |
| - if (code != NO_ERROR_DETECTED || IsComplete(params)) { |
| + bool check_passed = (code == NO_ERROR_DETECTED); |
| + if (!check_passed || IsComplete(params)) { |
| + if (status_ == InstallableMetrics::IN_PROGRESS_PWA && |
| + IsParamsForPwaCheck(params)) { |
| + status_ = check_passed ? InstallableMetrics::COMPLETE_PWA |
| + : InstallableMetrics::COMPLETE_NON_PWA; |
| + |
| + // 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.
|
| + InstallableMetrics::InstallabilityCheckStatus prev_status = |
| + check_passed ? InstallableMetrics::IN_PROGRESS_PWA |
| + : 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!
|
| + while (menu_opened_count_-- > 0) |
| + InstallableMetrics::RecordMenuOpenHistogram(prev_status); |
| + |
| + while (menu_item_add_to_homescreen_count_-- > 0) |
| + InstallableMetrics::RecordMenuItemAddToHomescreenHistogram(prev_status); |
| + |
| + 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.
|
| + menu_item_add_to_homescreen_count_ = 0; |
| + } |
| + |
| 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
|
| tasks_.erase(tasks_.begin()); |
| StartNextTask(); |