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" |
16 #include "chrome/common/render_messages.h" | |
14 #include "components/content_settings/core/browser/host_content_settings_map.h" | 17 #include "components/content_settings/core/browser/host_content_settings_map.h" |
15 #include "components/content_settings/core/common/content_settings_pattern.h" | 18 #include "components/content_settings/core/common/content_settings_pattern.h" |
19 #include "components/rappor/rappor_utils.h" | |
20 #include "content/public/browser/render_frame_host.h" | |
16 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
17 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
18 #include "url/gurl.h" | 23 #include "url/gurl.h" |
19 | 24 |
20 namespace { | 25 namespace { |
21 | 26 |
22 // Max number of apps (including ServiceWorker based web apps) that a particular | 27 // Max number of apps (including ServiceWorker based web apps) that a particular |
23 // site may show a banner for. | 28 // site may show a banner for. |
24 const size_t kMaxAppsPerSite = 3; | 29 const size_t kMaxAppsPerSite = 3; |
25 | 30 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 if (!pattern.IsValid()) | 93 if (!pattern.IsValid()) |
89 continue; | 94 continue; |
90 | 95 |
91 settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), | 96 settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), |
92 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | 97 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), |
93 nullptr); | 98 nullptr); |
94 settings->FlushLossyWebsiteSettings(); | 99 settings->FlushLossyWebsiteSettings(); |
95 } | 100 } |
96 } | 101 } |
97 | 102 |
103 void AppBannerSettingsHelper::RecordBannerWebInstallEvent( | |
104 content::WebContents* web_contents, | |
105 const std::string& package_name_or_start_url, | |
106 const std::string& rappor_metric, | |
107 int event_request_id_) { | |
108 banners::TrackInstallEvent(banners::INSTALL_EVENT_WEB_APP_INSTALLED); | |
109 | |
110 web_contents->GetMainFrame()->Send( | |
benwells
2015/06/02 05:53:36
The role of this helper is getting a bit haphazard
dominickn (DO NOT USE)
2015/06/02 06:51:32
In progress.
| |
111 new ChromeViewMsg_AppBannerAccepted( | |
112 web_contents->GetMainFrame()->GetRoutingID(), | |
113 event_request_id_, "web")); | |
114 | |
115 AppBannerSettingsHelper::RecordBannerEvent( | |
116 web_contents, web_contents->GetURL(), | |
117 package_name_or_start_url, | |
118 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | |
119 banners::AppBannerDataFetcher::GetCurrentTime()); | |
120 | |
121 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | |
122 rappor_metric, | |
123 web_contents->GetURL()); | |
124 } | |
125 | |
126 void AppBannerSettingsHelper::RecordBannerDismissEvent( | |
127 content::WebContents* web_contents, | |
128 const std::string& package_name_or_start_url, | |
129 const std::string& rappor_metric, | |
130 int event_request_id_) { | |
131 banners::TrackDismissEvent(banners::DISMISS_EVENT_CLOSE_BUTTON); | |
132 | |
133 web_contents->GetMainFrame()->Send( | |
134 new ChromeViewMsg_AppBannerDismissed( | |
135 web_contents->GetMainFrame()->GetRoutingID(), | |
136 event_request_id_)); | |
137 | |
138 AppBannerSettingsHelper::RecordBannerEvent( | |
139 web_contents, web_contents->GetURL(), | |
140 package_name_or_start_url, | |
141 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, | |
142 banners::AppBannerDataFetcher::GetCurrentTime()); | |
143 | |
144 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | |
145 rappor_metric, | |
146 web_contents->GetURL()); | |
147 } | |
148 | |
98 void AppBannerSettingsHelper::RecordBannerEvent( | 149 void AppBannerSettingsHelper::RecordBannerEvent( |
99 content::WebContents* web_contents, | 150 content::WebContents* web_contents, |
100 const GURL& origin_url, | 151 const GURL& origin_url, |
101 const std::string& package_name_or_start_url, | 152 const std::string& package_name_or_start_url, |
102 AppBannerEvent event, | 153 AppBannerEvent event, |
103 base::Time time) { | 154 base::Time time) { |
104 Profile* profile = | 155 Profile* profile = |
105 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 156 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
106 if (profile->IsOffTheRecord() || package_name_or_start_url.empty()) | 157 if (profile->IsOffTheRecord() || package_name_or_start_url.empty()) |
107 return; | 158 return; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 if (!app_dict) | 345 if (!app_dict) |
295 return base::Time(); | 346 return base::Time(); |
296 | 347 |
297 std::string event_key(kBannerEventKeys[event]); | 348 std::string event_key(kBannerEventKeys[event]); |
298 double internal_time; | 349 double internal_time; |
299 if (!app_dict->GetDouble(event_key, &internal_time)) | 350 if (!app_dict->GetDouble(event_key, &internal_time)) |
300 return base::Time(); | 351 return base::Time(); |
301 | 352 |
302 return base::Time::FromInternalValue(internal_time); | 353 return base::Time::FromInternalValue(internal_time); |
303 } | 354 } |
OLD | NEW |