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

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

Issue 2778983005: Allow the app banner installability check to run on page load. (Closed)
Patch Set: Address comments 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 #ifndef CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ 5 #ifndef CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_
6 #define CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ 6 #define CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <tuple> 10 #include <tuple>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback_forward.h" 14 #include "base/callback_forward.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "chrome/browser/installable/installable_logging.h" 18 #include "chrome/browser/installable/installable_logging.h"
19 #include "chrome/browser/installable/installable_metrics.h"
19 #include "content/public/browser/service_worker_context.h" 20 #include "content/public/browser/service_worker_context.h"
20 #include "content/public/browser/web_contents_observer.h" 21 #include "content/public/browser/web_contents_observer.h"
21 #include "content/public/browser/web_contents_user_data.h" 22 #include "content/public/browser/web_contents_user_data.h"
22 #include "content/public/common/manifest.h" 23 #include "content/public/common/manifest.h"
23 #include "third_party/skia/include/core/SkBitmap.h" 24 #include "third_party/skia/include/core/SkBitmap.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 // This struct specifies the work to be done by the InstallableManager. 27 // This struct specifies the work to be done by the InstallableManager.
27 // Data is cached and fetched in the order specified in this struct. A web app 28 // Data is cached and fetched in the order specified in this struct. A web app
28 // manifest will always be fetched first. 29 // manifest will always be fetched first.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // Get the installable data, fetching the resources specified in |params|. 122 // Get the installable data, fetching the resources specified in |params|.
122 // |callback| is invoked synchronously (i.e. no via PostTask on the UI thread 123 // |callback| is invoked synchronously (i.e. no via PostTask on the UI thread
123 // when the data is ready; the synchronous execution ensures that the 124 // when the data is ready; the synchronous execution ensures that the
124 // references |callback| receives in its InstallableData argument are valid. 125 // references |callback| receives in its InstallableData argument are valid.
125 // 126 //
126 // Calls requesting data that is already fetched will return the cached data. 127 // Calls requesting data that is already fetched will return the cached data.
127 // This method is marked virtual so clients may mock this object in tests. 128 // This method is marked virtual so clients may mock this object in tests.
128 virtual void GetData(const InstallableParams& params, 129 virtual void GetData(const InstallableParams& params,
129 const InstallableCallback& callback); 130 const InstallableCallback& callback);
130 131
132 // Called via AppBannerManagerAndroid to record metrics on how often the
133 // installable check is completed when the menu or add to homescreen menu item
134 // is opened on Android.
135 void RecordMenuOpenHistogram();
136 void RecordMenuItemAddToHomescreenHistogram();
137 void RecordQueuedMetricsOnTaskCompletion(const InstallableParams& params,
138 bool check_passed);
139
131 private: 140 private:
141 friend class InstallableManagerBrowserTest;
132 friend class InstallableManagerUnitTest; 142 friend class InstallableManagerUnitTest;
133 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, 143 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest,
134 ManagerBeginsInEmptyState); 144 ManagerBeginsInEmptyState);
135 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, CheckWebapp); 145 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, CheckWebapp);
136 146
137 using Task = std::pair<InstallableParams, InstallableCallback>; 147 using Task = std::pair<InstallableParams, InstallableCallback>;
138 using IconParams = std::tuple<int, int, content::Manifest::Icon::IconPurpose>; 148 using IconParams = std::tuple<int, int, content::Manifest::Icon::IconPurpose>;
139 149
140 struct ManifestProperty; 150 struct ManifestProperty;
141 struct InstallableProperty; 151 struct InstallableProperty;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 bool is_installable() const; 221 bool is_installable() const;
212 222
213 // The list of <params, callback> pairs that have come from a call to GetData. 223 // The list of <params, callback> pairs that have come from a call to GetData.
214 std::vector<Task> tasks_; 224 std::vector<Task> tasks_;
215 225
216 // Installable properties cached on this object. 226 // Installable properties cached on this object.
217 std::unique_ptr<ManifestProperty> manifest_; 227 std::unique_ptr<ManifestProperty> manifest_;
218 std::unique_ptr<InstallableProperty> installable_; 228 std::unique_ptr<InstallableProperty> installable_;
219 std::map<IconParams, IconProperty> icons_; 229 std::map<IconParams, IconProperty> icons_;
220 230
231 // Whether or not the current page is a PWA. This is reset per navigation and
232 // is independent of the caching mechanism, i.e. if a PWA check is run
233 // multiple times for one page, this will be set on the first check.
234 InstallabilityCheckStatus page_status_;
235
236 // Counts for the number of queued requests of the menu and add to homescreen
237 // menu item there have been whilst the installable check is awaiting
238 // completion. Used for metrics recording.
239 int menu_open_count_;
240 int menu_item_add_to_homescreen_count_;
241
221 bool is_active_; 242 bool is_active_;
243 bool is_pwa_check_complete_;
222 244
223 base::WeakPtrFactory<InstallableManager> weak_factory_; 245 base::WeakPtrFactory<InstallableManager> weak_factory_;
224 246
225 DISALLOW_COPY_AND_ASSIGN(InstallableManager); 247 DISALLOW_COPY_AND_ASSIGN(InstallableManager);
226 }; 248 };
227 249
228 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ 250 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/engagement/site_engagement_service.h ('k') | chrome/browser/installable/installable_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698