OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/ntp_tiles/most_visited_sites.h" | 5 #include "components/ntp_tiles/most_visited_sites.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #if defined(OS_ANDROID) | |
13 #include <jni.h> | |
14 #endif | |
15 | |
16 #include "base/callback.h" | 12 #include "base/callback.h" |
17 #include "base/command_line.h" | |
18 #include "base/feature_list.h" | 13 #include "base/feature_list.h" |
19 #include "base/metrics/field_trial.h" | |
20 #include "base/strings/string_util.h" | |
21 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
22 #include "components/history/core/browser/top_sites.h" | 15 #include "components/history/core/browser/top_sites.h" |
23 #include "components/ntp_tiles/constants.h" | 16 #include "components/ntp_tiles/constants.h" |
17 #include "components/ntp_tiles/field_trial.h" | |
24 #include "components/ntp_tiles/icon_cacher.h" | 18 #include "components/ntp_tiles/icon_cacher.h" |
25 #include "components/ntp_tiles/metrics.h" | 19 #include "components/ntp_tiles/metrics.h" |
26 #include "components/ntp_tiles/pref_names.h" | 20 #include "components/ntp_tiles/pref_names.h" |
27 #include "components/ntp_tiles/switches.h" | 21 #include "components/ntp_tiles/switches.h" |
28 #include "components/pref_registry/pref_registry_syncable.h" | 22 #include "components/pref_registry/pref_registry_syncable.h" |
29 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
30 | 24 |
31 #if defined(OS_ANDROID) | |
32 #include "base/android/jni_android.h" | |
33 #include "jni/MostVisitedSites_jni.h" | |
34 #endif | |
35 | |
36 using history::TopSites; | 25 using history::TopSites; |
37 using suggestions::ChromeSuggestion; | 26 using suggestions::ChromeSuggestion; |
38 using suggestions::SuggestionsProfile; | 27 using suggestions::SuggestionsProfile; |
39 using suggestions::SuggestionsService; | 28 using suggestions::SuggestionsService; |
40 | 29 |
41 namespace ntp_tiles { | 30 namespace ntp_tiles { |
42 | 31 |
43 namespace { | 32 namespace { |
44 | 33 |
45 const base::Feature kDisplaySuggestionsServiceTiles{ | 34 const base::Feature kDisplaySuggestionsServiceTiles{ |
46 "DisplaySuggestionsServiceTiles", base::FEATURE_ENABLED_BY_DEFAULT}; | 35 "DisplaySuggestionsServiceTiles", base::FEATURE_ENABLED_BY_DEFAULT}; |
47 | 36 |
48 bool ShouldShowPopularSites() { | |
49 // Note: It's important to query the field trial state first, to ensure that | |
50 // UMA reports the correct group. | |
51 const std::string group_name = | |
52 base::FieldTrialList::FindFullName(kPopularSitesFieldTrialName); | |
53 | |
54 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | |
55 if (cmd_line->HasSwitch(switches::kDisableNTPPopularSites)) | |
56 return false; | |
57 | |
58 if (cmd_line->HasSwitch(switches::kEnableNTPPopularSites)) | |
59 return true; | |
60 | |
61 #if defined(OS_ANDROID) | |
62 if (Java_MostVisitedSites_isPopularSitesForceEnabled( | |
63 base::android::AttachCurrentThread())) { | |
64 return true; | |
65 } | |
66 #endif | |
67 | |
68 return base::StartsWith(group_name, "Enabled", | |
69 base::CompareCase::INSENSITIVE_ASCII); | |
70 } | |
71 | |
72 // Determine whether we need any tiles from PopularSites to fill up a grid of | 37 // Determine whether we need any tiles from PopularSites to fill up a grid of |
73 // |num_tiles| tiles. | 38 // |num_tiles| tiles. |
74 bool NeedPopularSites(const PrefService* prefs, int num_tiles) { | 39 bool NeedPopularSites(const PrefService* prefs, int num_tiles) { |
75 return prefs->GetInteger(prefs::kNumPersonalTiles) < num_tiles; | 40 return prefs->GetInteger(prefs::kNumPersonalTiles) < num_tiles; |
76 } | 41 } |
77 | 42 |
78 bool AreURLsEquivalent(const GURL& url1, const GURL& url2) { | 43 bool AreURLsEquivalent(const GURL& url1, const GURL& url2) { |
79 return url1.host() == url2.host() && url1.path() == url2.path(); | 44 return url1.host() == url2.host() && url1.path() == url2.path(); |
80 } | 45 } |
81 | 46 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 if (supervisor_) | 78 if (supervisor_) |
114 supervisor_->SetObserver(nullptr); | 79 supervisor_->SetObserver(nullptr); |
115 } | 80 } |
116 | 81 |
117 void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer, | 82 void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer, |
118 int num_sites) { | 83 int num_sites) { |
119 DCHECK(observer); | 84 DCHECK(observer); |
120 observer_ = observer; | 85 observer_ = observer; |
121 num_sites_ = num_sites; | 86 num_sites_ = num_sites; |
122 | 87 |
123 if (popular_sites_ && ShouldShowPopularSites() && | 88 if (popular_sites_ && NeedPopularSites(prefs_, num_sites_) && |
124 NeedPopularSites(prefs_, num_sites_)) { | 89 ShouldShowPopularSites()) { |
noyau (Ping after 24h)
2016/11/09 10:56:39
I changed the order of the test, to only enroll in
rkaplow
2016/11/10 22:56:46
makes sense, field trial group should only be trig
noyau (Ping after 24h)
2016/11/14 17:08:08
Ok, I'll make sure everyone is aware.
Marc Treib
2016/11/16 12:50:29
Drive-by: This is subtle and not obvious from read
noyau (Ping after 24h)
2016/11/16 13:06:03
Done.
| |
125 popular_sites_->StartFetch( | 90 popular_sites_->StartFetch( |
126 false, base::Bind(&MostVisitedSites::OnPopularSitesAvailable, | 91 false, base::Bind(&MostVisitedSites::OnPopularSitesAvailable, |
127 base::Unretained(this))); | 92 base::Unretained(this))); |
128 } else { | 93 } else { |
129 waiting_for_popular_sites_ = false; | 94 waiting_for_popular_sites_ = false; |
130 } | 95 } |
131 | 96 |
132 if (top_sites_) { | 97 if (top_sites_) { |
133 // TopSites updates itself after a delay. To ensure up-to-date results, | 98 // TopSites updates itself after a delay. To ensure up-to-date results, |
134 // force an update now. | 99 // force an update now. |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 | 399 |
435 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, | 400 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, |
436 ChangeReason change_reason) { | 401 ChangeReason change_reason) { |
437 if (mv_source_ == NTPTileSource::TOP_SITES) { | 402 if (mv_source_ == NTPTileSource::TOP_SITES) { |
438 // The displayed tiles are invalidated. | 403 // The displayed tiles are invalidated. |
439 InitiateTopSitesQuery(); | 404 InitiateTopSitesQuery(); |
440 } | 405 } |
441 } | 406 } |
442 | 407 |
443 } // namespace ntp_tiles | 408 } // namespace ntp_tiles |
OLD | NEW |