Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(831)

Side by Side Diff: components/ntp_tiles/most_visited_sites.cc

Issue 2172203002: Enable Popular Sites in Android demo mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: x Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/ntp_tiles/most_visited_sites.h ('k') | tools/android/eclipse/.classpath » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
12 #include "base/callback.h" 16 #include "base/callback.h"
13 #include "base/command_line.h" 17 #include "base/command_line.h"
14 #include "base/feature_list.h" 18 #include "base/feature_list.h"
15 #include "base/metrics/field_trial.h" 19 #include "base/metrics/field_trial.h"
16 #include "base/metrics/histogram.h" 20 #include "base/metrics/histogram.h"
17 #include "base/metrics/sparse_histogram.h" 21 #include "base/metrics/sparse_histogram.h"
18 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
21 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
22 #include "base/time/time.h" 26 #include "base/time/time.h"
23 #include "components/history/core/browser/top_sites.h" 27 #include "components/history/core/browser/top_sites.h"
24 #include "components/ntp_tiles/constants.h" 28 #include "components/ntp_tiles/constants.h"
25 #include "components/ntp_tiles/pref_names.h" 29 #include "components/ntp_tiles/pref_names.h"
26 #include "components/ntp_tiles/switches.h" 30 #include "components/ntp_tiles/switches.h"
27 #include "components/pref_registry/pref_registry_syncable.h" 31 #include "components/pref_registry/pref_registry_syncable.h"
28 #include "components/prefs/pref_service.h" 32 #include "components/prefs/pref_service.h"
29 33
34 #if defined(OS_ANDROID)
35 #include "base/android/jni_android.h"
36 #include "jni/MostVisitedSites_jni.h"
37 #endif
38
30 using history::TopSites; 39 using history::TopSites;
31 using suggestions::ChromeSuggestion; 40 using suggestions::ChromeSuggestion;
32 using suggestions::SuggestionsProfile; 41 using suggestions::SuggestionsProfile;
33 using suggestions::SuggestionsService; 42 using suggestions::SuggestionsService;
34 43
35 namespace ntp_tiles { 44 namespace ntp_tiles {
36 45
37 namespace { 46 namespace {
38 47
39 // Identifiers for the various tile sources. 48 // Identifiers for the various tile sources.
(...skipping 19 matching lines...) Expand all
59 base::Histogram::kUmaTargetedHistogramFlag); 68 base::Histogram::kUmaTargetedHistogramFlag);
60 if (counter) 69 if (counter)
61 counter->Add(position); 70 counter->Add(position);
62 } 71 }
63 72
64 bool ShouldShowPopularSites() { 73 bool ShouldShowPopularSites() {
65 // Note: It's important to query the field trial state first, to ensure that 74 // Note: It's important to query the field trial state first, to ensure that
66 // UMA reports the correct group. 75 // UMA reports the correct group.
67 const std::string group_name = 76 const std::string group_name =
68 base::FieldTrialList::FindFullName(kPopularSitesFieldTrialName); 77 base::FieldTrialList::FindFullName(kPopularSitesFieldTrialName);
78
69 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 79 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
70 if (cmd_line->HasSwitch(switches::kDisableNTPPopularSites)) 80 if (cmd_line->HasSwitch(switches::kDisableNTPPopularSites))
71 return false; 81 return false;
82
72 if (cmd_line->HasSwitch(switches::kEnableNTPPopularSites)) 83 if (cmd_line->HasSwitch(switches::kEnableNTPPopularSites))
73 return true; 84 return true;
85
86 #if defined(OS_ANDROID)
87 if (Java_MostVisitedSites_isPopularSitesForceEnabled(
88 base::android::AttachCurrentThread())) {
89 return true;
90 }
91 #endif
92
74 return base::StartsWith(group_name, "Enabled", 93 return base::StartsWith(group_name, "Enabled",
75 base::CompareCase::INSENSITIVE_ASCII); 94 base::CompareCase::INSENSITIVE_ASCII);
76 } 95 }
77 96
78 // Determine whether we need any popular suggestions to fill up a grid of 97 // Determine whether we need any popular suggestions to fill up a grid of
79 // |num_tiles| tiles. 98 // |num_tiles| tiles.
80 bool NeedPopularSites(const PrefService* prefs, int num_tiles) { 99 bool NeedPopularSites(const PrefService* prefs, int num_tiles) {
81 if (num_tiles <= prefs->GetInteger(prefs::kNumPersonalSuggestions)) 100 if (num_tiles <= prefs->GetInteger(prefs::kNumPersonalSuggestions))
82 return false; 101 return false;
83 102
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)), 178 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)),
160 weak_ptr_factory_(this) { 179 weak_ptr_factory_(this) {
161 DCHECK(suggestions_service_); 180 DCHECK(suggestions_service_);
162 supervisor_->SetObserver(this); 181 supervisor_->SetObserver(this);
163 } 182 }
164 183
165 MostVisitedSites::~MostVisitedSites() { 184 MostVisitedSites::~MostVisitedSites() {
166 supervisor_->SetObserver(nullptr); 185 supervisor_->SetObserver(nullptr);
167 } 186 }
168 187
188 #if defined(OS_ANDROID)
189 // static
190 bool MostVisitedSites::Register(JNIEnv* env) {
191 return RegisterNativesImpl(env);
192 }
193 #endif
194
169 void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer, 195 void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer,
170 int num_sites) { 196 int num_sites) {
171 DCHECK(observer); 197 DCHECK(observer);
172 observer_ = observer; 198 observer_ = observer;
173 num_sites_ = num_sites; 199 num_sites_ = num_sites;
174 200
175 if (ShouldShowPopularSites() && NeedPopularSites(prefs_, num_sites_)) { 201 if (ShouldShowPopularSites() && NeedPopularSites(prefs_, num_sites_)) {
176 popular_sites_.reset(new PopularSites( 202 popular_sites_.reset(new PopularSites(
177 blocking_pool_, prefs_, template_url_service_, variations_service_, 203 blocking_pool_, prefs_, template_url_service_, variations_service_,
178 download_context_, popular_sites_directory_, false, 204 download_context_, popular_sites_directory_, false,
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 567
542 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 568 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
543 ChangeReason change_reason) { 569 ChangeReason change_reason) {
544 if (mv_source_ == TOP_SITES) { 570 if (mv_source_ == TOP_SITES) {
545 // The displayed suggestions are invalidated. 571 // The displayed suggestions are invalidated.
546 InitiateTopSitesQuery(); 572 InitiateTopSitesQuery();
547 } 573 }
548 } 574 }
549 575
550 } // namespace ntp_tiles 576 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/most_visited_sites.h ('k') | tools/android/eclipse/.classpath » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698