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

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

Issue 2960103002: Improve add to homescreen data fetcher unit tests. (Closed)
Patch Set: Comments Created 3 years, 5 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/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
91 struct InstallableManager::IconProperty {
92 IconProperty() :
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 78
107 InstallableManager::InstallableManager(content::WebContents* web_contents) 79 InstallableManager::InstallableManager(content::WebContents* web_contents)
108 : content::WebContentsObserver(web_contents), 80 : content::WebContentsObserver(web_contents),
109 manifest_(base::MakeUnique<ManifestProperty>()), 81 manifest_(base::MakeUnique<ManifestProperty>()),
110 valid_manifest_(base::MakeUnique<ValidManifestProperty>()), 82 valid_manifest_(base::MakeUnique<ValidManifestProperty>()),
111 worker_(base::MakeUnique<ServiceWorkerProperty>()), 83 worker_(base::MakeUnique<ServiceWorkerProperty>()),
112 service_worker_context_(nullptr), 84 service_worker_context_(nullptr),
113 page_status_(InstallabilityCheckStatus::NOT_STARTED), 85 page_status_(InstallabilityCheckStatus::NOT_STARTED),
114 menu_open_count_(0), 86 menu_open_count_(0),
115 menu_item_add_to_homescreen_count_(0), 87 menu_item_add_to_homescreen_count_(0),
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 return manifest_->url; 625 return manifest_->url;
654 } 626 }
655 627
656 const content::Manifest& InstallableManager::manifest() const { 628 const content::Manifest& InstallableManager::manifest() const {
657 return manifest_->manifest; 629 return manifest_->manifest;
658 } 630 }
659 631
660 bool InstallableManager::is_installable() const { 632 bool InstallableManager::is_installable() const {
661 return valid_manifest_->is_valid && worker_->has_worker; 633 return valid_manifest_->is_valid && worker_->has_worker;
662 } 634 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698