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

Side by Side Diff: chrome/browser/prerender/prerender_manager.cc

Issue 7828023: Re-enable TopSites in PrerenderManager, this time duplicating the invariant (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/prerender/prerender_manager.h" 5 #include "chrome/browser/prerender/prerender_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 ~PendingContentsData() {} 166 ~PendingContentsData() {}
167 GURL url_; 167 GURL url_;
168 GURL referrer_; 168 GURL referrer_;
169 Origin origin_; 169 Origin origin_;
170 }; 170 };
171 171
172 class PrerenderManager::MostVisitedSites : public NotificationObserver { 172 class PrerenderManager::MostVisitedSites : public NotificationObserver {
173 public: 173 public:
174 explicit MostVisitedSites(Profile* profile) : 174 explicit MostVisitedSites(Profile* profile) :
175 profile_(profile) { 175 profile_(profile) {
176 // If TopSites is already loaded, we will want to use it right away.
177 // Otherwise, wait for three seconds to avoid race conditions.
178 // This is a hack to ensure unit tests don't fail.
179 // See http://crbug.com/94654
180 if (profile && profile->GetTopSitesWithoutCreating()) {
181 Init();
182 } else {
183 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(3), this,
184 &prerender::PrerenderManager::MostVisitedSites::Init);
185 }
186 }
187
188 void Init() {
189 history::TopSites* top_sites = GetTopSites(); 176 history::TopSites* top_sites = GetTopSites();
190 if (top_sites) { 177 if (top_sites) {
191 registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED, 178 registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED,
192 Source<history::TopSites>(top_sites)); 179 Source<history::TopSites>(top_sites));
193 } 180 }
194 181
195 UpdateMostVisited(); 182 UpdateMostVisited();
196 } 183 }
197 184
198 void UpdateMostVisited() { 185 void UpdateMostVisited() {
(...skipping 28 matching lines...) Expand all
227 history::TopSites* GetTopSites() const { 214 history::TopSites* GetTopSites() const {
228 if (profile_) 215 if (profile_)
229 return profile_->GetTopSites(); 216 return profile_->GetTopSites();
230 return NULL; 217 return NULL;
231 } 218 }
232 219
233 CancelableRequestConsumer topsites_consumer_; 220 CancelableRequestConsumer topsites_consumer_;
234 Profile* profile_; 221 Profile* profile_;
235 NotificationRegistrar registrar_; 222 NotificationRegistrar registrar_;
236 std::set<GURL> urls_; 223 std::set<GURL> urls_;
237 base::OneShotTimer<prerender::PrerenderManager::MostVisitedSites> timer_;
238 }; 224 };
239 225
240 bool PrerenderManager::IsTopSite(const GURL& url) const { 226 bool PrerenderManager::IsTopSite(const GURL& url) {
241 return most_visited_.get() && most_visited_->IsTopSite(url); 227 if (!most_visited_.get())
228 most_visited_.reset(new MostVisitedSites(profile_));
229 return most_visited_->IsTopSite(url);
242 } 230 }
243 231
244 PrerenderManager::PrerenderManager(Profile* profile, 232 PrerenderManager::PrerenderManager(Profile* profile,
245 PrerenderTracker* prerender_tracker) 233 PrerenderTracker* prerender_tracker)
246 : enabled_(true), 234 : enabled_(true),
247 profile_(profile), 235 profile_(profile),
248 prerender_tracker_(prerender_tracker), 236 prerender_tracker_(prerender_tracker),
249 prerender_contents_factory_(PrerenderContents::CreateFactory()), 237 prerender_contents_factory_(PrerenderContents::CreateFactory()),
250 last_prerender_start_time_(GetCurrentTimeTicks() - 238 last_prerender_start_time_(GetCurrentTimeTicks() -
251 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)), 239 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)),
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 DeletePendingDeleteEntries(); 1013 DeletePendingDeleteEntries();
1026 } 1014 }
1027 1015
1028 void PrerenderManager::RecordFinalStatus(Origin origin, 1016 void PrerenderManager::RecordFinalStatus(Origin origin,
1029 uint8 experiment_id, 1017 uint8 experiment_id,
1030 FinalStatus final_status) const { 1018 FinalStatus final_status) const {
1031 histograms_->RecordFinalStatus(origin, experiment_id, final_status); 1019 histograms_->RecordFinalStatus(origin, experiment_id, final_status);
1032 } 1020 }
1033 1021
1034 } // namespace prerender 1022 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_manager.h ('k') | chrome/browser/prerender/prerender_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698