| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/engagement/site_engagement_service.h" | 5 #include "chrome/browser/engagement/site_engagement_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 31 #include "components/content_settings/core/browser/host_content_settings_map.h" | 31 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 32 #include "components/content_settings/core/common/content_settings_pattern.h" | 32 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 33 #include "components/history/core/browser/history_service.h" | 33 #include "components/history/core/browser/history_service.h" |
| 34 #include "components/prefs/pref_service.h" | 34 #include "components/prefs/pref_service.h" |
| 35 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 37 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| 38 | 38 |
| 39 #if defined(OS_ANDROID) |
| 40 #include "chrome/browser/engagement/site_engagement_service_android.h" |
| 41 #endif |
| 42 |
| 39 namespace { | 43 namespace { |
| 40 | 44 |
| 41 const int FOUR_WEEKS_IN_DAYS = 28; | 45 const int FOUR_WEEKS_IN_DAYS = 28; |
| 42 | 46 |
| 43 // Global bool to ensure we only update the parameters from variations once. | 47 // Global bool to ensure we only update the parameters from variations once. |
| 44 bool g_updated_from_variations = false; | 48 bool g_updated_from_variations = false; |
| 45 | 49 |
| 46 // Length of time between metrics logging. | 50 // Length of time between metrics logging. |
| 47 const int kMetricsIntervalInMinutes = 60; | 51 const int kMetricsIntervalInMinutes = 60; |
| 48 | 52 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 double SiteEngagementService::GetTotalEngagementPoints() const { | 235 double SiteEngagementService::GetTotalEngagementPoints() const { |
| 232 std::map<GURL, double> score_map = GetScoreMap(); | 236 std::map<GURL, double> score_map = GetScoreMap(); |
| 233 | 237 |
| 234 double total_score = 0; | 238 double total_score = 0; |
| 235 for (const auto& value : score_map) | 239 for (const auto& value : score_map) |
| 236 total_score += value.second; | 240 total_score += value.second; |
| 237 | 241 |
| 238 return total_score; | 242 return total_score; |
| 239 } | 243 } |
| 240 | 244 |
| 245 #if defined(OS_ANDROID) |
| 246 SiteEngagementServiceAndroid* SiteEngagementService::GetAndroidService() const { |
| 247 return android_service_.get(); |
| 248 } |
| 249 |
| 250 void SiteEngagementService::SetAndroidService( |
| 251 std::unique_ptr<SiteEngagementServiceAndroid> android_service) { |
| 252 android_service_ = std::move(android_service); |
| 253 } |
| 254 #endif |
| 255 |
| 241 SiteEngagementService::SiteEngagementService(Profile* profile, | 256 SiteEngagementService::SiteEngagementService(Profile* profile, |
| 242 std::unique_ptr<base::Clock> clock) | 257 std::unique_ptr<base::Clock> clock) |
| 243 : profile_(profile), clock_(std::move(clock)), weak_factory_(this) { | 258 : profile_(profile), clock_(std::move(clock)), weak_factory_(this) { |
| 244 // May be null in tests. | 259 // May be null in tests. |
| 245 history::HistoryService* history = HistoryServiceFactory::GetForProfile( | 260 history::HistoryService* history = HistoryServiceFactory::GetForProfile( |
| 246 profile, ServiceAccessType::IMPLICIT_ACCESS); | 261 profile, ServiceAccessType::IMPLICIT_ACCESS); |
| 247 if (history) | 262 if (history) |
| 248 history->AddObserver(this); | 263 history->AddObserver(this); |
| 249 } | 264 } |
| 250 | 265 |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 if (!engagement_score.last_shortcut_launch_time().is_null() && | 631 if (!engagement_score.last_shortcut_launch_time().is_null() && |
| 617 engagement_score.last_shortcut_launch_time() > last_visit) { | 632 engagement_score.last_shortcut_launch_time() > last_visit) { |
| 618 engagement_score.set_last_shortcut_launch_time(last_visit); | 633 engagement_score.set_last_shortcut_launch_time(last_visit); |
| 619 } | 634 } |
| 620 | 635 |
| 621 engagement_score.Commit(); | 636 engagement_score.Commit(); |
| 622 } | 637 } |
| 623 | 638 |
| 624 SetLastEngagementTime(now); | 639 SetLastEngagementTime(now); |
| 625 } | 640 } |
| OLD | NEW |