| 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 "chrome/browser/android/most_visited_sites.h" | 5 #include "chrome/browser/android/most_visited_sites.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 base::FieldTrialList::FindFullName(kPopularSitesFieldTrialName); | 122 base::FieldTrialList::FindFullName(kPopularSitesFieldTrialName); |
| 123 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 123 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 124 if (cmd_line->HasSwitch(switches::kDisableNTPPopularSites)) | 124 if (cmd_line->HasSwitch(switches::kDisableNTPPopularSites)) |
| 125 return false; | 125 return false; |
| 126 if (cmd_line->HasSwitch(switches::kEnableNTPPopularSites)) | 126 if (cmd_line->HasSwitch(switches::kEnableNTPPopularSites)) |
| 127 return true; | 127 return true; |
| 128 return base::StartsWith(group_name, "Enabled", | 128 return base::StartsWith(group_name, "Enabled", |
| 129 base::CompareCase::INSENSITIVE_ASCII); | 129 base::CompareCase::INSENSITIVE_ASCII); |
| 130 } | 130 } |
| 131 | 131 |
| 132 std::string GetPopularSitesCountry() { |
| 133 return variations::GetVariationParamValue(kPopularSitesFieldTrialName, |
| 134 "country"); |
| 135 } |
| 136 |
| 137 std::string GetPopularSitesVersion() { |
| 138 return variations::GetVariationParamValue(kPopularSitesFieldTrialName, |
| 139 "version"); |
| 140 } |
| 141 |
| 142 // TODO(treib): Get rid of this. |
| 132 std::string GetPopularSitesFilename() { | 143 std::string GetPopularSitesFilename() { |
| 133 return variations::GetVariationParamValue(kPopularSitesFieldTrialName, | 144 return variations::GetVariationParamValue(kPopularSitesFieldTrialName, |
| 134 "filename"); | 145 "filename"); |
| 135 } | 146 } |
| 136 | 147 |
| 137 // Determine whether we need any popular suggestions to fill up a grid of | 148 // Determine whether we need any popular suggestions to fill up a grid of |
| 138 // |num_tiles| tiles. | 149 // |num_tiles| tiles. |
| 139 bool NeedPopularSites(const PrefService* prefs, size_t num_tiles) { | 150 bool NeedPopularSites(const PrefService* prefs, size_t num_tiles) { |
| 140 const base::ListValue* source_list = | 151 const base::ListValue* source_list = |
| 141 prefs->GetList(prefs::kNTPSuggestionsIsPersonal); | 152 prefs->GetList(prefs::kNTPSuggestionsIsPersonal); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 jobject obj, | 242 jobject obj, |
| 232 jobject j_observer, | 243 jobject j_observer, |
| 233 jint num_sites) { | 244 jint num_sites) { |
| 234 observer_.Reset(env, j_observer); | 245 observer_.Reset(env, j_observer); |
| 235 num_sites_ = num_sites; | 246 num_sites_ = num_sites; |
| 236 | 247 |
| 237 if (ShouldShowPopularSites() && | 248 if (ShouldShowPopularSites() && |
| 238 NeedPopularSites(profile_->GetPrefs(), num_sites_)) { | 249 NeedPopularSites(profile_->GetPrefs(), num_sites_)) { |
| 239 popular_sites_.reset(new PopularSites( | 250 popular_sites_.reset(new PopularSites( |
| 240 profile_, | 251 profile_, |
| 252 GetPopularSitesCountry(), |
| 253 GetPopularSitesVersion(), |
| 241 GetPopularSitesFilename(), | 254 GetPopularSitesFilename(), |
| 242 base::Bind(&MostVisitedSites::OnPopularSitesAvailable, | 255 base::Bind(&MostVisitedSites::OnPopularSitesAvailable, |
| 243 base::Unretained(this)))); | 256 base::Unretained(this)))); |
| 244 } else { | 257 } else { |
| 245 received_popular_sites_ = true; | 258 received_popular_sites_ = true; |
| 246 } | 259 } |
| 247 | 260 |
| 248 QueryMostVisitedURLs(); | 261 QueryMostVisitedURLs(); |
| 249 | 262 |
| 250 scoped_refptr<history::TopSites> top_sites = | 263 scoped_refptr<history::TopSites> top_sites = |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 } | 739 } |
| 727 } | 740 } |
| 728 | 741 |
| 729 static jlong Init(JNIEnv* env, | 742 static jlong Init(JNIEnv* env, |
| 730 const JavaParamRef<jobject>& obj, | 743 const JavaParamRef<jobject>& obj, |
| 731 const JavaParamRef<jobject>& jprofile) { | 744 const JavaParamRef<jobject>& jprofile) { |
| 732 MostVisitedSites* most_visited_sites = | 745 MostVisitedSites* most_visited_sites = |
| 733 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); | 746 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); |
| 734 return reinterpret_cast<intptr_t>(most_visited_sites); | 747 return reinterpret_cast<intptr_t>(most_visited_sites); |
| 735 } | 748 } |
| OLD | NEW |