| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/banners/app_banner_settings_helper.h" | 5 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "chrome/browser/banners/app_banner_data_fetcher.h" |
| 11 #include "chrome/browser/banners/app_banner_metrics.h" | 12 #include "chrome/browser/banners/app_banner_metrics.h" |
| 13 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 14 #include "components/content_settings/core/browser/host_content_settings_map.h" | 16 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 15 #include "components/content_settings/core/common/content_settings_pattern.h" | 17 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 18 #include "components/rappor/rappor_utils.h" |
| 16 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 17 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
| 18 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 19 | 22 |
| 20 namespace { | 23 namespace { |
| 21 | 24 |
| 22 // Max number of apps (including ServiceWorker based web apps) that a particular | 25 // Max number of apps (including ServiceWorker based web apps) that a particular |
| 23 // site may show a banner for. | 26 // site may show a banner for. |
| 24 const size_t kMaxAppsPerSite = 3; | 27 const size_t kMaxAppsPerSite = 3; |
| 25 | 28 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (!pattern.IsValid()) | 91 if (!pattern.IsValid()) |
| 89 continue; | 92 continue; |
| 90 | 93 |
| 91 settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), | 94 settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), |
| 92 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | 95 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), |
| 93 nullptr); | 96 nullptr); |
| 94 settings->FlushLossyWebsiteSettings(); | 97 settings->FlushLossyWebsiteSettings(); |
| 95 } | 98 } |
| 96 } | 99 } |
| 97 | 100 |
| 101 void AppBannerSettingsHelper::RecordBannerInstallEvent( |
| 102 content::WebContents* web_contents, |
| 103 const std::string& package_name_or_start_url, |
| 104 AppBannerRapporMetric rappor_metric) { |
| 105 banners::TrackInstallEvent(banners::INSTALL_EVENT_WEB_APP_INSTALLED); |
| 106 |
| 107 AppBannerSettingsHelper::RecordBannerEvent( |
| 108 web_contents, web_contents->GetURL(), |
| 109 package_name_or_start_url, |
| 110 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
| 111 banners::AppBannerDataFetcher::GetCurrentTime()); |
| 112 |
| 113 rappor::SampleDomainAndRegistryFromGURL( |
| 114 g_browser_process->rappor_service(), |
| 115 (rappor_metric == WEB ? "AppBanner.WebApp.Installed" |
| 116 : "AppBanner.NativeApp.Installed"), |
| 117 web_contents->GetURL()); |
| 118 } |
| 119 |
| 120 void AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 121 content::WebContents* web_contents, |
| 122 const std::string& package_name_or_start_url, |
| 123 AppBannerRapporMetric rappor_metric) { |
| 124 banners::TrackDismissEvent(banners::DISMISS_EVENT_CLOSE_BUTTON); |
| 125 |
| 126 AppBannerSettingsHelper::RecordBannerEvent( |
| 127 web_contents, web_contents->GetURL(), |
| 128 package_name_or_start_url, |
| 129 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, |
| 130 banners::AppBannerDataFetcher::GetCurrentTime()); |
| 131 |
| 132 rappor::SampleDomainAndRegistryFromGURL( |
| 133 g_browser_process->rappor_service(), |
| 134 (rappor_metric == WEB ? "AppBanner.WebApp.Dismissed" |
| 135 : "AppBanner.NativeApp.Dismissed"), |
| 136 web_contents->GetURL()); |
| 137 } |
| 138 |
| 98 void AppBannerSettingsHelper::RecordBannerEvent( | 139 void AppBannerSettingsHelper::RecordBannerEvent( |
| 99 content::WebContents* web_contents, | 140 content::WebContents* web_contents, |
| 100 const GURL& origin_url, | 141 const GURL& origin_url, |
| 101 const std::string& package_name_or_start_url, | 142 const std::string& package_name_or_start_url, |
| 102 AppBannerEvent event, | 143 AppBannerEvent event, |
| 103 base::Time time) { | 144 base::Time time) { |
| 104 Profile* profile = | 145 Profile* profile = |
| 105 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 146 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 106 if (profile->IsOffTheRecord() || package_name_or_start_url.empty()) | 147 if (profile->IsOffTheRecord() || package_name_or_start_url.empty()) |
| 107 return; | 148 return; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 if (!app_dict) | 335 if (!app_dict) |
| 295 return base::Time(); | 336 return base::Time(); |
| 296 | 337 |
| 297 std::string event_key(kBannerEventKeys[event]); | 338 std::string event_key(kBannerEventKeys[event]); |
| 298 double internal_time; | 339 double internal_time; |
| 299 if (!app_dict->GetDouble(event_key, &internal_time)) | 340 if (!app_dict->GetDouble(event_key, &internal_time)) |
| 300 return base::Time(); | 341 return base::Time(); |
| 301 | 342 |
| 302 return base::Time::FromInternalValue(internal_time); | 343 return base::Time::FromInternalValue(internal_time); |
| 303 } | 344 } |
| OLD | NEW |