Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 const InstallableCallback& callback) { | 138 const InstallableCallback& callback) { |
| 139 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 139 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 140 | 140 |
| 141 // 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 |
| 142 // looked at once the current task is finished. | 142 // looked at once the current task is finished. |
| 143 tasks_.push_back({params, callback}); | 143 tasks_.push_back({params, callback}); |
| 144 if (is_active_) | 144 if (is_active_) |
| 145 return; | 145 return; |
| 146 | 146 |
| 147 is_active_ = true; | 147 is_active_ = true; |
| 148 if (page_status_ == InstallabilityCheckStatus::NOT_STARTED) | |
| 149 page_status_ = InstallabilityCheckStatus::NOT_COMPLETED; | |
| 148 StartNextTask(); | 150 StartNextTask(); |
| 149 } | 151 } |
| 150 | 152 |
| 151 void InstallableManager::RecordMenuOpenHistogram() { | 153 void InstallableManager::RecordMenuOpenHistogram() { |
| 152 if (is_pwa_check_complete_) | 154 if (is_pwa_check_complete_) |
| 153 InstallableMetrics::RecordMenuOpenHistogram(page_status_); | 155 InstallableMetrics::RecordMenuOpenHistogram(page_status_); |
| 154 else | 156 else |
| 155 ++menu_open_count_; | 157 ++menu_open_count_; |
| 156 } | 158 } |
| 157 | 159 |
| 158 void InstallableManager::RecordMenuItemAddToHomescreenHistogram() { | 160 void InstallableManager::RecordMenuItemAddToHomescreenHistogram() { |
| 159 if (is_pwa_check_complete_) | 161 if (is_pwa_check_complete_) |
| 160 InstallableMetrics::RecordMenuItemAddToHomescreenHistogram(page_status_); | 162 InstallableMetrics::RecordMenuItemAddToHomescreenHistogram(page_status_); |
| 161 else | 163 else |
| 162 ++menu_item_add_to_homescreen_count_; | 164 ++menu_item_add_to_homescreen_count_; |
| 163 } | 165 } |
| 164 | 166 |
| 165 void InstallableManager::RecordQueuedMetricsOnTaskCompletion( | 167 void InstallableManager::RecordQueuedMetricsOnTaskCompletion( |
| 166 const InstallableParams& params, | 168 const InstallableParams& params, |
| 167 bool check_passed) { | 169 bool check_passed) { |
| 168 // Don't do anything if we've already finished the PWA check or if this check | 170 // Don't do anything if we've: |
| 169 // was not for the full PWA params. Once a full check is completed, metrics | 171 // - already finished the PWA check, or |
| 170 // will be directly recorded in Record*Histogram since | 172 // - we passed the check AND it was not for the full PWA params. |
| 171 // |is_pwa_check_complete_| will be true. | 173 // In the latter case, we know if we passed the check and we weren't checking |
| 172 if (is_pwa_check_complete_ || !IsParamsForPwaCheck(params)) | 174 // the full params, we don't yet know if the site is installable. However, any |
|
benwells
2017/05/04 05:05:13
This comment is confusing - it's basically saying
dominickn
2017/05/04 05:18:56
Done.
| |
| 175 // failure means that we will never pass the check. | |
| 176 // | |
| 177 // Once a full check is completed, metrics will be directly recorded in | |
| 178 // Record*Histogram since |is_pwa_check_complete_| will be true. | |
| 179 if (is_pwa_check_complete_ || (check_passed && !IsParamsForPwaCheck(params))) | |
| 173 return; | 180 return; |
| 174 | 181 |
| 175 is_pwa_check_complete_ = true; | 182 is_pwa_check_complete_ = true; |
| 176 page_status_ = | 183 page_status_ = |
| 177 check_passed | 184 check_passed |
| 178 ? InstallabilityCheckStatus::COMPLETE_PROGRESSIVE_WEB_APP | 185 ? InstallabilityCheckStatus::COMPLETE_PROGRESSIVE_WEB_APP |
| 179 : InstallabilityCheckStatus::COMPLETE_NON_PROGRESSIVE_WEB_APP; | 186 : InstallabilityCheckStatus::COMPLETE_NON_PROGRESSIVE_WEB_APP; |
| 180 | 187 |
| 181 // Compute what the status would have been for any queued calls to | 188 // Compute what the status would have been for any queued calls to |
| 182 // Record*Histogram, and record appropriately. | 189 // Record*Histogram, and record appropriately. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 IsIconFetched(ParamsForBadgeIcon(params))); | 295 IsIconFetched(ParamsForBadgeIcon(params))); |
| 289 } | 296 } |
| 290 | 297 |
| 291 void InstallableManager::Reset() { | 298 void InstallableManager::Reset() { |
| 292 // Prevent any outstanding callbacks to or from this object from being called. | 299 // Prevent any outstanding callbacks to or from this object from being called. |
| 293 weak_factory_.InvalidateWeakPtrs(); | 300 weak_factory_.InvalidateWeakPtrs(); |
| 294 tasks_.clear(); | 301 tasks_.clear(); |
| 295 icons_.clear(); | 302 icons_.clear(); |
| 296 | 303 |
| 297 // We may have reset prior to completion, in which case |menu_open_count_| or | 304 // We may have reset prior to completion, in which case |menu_open_count_| or |
| 298 // |menu_item_add_to_homescreen_count_| will be nonzero. If we completed, then | 305 // |menu_item_add_to_homescreen_count_| might be nonzero and |page_status_| is |
| 299 // these values cannot be anything except 0. | 306 // one of NOT_STARTED or NOT_COMPLETED. If we completed, then these values |
| 300 page_status_ = InstallabilityCheckStatus::NOT_STARTED; | 307 // cannot be anything except 0. |
| 301 is_pwa_check_complete_ = false; | 308 is_pwa_check_complete_ = false; |
| 302 | 309 |
| 303 for (; menu_open_count_ > 0; --menu_open_count_) { | 310 for (; menu_open_count_ > 0; --menu_open_count_) |
| 304 InstallableMetrics::RecordMenuOpenHistogram( | 311 InstallableMetrics::RecordMenuOpenHistogram(page_status_); |
| 305 InstallabilityCheckStatus::STOPPED_BEFORE_COMPLETION); | |
| 306 } | |
| 307 | 312 |
| 308 for (; menu_item_add_to_homescreen_count_ > 0; | 313 for (; menu_item_add_to_homescreen_count_ > 0; |
| 309 --menu_item_add_to_homescreen_count_) { | 314 --menu_item_add_to_homescreen_count_) { |
| 310 InstallableMetrics::RecordMenuItemAddToHomescreenHistogram( | 315 InstallableMetrics::RecordMenuItemAddToHomescreenHistogram(page_status_); |
| 311 InstallabilityCheckStatus::STOPPED_BEFORE_COMPLETION); | |
| 312 } | 316 } |
| 313 | 317 |
| 318 page_status_ = InstallabilityCheckStatus::NOT_STARTED; | |
| 314 manifest_.reset(new ManifestProperty()); | 319 manifest_.reset(new ManifestProperty()); |
| 315 installable_.reset(new InstallableProperty()); | 320 installable_.reset(new InstallableProperty()); |
| 316 | 321 |
| 317 is_active_ = false; | 322 is_active_ = false; |
| 318 } | 323 } |
| 319 | 324 |
| 320 void InstallableManager::SetManifestDependentTasksComplete() { | 325 void InstallableManager::SetManifestDependentTasksComplete() { |
| 321 DCHECK(!tasks_.empty()); | 326 DCHECK(!tasks_.empty()); |
| 322 const InstallableParams& params = tasks_[0].first; | 327 const InstallableParams& params = tasks_[0].first; |
| 323 | 328 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 return manifest_->url; | 585 return manifest_->url; |
| 581 } | 586 } |
| 582 | 587 |
| 583 const content::Manifest& InstallableManager::manifest() const { | 588 const content::Manifest& InstallableManager::manifest() const { |
| 584 return manifest_->manifest; | 589 return manifest_->manifest; |
| 585 } | 590 } |
| 586 | 591 |
| 587 bool InstallableManager::is_installable() const { | 592 bool InstallableManager::is_installable() const { |
| 588 return installable_->installable; | 593 return installable_->installable; |
| 589 } | 594 } |
| OLD | NEW |