| OLD | NEW | 
|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_UTIL_H_ | 5 #ifndef CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_UTIL_H_ | 
| 6 #define CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_UTIL_H_ | 6 #define CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_UTIL_H_ | 
| 7 | 7 | 
| 8 #include <string> | 8 #include <string> | 
| 9 #include <vector> | 9 #include <vector> | 
| 10 | 10 | 
|  | 11 #include "base/callback.h" | 
| 11 #include "base/macros.h" | 12 #include "base/macros.h" | 
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" | 
| 13 | 14 | 
| 14 class Profile; | 15 class Profile; | 
| 15 | 16 | 
|  | 17 namespace content { | 
|  | 18 class DOMStorageContext; | 
|  | 19 } | 
|  | 20 | 
|  | 21 namespace storage { | 
|  | 22 class QuotaManager; | 
|  | 23 } | 
|  | 24 | 
| 16 namespace user_prefs { | 25 namespace user_prefs { | 
| 17 class PrefRegistrySyncable; | 26 class PrefRegistrySyncable; | 
| 18 } | 27 } | 
| 19 | 28 | 
|  | 29 // Helper methods for important sites. | 
|  | 30 // All methods should be used on the UI thread. | 
| 20 class ImportantSitesUtil { | 31 class ImportantSitesUtil { | 
| 21  public: | 32  public: | 
|  | 33 #if defined(OS_ANDROID) | 
|  | 34   static const int kMaxImportantSites = 5; | 
|  | 35 #else | 
|  | 36   static const int kMaxImportantSites = 10; | 
|  | 37 #endif | 
|  | 38 | 
| 22   struct ImportantDomainInfo { | 39   struct ImportantDomainInfo { | 
| 23     std::string registerable_domain; | 40     std::string registerable_domain; | 
| 24     GURL example_origin; | 41     GURL example_origin; | 
| 25     double engagement_score = 0; | 42     double engagement_score = 0; | 
| 26     int32_t reason_bitfield = 0; | 43     int32_t reason_bitfield = 0; | 
|  | 44     int64_t usage = 0; | 
| 27   }; | 45   }; | 
| 28 | 46 | 
| 29   // Do not change the values here, as they are used for UMA histograms. | 47   // Do not change the values here, as they are used for UMA histograms. | 
| 30   enum ImportantReason { | 48   enum ImportantReason { | 
| 31     ENGAGEMENT = 0, | 49     ENGAGEMENT = 0, | 
| 32     DURABLE = 1, | 50     DURABLE = 1, | 
| 33     BOOKMARKS = 2, | 51     BOOKMARKS = 2, | 
| 34     HOME_SCREEN = 3, | 52     HOME_SCREEN = 3, | 
| 35     NOTIFICATIONS = 4, | 53     NOTIFICATIONS = 4, | 
| 36     REASON_BOUNDARY | 54     REASON_BOUNDARY | 
| 37   }; | 55   }; | 
| 38 | 56 | 
|  | 57   using UsageCallback = | 
|  | 58       base::Callback<void(std::vector<ImportantDomainInfo> sites)>; | 
|  | 59 | 
| 39   static bool IsDialogDisabled(Profile* profile); | 60   static bool IsDialogDisabled(Profile* profile); | 
| 40 | 61 | 
| 41   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 62   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 
| 42 | 63 | 
| 43   // This returns the top |<=max_results| important registrable domains. This | 64   // This returns the top |<=max_results| important registrable domains. This | 
| 44   // uses site engagement and notifications to generate the list. |max_results| | 65   // uses site engagement and notifications to generate the list. |max_results| | 
| 45   // is assumed to be small. | 66   // is assumed to be small. | 
| 46   // See net/base/registry_controlled_domains/registry_controlled_domain.h for | 67   // See net/base/registry_controlled_domains/registry_controlled_domain.h for | 
| 47   // more details on registrable domains and the current list of effective | 68   // more details on registrable domains and the current list of effective | 
| 48   // eTLDs. | 69   // eTLDs. | 
| 49   static std::vector<ImportantDomainInfo> GetImportantRegisterableDomains( | 70   static std::vector<ImportantDomainInfo> GetImportantRegisterableDomains( | 
| 50       Profile* profile, | 71       Profile* profile, | 
| 51       size_t max_results); | 72       size_t max_results); | 
| 52 | 73 | 
|  | 74   // Populates the ImportantDomainInfo::usage field of each site with the amount | 
|  | 75   // of localstorage and quota bytes used. The |sites| vector with populated | 
|  | 76   // usage fields is returned by |callback|. | 
|  | 77   static void PopulateUsage(storage::QuotaManager* quota_manager, | 
|  | 78                             content::DOMStorageContext* dom_storage, | 
|  | 79                             std::vector<ImportantDomainInfo> sites, | 
|  | 80                             UsageCallback callback); | 
|  | 81 | 
| 53   // Record the sites that the user chose to blacklist from clearing (in the | 82   // Record the sites that the user chose to blacklist from clearing (in the | 
| 54   // Clear Browsing Dialog) and the sites they ignored. The blacklisted sites | 83   // Clear Browsing Dialog) and the sites they ignored. The blacklisted sites | 
| 55   // are NOT cleared as they are 'blacklisted' from the clear operation. | 84   // are NOT cleared as they are 'blacklisted' from the clear operation. | 
| 56   // This records metrics for blacklisted and ignored sites and removes any | 85   // This records metrics for blacklisted and ignored sites and removes any | 
| 57   // 'ignored' sites from our important sites list if they were ignored 3 times | 86   // 'ignored' sites from our important sites list if they were ignored 3 times | 
| 58   // in a row. | 87   // in a row. | 
| 59   static void RecordBlacklistedAndIgnoredImportantSites( | 88   static void RecordBlacklistedAndIgnoredImportantSites( | 
| 60       Profile* profile, | 89       Profile* profile, | 
| 61       const std::vector<std::string>& blacklisted_sites, | 90       const std::vector<std::string>& blacklisted_sites, | 
| 62       const std::vector<int32_t>& blacklisted_sites_reason_bitfield, | 91       const std::vector<int32_t>& blacklisted_sites_reason_bitfield, | 
| 63       const std::vector<std::string>& ignored_sites, | 92       const std::vector<std::string>& ignored_sites, | 
| 64       const std::vector<int32_t>& ignored_sites_reason_bitfield); | 93       const std::vector<int32_t>& ignored_sites_reason_bitfield); | 
| 65 | 94 | 
| 66   // This marks the given origin as important for testing. Note: This changes | 95   // This marks the given origin as important for testing. Note: This changes | 
| 67   // the score requirements for the Site Engagement Service, so ONLY call for | 96   // the score requirements for the Site Engagement Service, so ONLY call for | 
| 68   // testing. | 97   // testing. | 
| 69   static void MarkOriginAsImportantForTesting(Profile* profile, | 98   static void MarkOriginAsImportantForTesting(Profile* profile, | 
| 70                                               const GURL& origin); | 99                                               const GURL& origin); | 
| 71 | 100 | 
| 72  private: | 101  private: | 
| 73   DISALLOW_IMPLICIT_CONSTRUCTORS(ImportantSitesUtil); | 102   DISALLOW_IMPLICIT_CONSTRUCTORS(ImportantSitesUtil); | 
| 74 }; | 103 }; | 
| 75 | 104 | 
| 76 #endif  // CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_UTIL_H_ | 105 #endif  // CHROME_BROWSER_ENGAGEMENT_IMPORTANT_SITES_UTIL_H_ | 
| OLD | NEW | 
|---|