| 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/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 // Returns true if |params| specifies a full PWA check. | 63 // Returns true if |params| specifies a full PWA check. |
| 64 bool IsParamsForPwaCheck(const InstallableParams& params) { | 64 bool IsParamsForPwaCheck(const InstallableParams& params) { |
| 65 return params.check_installable && params.fetch_valid_primary_icon; | 65 return params.check_installable && params.fetch_valid_primary_icon; |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager); | 70 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager); |
| 71 | 71 |
| 72 struct InstallableManager::ManifestProperty { | 72 InstallableManager::IconProperty::IconProperty() |
| 73 InstallableStatusCode error = NO_ERROR_DETECTED; | 73 : error(NO_ERROR_DETECTED), url(), icon(), fetched(false) {} |
| 74 GURL url; | |
| 75 content::Manifest manifest; | |
| 76 bool fetched = false; | |
| 77 }; | |
| 78 | 74 |
| 79 struct InstallableManager::ValidManifestProperty { | 75 InstallableManager::IconProperty::IconProperty(IconProperty&& other) = default; |
| 80 InstallableStatusCode error = NO_ERROR_DETECTED; | |
| 81 bool is_valid = false; | |
| 82 bool fetched = false; | |
| 83 }; | |
| 84 | 76 |
| 85 struct InstallableManager::ServiceWorkerProperty { | 77 InstallableManager::IconProperty::~IconProperty() {} |
| 86 InstallableStatusCode error = NO_ERROR_DETECTED; | |
| 87 bool has_worker = false; | |
| 88 bool fetched = false; | |
| 89 }; | |
| 90 | 78 |
| 91 struct InstallableManager::IconProperty { | 79 InstallableManager::IconProperty& InstallableManager::IconProperty::operator=( |
| 92 IconProperty() : | 80 InstallableManager::IconProperty&& other) = default; |
| 93 error(NO_ERROR_DETECTED), url(), icon(), fetched(false) { } | |
| 94 IconProperty(IconProperty&& other) = default; | |
| 95 IconProperty& operator=(IconProperty&& other) = default; | |
| 96 | |
| 97 InstallableStatusCode error = NO_ERROR_DETECTED; | |
| 98 GURL url; | |
| 99 std::unique_ptr<SkBitmap> icon; | |
| 100 bool fetched; | |
| 101 | |
| 102 private: | |
| 103 // This class contains a std::unique_ptr and therefore must be move-only. | |
| 104 DISALLOW_COPY_AND_ASSIGN(IconProperty); | |
| 105 }; | |
| 106 | 81 |
| 107 InstallableManager::InstallableManager(content::WebContents* web_contents) | 82 InstallableManager::InstallableManager(content::WebContents* web_contents) |
| 108 : content::WebContentsObserver(web_contents), | 83 : content::WebContentsObserver(web_contents), |
| 109 manifest_(base::MakeUnique<ManifestProperty>()), | 84 manifest_(base::MakeUnique<ManifestProperty>()), |
| 110 valid_manifest_(base::MakeUnique<ValidManifestProperty>()), | 85 valid_manifest_(base::MakeUnique<ValidManifestProperty>()), |
| 111 worker_(base::MakeUnique<ServiceWorkerProperty>()), | 86 worker_(base::MakeUnique<ServiceWorkerProperty>()), |
| 112 service_worker_context_(nullptr), | 87 service_worker_context_(nullptr), |
| 113 page_status_(InstallabilityCheckStatus::NOT_STARTED), | 88 page_status_(InstallabilityCheckStatus::NOT_STARTED), |
| 114 menu_open_count_(0), | 89 menu_open_count_(0), |
| 115 menu_item_add_to_homescreen_count_(0), | 90 menu_item_add_to_homescreen_count_(0), |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 return manifest_->url; | 628 return manifest_->url; |
| 654 } | 629 } |
| 655 | 630 |
| 656 const content::Manifest& InstallableManager::manifest() const { | 631 const content::Manifest& InstallableManager::manifest() const { |
| 657 return manifest_->manifest; | 632 return manifest_->manifest; |
| 658 } | 633 } |
| 659 | 634 |
| 660 bool InstallableManager::is_installable() const { | 635 bool InstallableManager::is_installable() const { |
| 661 return valid_manifest_->is_valid && worker_->has_worker; | 636 return valid_manifest_->is_valid && worker_->has_worker; |
| 662 } | 637 } |
| OLD | NEW |