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

Side by Side Diff: chrome/browser/android/most_visited_sites.cc

Issue 1302773002: Popular sites on the NTP: add the option to provide the server filename through a variation param (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: redownload on filename change Created 5 years, 4 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 | « no previous file | chrome/browser/android/popular_sites.h » ('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 "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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // Client impression. 69 // Client impression.
70 const char kImpressionClientHistogramName[] = 70 const char kImpressionClientHistogramName[] =
71 "NewTabPage.SuggestionsImpression.client"; 71 "NewTabPage.SuggestionsImpression.client";
72 // Server suggestion impression, no provider. 72 // Server suggestion impression, no provider.
73 const char kImpressionServerHistogramName[] = 73 const char kImpressionServerHistogramName[] =
74 "NewTabPage.SuggestionsImpression.server"; 74 "NewTabPage.SuggestionsImpression.server";
75 // Server suggestion impression with provider. 75 // Server suggestion impression with provider.
76 const char kImpressionServerHistogramFormat[] = 76 const char kImpressionServerHistogramFormat[] =
77 "NewTabPage.SuggestionsImpression.server%d"; 77 "NewTabPage.SuggestionsImpression.server%d";
78 78
79 const char kPopularSitesFieldTrialName[] = "NTPPopularSites";
80
79 scoped_ptr<SkBitmap> MaybeFetchLocalThumbnail( 81 scoped_ptr<SkBitmap> MaybeFetchLocalThumbnail(
80 const GURL& url, 82 const GURL& url,
81 const scoped_refptr<TopSites>& top_sites) { 83 const scoped_refptr<TopSites>& top_sites) {
82 DCHECK_CURRENTLY_ON(BrowserThread::DB); 84 DCHECK_CURRENTLY_ON(BrowserThread::DB);
83 scoped_refptr<base::RefCountedMemory> image; 85 scoped_refptr<base::RefCountedMemory> image;
84 scoped_ptr<SkBitmap> bitmap; 86 scoped_ptr<SkBitmap> bitmap;
85 if (top_sites && top_sites->GetPageThumbnail(url, false, &image)) 87 if (top_sites && top_sites->GetPageThumbnail(url, false, &image))
86 bitmap.reset(gfx::JPEGCodec::Decode(image->front(), image->size())); 88 bitmap.reset(gfx::JPEGCodec::Decode(image->front(), image->size()));
87 return bitmap.Pass(); 89 return bitmap.Pass();
88 } 90 }
(...skipping 22 matching lines...) Expand all
111 return suggestions::GetSyncState( 113 return suggestions::GetSyncState(
112 sync->CanSyncStart(), 114 sync->CanSyncStart(),
113 sync->IsSyncActive() && sync->ConfigurationDone(), 115 sync->IsSyncActive() && sync->ConfigurationDone(),
114 sync->GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES)); 116 sync->GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES));
115 } 117 }
116 118
117 bool ShouldShowPopularSites() { 119 bool ShouldShowPopularSites() {
118 // Note: It's important to query the field trial state first, to ensure that 120 // Note: It's important to query the field trial state first, to ensure that
119 // UMA reports the correct group. 121 // UMA reports the correct group.
120 const std::string group_name = 122 const std::string group_name =
121 base::FieldTrialList::FindFullName("NTPPopularSites"); 123 base::FieldTrialList::FindFullName(kPopularSitesFieldTrialName);
122 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 124 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
123 if (cmd_line->HasSwitch(switches::kDisableNTPPopularSites)) 125 if (cmd_line->HasSwitch(switches::kDisableNTPPopularSites))
124 return false; 126 return false;
125 if (cmd_line->HasSwitch(switches::kEnableNTPPopularSites)) 127 if (cmd_line->HasSwitch(switches::kEnableNTPPopularSites))
126 return true; 128 return true;
127 return group_name == "Enabled"; 129 return group_name == "Enabled";
128 } 130 }
129 131
132 std::string GetPopularSitesFilename() {
133 return variations::GetVariationParamValue(kPopularSitesFieldTrialName,
134 "filename");
135 }
136
130 } // namespace 137 } // namespace
131 138
132 MostVisitedSites::MostVisitedSites(Profile* profile) 139 MostVisitedSites::MostVisitedSites(Profile* profile)
133 : profile_(profile), num_sites_(0), initial_load_done_(false), 140 : profile_(profile), num_sites_(0), initial_load_done_(false),
134 num_local_thumbs_(0), num_server_thumbs_(0), num_empty_thumbs_(0), 141 num_local_thumbs_(0), num_server_thumbs_(0), num_empty_thumbs_(0),
135 scoped_observer_(this), weak_ptr_factory_(this) { 142 scoped_observer_(this), weak_ptr_factory_(this) {
136 // Register the debugging page for the Suggestions Service and the thumbnails 143 // Register the debugging page for the Suggestions Service and the thumbnails
137 // debugging page. 144 // debugging page.
138 content::URLDataSource::Add(profile_, 145 content::URLDataSource::Add(profile_,
139 new suggestions::SuggestionsSource(profile_)); 146 new suggestions::SuggestionsSource(profile_));
140 content::URLDataSource::Add(profile_, new ThumbnailListSource(profile_)); 147 content::URLDataSource::Add(profile_, new ThumbnailListSource(profile_));
141 148
142 // Register this class as an observer to the sync service. It is important to 149 // Register this class as an observer to the sync service. It is important to
143 // be notified of changes in the sync state such as initialization, sync 150 // be notified of changes in the sync state such as initialization, sync
144 // being enabled or disabled, etc. 151 // being enabled or disabled, etc.
145 ProfileSyncService* profile_sync_service = 152 ProfileSyncService* profile_sync_service =
146 ProfileSyncServiceFactory::GetForProfile(profile_); 153 ProfileSyncServiceFactory::GetForProfile(profile_);
147 if (profile_sync_service) 154 if (profile_sync_service)
148 profile_sync_service->AddObserver(this); 155 profile_sync_service->AddObserver(this);
149 156
150 if (ShouldShowPopularSites()) { 157 if (ShouldShowPopularSites()) {
151 popular_sites_.reset(new PopularSites( 158 popular_sites_.reset(new PopularSites(
159 GetPopularSitesFilename(),
152 profile_->GetRequestContext(), 160 profile_->GetRequestContext(),
153 base::Bind(&MostVisitedSites::OnPopularSitesAvailable, 161 base::Bind(&MostVisitedSites::OnPopularSitesAvailable,
154 base::Unretained(this)))); 162 base::Unretained(this))));
155 } 163 }
156 } 164 }
157 165
158 MostVisitedSites::~MostVisitedSites() { 166 MostVisitedSites::~MostVisitedSites() {
159 ProfileSyncService* profile_sync_service = 167 ProfileSyncService* profile_sync_service =
160 ProfileSyncServiceFactory::GetForProfile(profile_); 168 ProfileSyncServiceFactory::GetForProfile(profile_);
161 if (profile_sync_service && profile_sync_service->HasObserver(this)) 169 if (profile_sync_service && profile_sync_service->HasObserver(this))
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 // The displayed suggestions are invalidated. 565 // The displayed suggestions are invalidated.
558 QueryMostVisitedURLs(); 566 QueryMostVisitedURLs();
559 } 567 }
560 } 568 }
561 569
562 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) { 570 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) {
563 MostVisitedSites* most_visited_sites = 571 MostVisitedSites* most_visited_sites =
564 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); 572 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile));
565 return reinterpret_cast<intptr_t>(most_visited_sites); 573 return reinterpret_cast<intptr_t>(most_visited_sites);
566 } 574 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/popular_sites.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698