| 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 "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "chrome/browser/banners/app_banner_data_fetcher.h" | 14 #include "chrome/browser/banners/app_banner_data_fetcher.h" |
| 15 #include "chrome/browser/banners/app_banner_metrics.h" | 15 #include "chrome/browser/banners/app_banner_metrics.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 19 #include "components/content_settings/core/browser/host_content_settings_map.h" | 20 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 20 #include "components/content_settings/core/common/content_settings_pattern.h" | 21 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 21 #include "components/rappor/rappor_utils.h" | 22 #include "components/rappor/rappor_utils.h" |
| 22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 23 #include "net/base/escape.h" | 24 #include "net/base/escape.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 int minimum_minutes = 0; | 156 int minimum_minutes = 0; |
| 156 if (base::StringToInt(minutes_between_visits, &minimum_minutes)) | 157 if (base::StringToInt(minutes_between_visits, &minimum_minutes)) |
| 157 AppBannerSettingsHelper::SetMinimumMinutesBetweenVisits(minimum_minutes); | 158 AppBannerSettingsHelper::SetMinimumMinutesBetweenVisits(minimum_minutes); |
| 158 } | 159 } |
| 159 | 160 |
| 160 } // namespace | 161 } // namespace |
| 161 | 162 |
| 162 void AppBannerSettingsHelper::ClearHistoryForURLs( | 163 void AppBannerSettingsHelper::ClearHistoryForURLs( |
| 163 Profile* profile, | 164 Profile* profile, |
| 164 const std::set<GURL>& origin_urls) { | 165 const std::set<GURL>& origin_urls) { |
| 165 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | 166 HostContentSettingsMap* settings = |
| 167 HostContentSettingsMapFactory::GetForProfile(profile); |
| 166 for (const GURL& origin_url : origin_urls) { | 168 for (const GURL& origin_url : origin_urls) { |
| 167 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url)); | 169 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url)); |
| 168 if (!pattern.IsValid()) | 170 if (!pattern.IsValid()) |
| 169 continue; | 171 continue; |
| 170 | 172 |
| 171 settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), | 173 settings->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), |
| 172 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | 174 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), |
| 173 nullptr); | 175 nullptr); |
| 174 settings->FlushLossyWebsiteSettings(); | 176 settings->FlushLossyWebsiteSettings(); |
| 175 } | 177 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 225 |
| 224 Profile* profile = | 226 Profile* profile = |
| 225 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 227 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 226 if (profile->IsOffTheRecord() || package_name_or_start_url.empty()) | 228 if (profile->IsOffTheRecord() || package_name_or_start_url.empty()) |
| 227 return; | 229 return; |
| 228 | 230 |
| 229 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url)); | 231 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url)); |
| 230 if (!pattern.IsValid()) | 232 if (!pattern.IsValid()) |
| 231 return; | 233 return; |
| 232 | 234 |
| 233 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | 235 HostContentSettingsMap* settings = |
| 236 HostContentSettingsMapFactory::GetForProfile(profile); |
| 234 scoped_ptr<base::DictionaryValue> origin_dict = | 237 scoped_ptr<base::DictionaryValue> origin_dict = |
| 235 GetOriginDict(settings, origin_url); | 238 GetOriginDict(settings, origin_url); |
| 236 if (!origin_dict) | 239 if (!origin_dict) |
| 237 return; | 240 return; |
| 238 | 241 |
| 239 base::DictionaryValue* app_dict = | 242 base::DictionaryValue* app_dict = |
| 240 GetAppDict(origin_dict.get(), package_name_or_start_url); | 243 GetAppDict(origin_dict.get(), package_name_or_start_url); |
| 241 if (!app_dict) | 244 if (!app_dict) |
| 242 return; | 245 return; |
| 243 | 246 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 267 ui::PageTransition transition_type) { | 270 ui::PageTransition transition_type) { |
| 268 Profile* profile = | 271 Profile* profile = |
| 269 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 272 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 270 if (profile->IsOffTheRecord() || package_name_or_start_url.empty()) | 273 if (profile->IsOffTheRecord() || package_name_or_start_url.empty()) |
| 271 return; | 274 return; |
| 272 | 275 |
| 273 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url)); | 276 ContentSettingsPattern pattern(ContentSettingsPattern::FromURL(origin_url)); |
| 274 if (!pattern.IsValid()) | 277 if (!pattern.IsValid()) |
| 275 return; | 278 return; |
| 276 | 279 |
| 277 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | 280 HostContentSettingsMap* settings = |
| 281 HostContentSettingsMapFactory::GetForProfile(profile); |
| 278 scoped_ptr<base::DictionaryValue> origin_dict = | 282 scoped_ptr<base::DictionaryValue> origin_dict = |
| 279 GetOriginDict(settings, origin_url); | 283 GetOriginDict(settings, origin_url); |
| 280 if (!origin_dict) | 284 if (!origin_dict) |
| 281 return; | 285 return; |
| 282 | 286 |
| 283 base::DictionaryValue* app_dict = | 287 base::DictionaryValue* app_dict = |
| 284 GetAppDict(origin_dict.get(), package_name_or_start_url); | 288 GetAppDict(origin_dict.get(), package_name_or_start_url); |
| 285 if (!app_dict) | 289 if (!app_dict) |
| 286 return; | 290 return; |
| 287 | 291 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 AppBannerSettingsHelper::GetCouldShowBannerEvents( | 413 AppBannerSettingsHelper::GetCouldShowBannerEvents( |
| 410 content::WebContents* web_contents, | 414 content::WebContents* web_contents, |
| 411 const GURL& origin_url, | 415 const GURL& origin_url, |
| 412 const std::string& package_name_or_start_url) { | 416 const std::string& package_name_or_start_url) { |
| 413 std::vector<BannerEvent> result; | 417 std::vector<BannerEvent> result; |
| 414 if (package_name_or_start_url.empty()) | 418 if (package_name_or_start_url.empty()) |
| 415 return result; | 419 return result; |
| 416 | 420 |
| 417 Profile* profile = | 421 Profile* profile = |
| 418 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 422 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 419 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | 423 HostContentSettingsMap* settings = |
| 424 HostContentSettingsMapFactory::GetForProfile(profile); |
| 420 scoped_ptr<base::DictionaryValue> origin_dict = | 425 scoped_ptr<base::DictionaryValue> origin_dict = |
| 421 GetOriginDict(settings, origin_url); | 426 GetOriginDict(settings, origin_url); |
| 422 | 427 |
| 423 if (!origin_dict) | 428 if (!origin_dict) |
| 424 return result; | 429 return result; |
| 425 | 430 |
| 426 base::DictionaryValue* app_dict = | 431 base::DictionaryValue* app_dict = |
| 427 GetAppDict(origin_dict.get(), package_name_or_start_url); | 432 GetAppDict(origin_dict.get(), package_name_or_start_url); |
| 428 if (!app_dict) | 433 if (!app_dict) |
| 429 return result; | 434 return result; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 457 const std::string& package_name_or_start_url, | 462 const std::string& package_name_or_start_url, |
| 458 AppBannerEvent event) { | 463 AppBannerEvent event) { |
| 459 DCHECK(event != APP_BANNER_EVENT_COULD_SHOW); | 464 DCHECK(event != APP_BANNER_EVENT_COULD_SHOW); |
| 460 DCHECK(event < APP_BANNER_EVENT_NUM_EVENTS); | 465 DCHECK(event < APP_BANNER_EVENT_NUM_EVENTS); |
| 461 | 466 |
| 462 if (package_name_or_start_url.empty()) | 467 if (package_name_or_start_url.empty()) |
| 463 return base::Time(); | 468 return base::Time(); |
| 464 | 469 |
| 465 Profile* profile = | 470 Profile* profile = |
| 466 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 471 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 467 HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); | 472 HostContentSettingsMap* settings = |
| 473 HostContentSettingsMapFactory::GetForProfile(profile); |
| 468 scoped_ptr<base::DictionaryValue> origin_dict = | 474 scoped_ptr<base::DictionaryValue> origin_dict = |
| 469 GetOriginDict(settings, origin_url); | 475 GetOriginDict(settings, origin_url); |
| 470 | 476 |
| 471 if (!origin_dict) | 477 if (!origin_dict) |
| 472 return base::Time(); | 478 return base::Time(); |
| 473 | 479 |
| 474 base::DictionaryValue* app_dict = | 480 base::DictionaryValue* app_dict = |
| 475 GetAppDict(origin_dict.get(), package_name_or_start_url); | 481 GetAppDict(origin_dict.get(), package_name_or_start_url); |
| 476 if (!app_dict) | 482 if (!app_dict) |
| 477 return base::Time(); | 483 return base::Time(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 529 |
| 524 // Use truncating integer division here. | 530 // Use truncating integer division here. |
| 525 return time.LocalMidnight() + | 531 return time.LocalMidnight() + |
| 526 base::TimeDelta::FromMinutes((total_minutes / minutes) * minutes); | 532 base::TimeDelta::FromMinutes((total_minutes / minutes) * minutes); |
| 527 } | 533 } |
| 528 | 534 |
| 529 void AppBannerSettingsHelper::UpdateFromFieldTrial() { | 535 void AppBannerSettingsHelper::UpdateFromFieldTrial() { |
| 530 UpdateEngagementWeights(); | 536 UpdateEngagementWeights(); |
| 531 UpdateMinutesBetweenVisits(); | 537 UpdateMinutesBetweenVisits(); |
| 532 } | 538 } |
| OLD | NEW |