Commit b69056dc authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

WebApps: Replace install_source with Histogram enum in WebAppDataRetriever::GetIcons()

This is a simple refactor CL that replaces the WebappInstallSource
parameter in WebAppDataRetriever with WebAppIconDownloader::Histogram.
This removes the strong dependency on install_source in preparation for update
install tasks that don't have an install_source:
https://chromium-review.googlesource.com/c/chromium/src/+/1811402

Bug: 926083
Change-Id: I239d5094f545a5d86d2d282ed53185de935caa22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837573
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705851}
parent c628e7b0
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/installable/installable_data.h" #include "chrome/browser/installable/installable_data.h"
#include "chrome/browser/installable/installable_manager.h" #include "chrome/browser/installable/installable_manager.h"
#include "chrome/browser/installable/installable_metrics.h"
#include "chrome/browser/web_applications/components/web_app_icon_downloader.h"
#include "chrome/browser/web_applications/components/web_app_icon_generator.h" #include "chrome/browser/web_applications/components/web_app_icon_generator.h"
#include "chrome/common/chrome_render_frame.mojom.h" #include "chrome/common/chrome_render_frame.mojom.h"
#include "chrome/common/web_application_info.h" #include "chrome/common/web_application_info.h"
...@@ -101,7 +99,7 @@ void WebAppDataRetriever::CheckInstallabilityAndRetrieveManifest( ...@@ -101,7 +99,7 @@ void WebAppDataRetriever::CheckInstallabilityAndRetrieveManifest(
void WebAppDataRetriever::GetIcons(content::WebContents* web_contents, void WebAppDataRetriever::GetIcons(content::WebContents* web_contents,
const std::vector<GURL>& icon_urls, const std::vector<GURL>& icon_urls,
bool skip_page_favicons, bool skip_page_favicons,
WebappInstallSource install_source, WebAppIconDownloader::Histogram histogram,
GetIconsCallback callback) { GetIconsCallback callback) {
Observe(web_contents); Observe(web_contents);
...@@ -109,14 +107,9 @@ void WebAppDataRetriever::GetIcons(content::WebContents* web_contents, ...@@ -109,14 +107,9 @@ void WebAppDataRetriever::GetIcons(content::WebContents* web_contents,
CHECK(!get_icons_callback_); CHECK(!get_icons_callback_);
get_icons_callback_ = std::move(callback); get_icons_callback_ = std::move(callback);
const char* https_status_code_class_histogram_name =
install_source == WebappInstallSource::SYNC
? "WebApp.Icon.HttpStatusCodeClassOnSync"
: "WebApp.Icon.HttpStatusCodeClassOnCreate";
// TODO(loyso): Refactor WebAppIconDownloader: crbug.com/907296. // TODO(loyso): Refactor WebAppIconDownloader: crbug.com/907296.
icon_downloader_ = std::make_unique<WebAppIconDownloader>( icon_downloader_ = std::make_unique<WebAppIconDownloader>(
web_contents, icon_urls, https_status_code_class_histogram_name, web_contents, icon_urls, histogram,
base::BindOnce(&WebAppDataRetriever::OnIconsDownloaded, base::BindOnce(&WebAppDataRetriever::OnIconsDownloaded,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
......
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/web_applications/components/web_app_icon_downloader.h"
#include "chrome/browser/web_applications/components/web_app_install_utils.h" #include "chrome/browser/web_applications/components/web_app_install_utils.h"
#include "chrome/common/chrome_render_frame.mojom.h" #include "chrome/common/chrome_render_frame.mojom.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/associated_remote.h"
class GURL; class GURL;
enum class WebappInstallSource;
struct InstallableData; struct InstallableData;
struct WebApplicationInfo; struct WebApplicationInfo;
...@@ -32,8 +32,6 @@ class WebContents; ...@@ -32,8 +32,6 @@ class WebContents;
namespace web_app { namespace web_app {
class WebAppIconDownloader;
// Class used by WebAppInstallTask to retrieve the necessary information to // Class used by WebAppInstallTask to retrieve the necessary information to
// install an app. Should only be called from the UI thread. // install an app. Should only be called from the UI thread.
class WebAppDataRetriever : content::WebContentsObserver { class WebAppDataRetriever : content::WebContentsObserver {
...@@ -68,7 +66,7 @@ class WebAppDataRetriever : content::WebContentsObserver { ...@@ -68,7 +66,7 @@ class WebAppDataRetriever : content::WebContentsObserver {
virtual void GetIcons(content::WebContents* web_contents, virtual void GetIcons(content::WebContents* web_contents,
const std::vector<GURL>& icon_urls, const std::vector<GURL>& icon_urls,
bool skip_page_favicons, bool skip_page_favicons,
WebappInstallSource install_source, WebAppIconDownloader::Histogram histogram,
GetIconsCallback callback); GetIconsCallback callback);
// WebContentsObserver: // WebContentsObserver:
......
...@@ -323,12 +323,11 @@ TEST_F(WebAppDataRetrieverTest, GetIcons_WebContentsDestroyed) { ...@@ -323,12 +323,11 @@ TEST_F(WebAppDataRetrieverTest, GetIcons_WebContentsDestroyed) {
const std::vector<GURL> icon_urls; const std::vector<GURL> icon_urls;
bool skip_page_favicons = true; bool skip_page_favicons = true;
auto install_source = WebappInstallSource::MENU_BROWSER_TAB;
base::RunLoop run_loop; base::RunLoop run_loop;
WebAppDataRetriever retriever; WebAppDataRetriever retriever;
retriever.GetIcons(web_contents(), icon_urls, skip_page_favicons, retriever.GetIcons(web_contents(), icon_urls, skip_page_favicons,
install_source, WebAppIconDownloader::Histogram::kForCreate,
base::BindLambdaForTesting([&](IconsMap icons_map) { base::BindLambdaForTesting([&](IconsMap icons_map) {
EXPECT_TRUE(icons_map.empty()); EXPECT_TRUE(icons_map.empty());
run_loop.Quit(); run_loop.Quit();
......
...@@ -20,14 +20,13 @@ namespace web_app { ...@@ -20,14 +20,13 @@ namespace web_app {
WebAppIconDownloader::WebAppIconDownloader( WebAppIconDownloader::WebAppIconDownloader(
content::WebContents* web_contents, content::WebContents* web_contents,
const std::vector<GURL>& extra_favicon_urls, const std::vector<GURL>& extra_favicon_urls,
const char* https_status_code_class_histogram_name, Histogram histogram,
WebAppIconDownloaderCallback callback) WebAppIconDownloaderCallback callback)
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
need_favicon_urls_(true), need_favicon_urls_(true),
extra_favicon_urls_(extra_favicon_urls), extra_favicon_urls_(extra_favicon_urls),
callback_(std::move(callback)), callback_(std::move(callback)),
https_status_code_class_histogram_name_( histogram_(histogram) {}
https_status_code_class_histogram_name) {}
WebAppIconDownloader::~WebAppIconDownloader() {} WebAppIconDownloader::~WebAppIconDownloader() {}
...@@ -113,12 +112,19 @@ void WebAppIconDownloader::DidDownloadFavicon( ...@@ -113,12 +112,19 @@ void WebAppIconDownloader::DidDownloadFavicon(
if (in_progress_requests_.erase(id) == 0) if (in_progress_requests_.erase(id) == 0)
return; return;
if (!https_status_code_class_histogram_name_.empty() && if (http_status_code != 0) {
http_status_code != 0) { const char* histogram_name = nullptr;
switch (histogram_) {
case Histogram::kForCreate:
histogram_name = "WebApp.Icon.HttpStatusCodeClassOnCreate";
break;
case Histogram::kForSync:
histogram_name = "WebApp.Icon.HttpStatusCodeClassOnSync";
break;
}
DCHECK_LE(100, http_status_code); DCHECK_LE(100, http_status_code);
DCHECK_GT(600, http_status_code); DCHECK_GT(600, http_status_code);
base::UmaHistogramExactLinear(https_status_code_class_histogram_name_, base::UmaHistogramExactLinear(histogram_name, http_status_code / 100, 5);
http_status_code / 100, 5);
} }
icons_map_[image_url] = bitmaps; icons_map_[image_url] = bitmaps;
......
...@@ -32,6 +32,11 @@ namespace web_app { ...@@ -32,6 +32,11 @@ namespace web_app {
// icons) for a tab. // icons) for a tab.
class WebAppIconDownloader : public content::WebContentsObserver { class WebAppIconDownloader : public content::WebContentsObserver {
public: public:
enum class Histogram {
kForCreate,
kForSync,
};
using WebAppIconDownloaderCallback = using WebAppIconDownloaderCallback =
base::OnceCallback<void(bool success, IconsMap icons_map)>; base::OnceCallback<void(bool success, IconsMap icons_map)>;
...@@ -41,7 +46,7 @@ class WebAppIconDownloader : public content::WebContentsObserver { ...@@ -41,7 +46,7 @@ class WebAppIconDownloader : public content::WebContentsObserver {
// to use for logging http status code class results from fetch attempts. // to use for logging http status code class results from fetch attempts.
WebAppIconDownloader(content::WebContents* web_contents, WebAppIconDownloader(content::WebContents* web_contents,
const std::vector<GURL>& extra_favicon_urls, const std::vector<GURL>& extra_favicon_urls,
const char* https_status_code_class_histogram_name, Histogram histogram,
WebAppIconDownloaderCallback callback); WebAppIconDownloaderCallback callback);
~WebAppIconDownloader() override; ~WebAppIconDownloader() override;
...@@ -102,8 +107,8 @@ class WebAppIconDownloader : public content::WebContentsObserver { ...@@ -102,8 +107,8 @@ class WebAppIconDownloader : public content::WebContentsObserver {
// Callback to run on favicon download completion. // Callback to run on favicon download completion.
WebAppIconDownloaderCallback callback_; WebAppIconDownloaderCallback callback_;
// The histogram name to log individual fetch results under. // Which histogram to log individual fetch results under.
const std::string https_status_code_class_histogram_name_; Histogram histogram_;
base::WeakPtrFactory<WebAppIconDownloader> weak_ptr_factory_{this}; base::WeakPtrFactory<WebAppIconDownloader> weak_ptr_factory_{this};
......
...@@ -48,7 +48,7 @@ class WebAppIconDownloaderTest : public ChromeRenderViewHostTestHarness { ...@@ -48,7 +48,7 @@ class WebAppIconDownloaderTest : public ChromeRenderViewHostTestHarness {
DISALLOW_COPY_AND_ASSIGN(WebAppIconDownloaderTest); DISALLOW_COPY_AND_ASSIGN(WebAppIconDownloaderTest);
}; };
const char* kTestHistogramName = "WebAppIconDownloader.TestHistogram"; const char* kHistogramForCreateName = "WebApp.Icon.HttpStatusCodeClassOnCreate";
} // namespace } // namespace
...@@ -59,7 +59,7 @@ class TestWebAppIconDownloader : public WebAppIconDownloader { ...@@ -59,7 +59,7 @@ class TestWebAppIconDownloader : public WebAppIconDownloader {
: WebAppIconDownloader( : WebAppIconDownloader(
web_contents, web_contents,
extra_favicon_urls, extra_favicon_urls,
kTestHistogramName, Histogram::kForCreate,
base::BindOnce(&TestWebAppIconDownloader::DownloadsComplete, base::BindOnce(&TestWebAppIconDownloader::DownloadsComplete,
base::Unretained(this))), base::Unretained(this))),
id_counter_(0) {} id_counter_(0) {}
...@@ -130,7 +130,7 @@ TEST_F(WebAppIconDownloaderTest, SimpleDownload) { ...@@ -130,7 +130,7 @@ TEST_F(WebAppIconDownloaderTest, SimpleDownload) {
EXPECT_EQ(1u, downloader.favicon_map().size()); EXPECT_EQ(1u, downloader.favicon_map().size());
EXPECT_EQ(1u, downloader.favicon_map()[favicon_url].size()); EXPECT_EQ(1u, downloader.favicon_map()[favicon_url].size());
EXPECT_TRUE(downloader.downloads_succeeded()); EXPECT_TRUE(downloader.downloads_succeeded());
histogram_tester_.ExpectUniqueSample(kTestHistogramName, 2, 1); histogram_tester_.ExpectUniqueSample(kHistogramForCreateName, 2, 1);
} }
TEST_F(WebAppIconDownloaderTest, NoHTTPStatusCode) { TEST_F(WebAppIconDownloaderTest, NoHTTPStatusCode) {
...@@ -156,7 +156,7 @@ TEST_F(WebAppIconDownloaderTest, NoHTTPStatusCode) { ...@@ -156,7 +156,7 @@ TEST_F(WebAppIconDownloaderTest, NoHTTPStatusCode) {
EXPECT_EQ(1u, downloader.favicon_map()[favicon_url].size()); EXPECT_EQ(1u, downloader.favicon_map()[favicon_url].size());
EXPECT_TRUE(downloader.downloads_succeeded()) EXPECT_TRUE(downloader.downloads_succeeded())
<< "Should not consider data: URL or HTTP status code of 0 a failure"; << "Should not consider data: URL or HTTP status code of 0 a failure";
histogram_tester_.ExpectTotalCount(kTestHistogramName, 0); histogram_tester_.ExpectTotalCount(kHistogramForCreateName, 0);
} }
TEST_F(WebAppIconDownloaderTest, DownloadWithUrlsFromWebContentsNotification) { TEST_F(WebAppIconDownloaderTest, DownloadWithUrlsFromWebContentsNotification) {
...@@ -183,7 +183,7 @@ TEST_F(WebAppIconDownloaderTest, DownloadWithUrlsFromWebContentsNotification) { ...@@ -183,7 +183,7 @@ TEST_F(WebAppIconDownloaderTest, DownloadWithUrlsFromWebContentsNotification) {
EXPECT_EQ(1u, downloader.favicon_map().size()); EXPECT_EQ(1u, downloader.favicon_map().size());
EXPECT_EQ(1u, downloader.favicon_map()[favicon_url].size()); EXPECT_EQ(1u, downloader.favicon_map()[favicon_url].size());
EXPECT_TRUE(downloader.downloads_succeeded()); EXPECT_TRUE(downloader.downloads_succeeded());
histogram_tester_.ExpectUniqueSample(kTestHistogramName, 2, 1); histogram_tester_.ExpectUniqueSample(kHistogramForCreateName, 2, 1);
} }
TEST_F(WebAppIconDownloaderTest, DownloadMultipleUrls) { TEST_F(WebAppIconDownloaderTest, DownloadMultipleUrls) {
...@@ -233,7 +233,7 @@ TEST_F(WebAppIconDownloaderTest, DownloadMultipleUrls) { ...@@ -233,7 +233,7 @@ TEST_F(WebAppIconDownloaderTest, DownloadMultipleUrls) {
EXPECT_EQ(1u, downloader.favicon_map()[favicon_url_1].size()); EXPECT_EQ(1u, downloader.favicon_map()[favicon_url_1].size());
EXPECT_EQ(2u, downloader.favicon_map()[favicon_url_2].size()); EXPECT_EQ(2u, downloader.favicon_map()[favicon_url_2].size());
EXPECT_TRUE(downloader.downloads_succeeded()); EXPECT_TRUE(downloader.downloads_succeeded());
histogram_tester_.ExpectUniqueSample(kTestHistogramName, 2, 3); histogram_tester_.ExpectUniqueSample(kHistogramForCreateName, 2, 3);
} }
TEST_F(WebAppIconDownloaderTest, SkipPageFavicons) { TEST_F(WebAppIconDownloaderTest, SkipPageFavicons) {
...@@ -269,7 +269,7 @@ TEST_F(WebAppIconDownloaderTest, SkipPageFavicons) { ...@@ -269,7 +269,7 @@ TEST_F(WebAppIconDownloaderTest, SkipPageFavicons) {
EXPECT_EQ(1u, downloader.favicon_map()[favicon_url_1].size()); EXPECT_EQ(1u, downloader.favicon_map()[favicon_url_1].size());
EXPECT_EQ(0u, downloader.favicon_map()[favicon_url_2].size()); EXPECT_EQ(0u, downloader.favicon_map()[favicon_url_2].size());
EXPECT_TRUE(downloader.downloads_succeeded()); EXPECT_TRUE(downloader.downloads_succeeded());
histogram_tester_.ExpectUniqueSample(kTestHistogramName, 2, 1); histogram_tester_.ExpectUniqueSample(kHistogramForCreateName, 2, 1);
} }
TEST_F(WebAppIconDownloaderTest, PageNavigates) { TEST_F(WebAppIconDownloaderTest, PageNavigates) {
...@@ -320,7 +320,7 @@ TEST_F(WebAppIconDownloaderTest, PageNavigatesSameDocument) { ...@@ -320,7 +320,7 @@ TEST_F(WebAppIconDownloaderTest, PageNavigatesSameDocument) {
EXPECT_EQ(1u, downloader.favicon_map().size()); EXPECT_EQ(1u, downloader.favicon_map().size());
EXPECT_EQ(1u, downloader.favicon_map()[favicon_url].size()); EXPECT_EQ(1u, downloader.favicon_map()[favicon_url].size());
EXPECT_TRUE(downloader.downloads_succeeded()); EXPECT_TRUE(downloader.downloads_succeeded());
histogram_tester_.ExpectUniqueSample(kTestHistogramName, 2, 1); histogram_tester_.ExpectUniqueSample(kHistogramForCreateName, 2, 1);
} }
} // namespace web_app } // namespace web_app
...@@ -45,7 +45,7 @@ void TestDataRetriever::CheckInstallabilityAndRetrieveManifest( ...@@ -45,7 +45,7 @@ void TestDataRetriever::CheckInstallabilityAndRetrieveManifest(
void TestDataRetriever::GetIcons(content::WebContents* web_contents, void TestDataRetriever::GetIcons(content::WebContents* web_contents,
const std::vector<GURL>& icon_urls, const std::vector<GURL>& icon_urls,
bool skip_page_favicons, bool skip_page_favicons,
WebappInstallSource install_source, WebAppIconDownloader::Histogram histogram,
GetIconsCallback callback) { GetIconsCallback callback) {
if (get_icons_delegate_) { if (get_icons_delegate_) {
icons_map_ = icons_map_ =
......
...@@ -35,7 +35,7 @@ class TestDataRetriever : public WebAppDataRetriever { ...@@ -35,7 +35,7 @@ class TestDataRetriever : public WebAppDataRetriever {
void GetIcons(content::WebContents* web_contents, void GetIcons(content::WebContents* web_contents,
const std::vector<GURL>& icon_urls, const std::vector<GURL>& icon_urls,
bool skip_page_favicons, bool skip_page_favicons,
WebappInstallSource install_source, WebAppIconDownloader::Histogram histogram,
GetIconsCallback callback) override; GetIconsCallback callback) override;
// Set info to respond on |GetWebApplicationInfo|. // Set info to respond on |GetWebApplicationInfo|.
......
...@@ -171,7 +171,10 @@ void WebAppInstallTask::InstallWebAppFromInfoRetrieveIcons( ...@@ -171,7 +171,10 @@ void WebAppInstallTask::InstallWebAppFromInfoRetrieveIcons(
// Skip downloading the page favicons as everything in is the URL list. // Skip downloading the page favicons as everything in is the URL list.
data_retriever_->GetIcons( data_retriever_->GetIcons(
web_contents, icon_urls, /*skip_page_fav_icons*/ true, install_source_, web_contents, icon_urls, /*skip_page_fav_icons*/ true,
install_source_ == WebappInstallSource::SYNC
? WebAppIconDownloader::Histogram::kForSync
: WebAppIconDownloader::Histogram::kForCreate,
base::BindOnce(&WebAppInstallTask::OnIconsRetrieved, base::BindOnce(&WebAppInstallTask::OnIconsRetrieved,
base::Unretained(this), std::move(web_application_info), base::Unretained(this), std::move(web_application_info),
is_locally_installed)); is_locally_installed));
...@@ -372,7 +375,10 @@ void WebAppInstallTask::OnDidCheckForIntentToPlayStore( ...@@ -372,7 +375,10 @@ void WebAppInstallTask::OnDidCheckForIntentToPlayStore(
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
data_retriever_->GetIcons( data_retriever_->GetIcons(
web_contents(), icon_urls, skip_page_favicons, install_source_, web_contents(), icon_urls, skip_page_favicons,
install_source_ == WebappInstallSource::SYNC
? WebAppIconDownloader::Histogram::kForSync
: WebAppIconDownloader::Histogram::kForCreate,
base::BindOnce(&WebAppInstallTask::OnIconsRetrievedShowDialog, base::BindOnce(&WebAppInstallTask::OnIconsRetrievedShowDialog,
base::Unretained(this), std::move(web_app_info), base::Unretained(this), std::move(web_app_info),
for_installable_site)); for_installable_site));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment