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

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

Issue 7740029: Revert 98250 - Add code to keep track of what fraction of pageviews are top sites. (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"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/favicon/favicon_tab_helper.h" 17 #include "chrome/browser/favicon/favicon_tab_helper.h"
18 #include "chrome/browser/history/top_sites.h"
19 #include "chrome/browser/prerender/prerender_condition.h" 18 #include "chrome/browser/prerender/prerender_condition.h"
20 #include "chrome/browser/prerender/prerender_contents.h" 19 #include "chrome/browser/prerender/prerender_contents.h"
21 #include "chrome/browser/prerender/prerender_final_status.h" 20 #include "chrome/browser/prerender/prerender_final_status.h"
22 #include "chrome/browser/prerender/prerender_histograms.h" 21 #include "chrome/browser/prerender/prerender_histograms.h"
23 #include "chrome/browser/prerender/prerender_history.h" 22 #include "chrome/browser/prerender/prerender_history.h"
24 #include "chrome/browser/prerender/prerender_observer.h" 23 #include "chrome/browser/prerender/prerender_observer.h"
25 #include "chrome/browser/prerender/prerender_tracker.h" 24 #include "chrome/browser/prerender/prerender_tracker.h"
26 #include "chrome/browser/prerender/prerender_util.h" 25 #include "chrome/browser/prerender/prerender_util.h"
27 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
29 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" 28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h"
30 #include "chrome/common/chrome_notification_types.h"
31 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/render_messages.h" 30 #include "chrome/common/render_messages.h"
33 #include "content/browser/browser_thread.h" 31 #include "content/browser/browser_thread.h"
34 #include "content/browser/cancelable_request.h"
35 #include "content/browser/renderer_host/render_process_host.h" 32 #include "content/browser/renderer_host/render_process_host.h"
36 #include "content/browser/renderer_host/render_view_host.h" 33 #include "content/browser/renderer_host/render_view_host.h"
37 #include "content/browser/renderer_host/resource_dispatcher_host.h" 34 #include "content/browser/renderer_host/resource_dispatcher_host.h"
38 #include "content/browser/tab_contents/render_view_host_manager.h" 35 #include "content/browser/tab_contents/render_view_host_manager.h"
39 #include "content/browser/tab_contents/tab_contents.h" 36 #include "content/browser/tab_contents/tab_contents.h"
40 #include "content/browser/tab_contents/tab_contents_delegate.h" 37 #include "content/browser/tab_contents/tab_contents_delegate.h"
41 #include "content/common/notification_observer.h"
42 #include "content/common/notification_registrar.h"
43 #include "content/common/notification_service.h" 38 #include "content/common/notification_service.h"
44 39
45 namespace prerender { 40 namespace prerender {
46 41
47 namespace { 42 namespace {
48 43
49 // Time window for which we will record windowed PLT's from the last 44 // Time window for which we will record windowed PLT's from the last
50 // observed link rel=prefetch tag. 45 // observed link rel=prefetch tag.
51 const int kWindowDurationSeconds = 30; 46 const int kWindowDurationSeconds = 30;
52 47
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 PendingContentsData(const GURL& url, 158 PendingContentsData(const GURL& url,
164 const GURL& referrer, 159 const GURL& referrer,
165 Origin origin) 160 Origin origin)
166 : url_(url), referrer_(referrer), origin_(origin) { } 161 : url_(url), referrer_(referrer), origin_(origin) { }
167 ~PendingContentsData() {} 162 ~PendingContentsData() {}
168 GURL url_; 163 GURL url_;
169 GURL referrer_; 164 GURL referrer_;
170 Origin origin_; 165 Origin origin_;
171 }; 166 };
172 167
173 class PrerenderManager::MostVisitedSites : public NotificationObserver {
174 public:
175 explicit MostVisitedSites(Profile* profile) :
176 profile_(profile) {
177 history::TopSites* ts = GetTopSites();
178 if (ts) {
179 registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED,
180 Source<history::TopSites>(ts));
181 }
182
183 UpdateMostVisited();
184 }
185
186 void UpdateMostVisited() {
187 history::TopSites* ts = GetTopSites();
188 if (ts) {
189 ts->GetMostVisitedURLs(
190 &topsites_consumer_,
191 NewCallback(this,
192 &prerender::PrerenderManager::MostVisitedSites::
193 OnMostVisitedURLsAvailable));
194 }
195 }
196
197 void OnMostVisitedURLsAvailable(const history::MostVisitedURLList& data) {
198 urls_.clear();
199 for (int i = 0; i < static_cast<int>(data.size()); i++)
200 urls_.insert(data[i].url);
201 }
202
203 void Observe(int type,
204 const NotificationSource& source,
205 const NotificationDetails& details) {
206 DCHECK_EQ(type, chrome::NOTIFICATION_TOP_SITES_CHANGED);
207 UpdateMostVisited();
208 }
209
210 bool IsTopSite(const GURL& url) const {
211 return (urls_.count(url) > 0);
212 }
213
214 private:
215 history::TopSites* GetTopSites() const {
216 if (profile_)
217 return profile_->GetTopSites();
218 return NULL;
219 }
220 CancelableRequestConsumer topsites_consumer_;
221 Profile* profile_;
222 NotificationRegistrar registrar_;
223 std::set<GURL> urls_;
224 };
225
226 bool PrerenderManager::IsTopSite(const GURL& url) const {
227 return most_visited_->IsTopSite(url);
228 }
229
230 PrerenderManager::PrerenderManager(Profile* profile, 168 PrerenderManager::PrerenderManager(Profile* profile,
231 PrerenderTracker* prerender_tracker) 169 PrerenderTracker* prerender_tracker)
232 : enabled_(true), 170 : enabled_(true),
233 profile_(profile), 171 profile_(profile),
234 prerender_tracker_(prerender_tracker), 172 prerender_tracker_(prerender_tracker),
235 prerender_contents_factory_(PrerenderContents::CreateFactory()), 173 prerender_contents_factory_(PrerenderContents::CreateFactory()),
236 last_prerender_start_time_(GetCurrentTimeTicks() - 174 last_prerender_start_time_(GetCurrentTimeTicks() -
237 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)), 175 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)),
238 runnable_method_factory_(this), 176 runnable_method_factory_(this),
239 prerender_history_(new PrerenderHistory(kHistoryLength)), 177 prerender_history_(new PrerenderHistory(kHistoryLength)),
240 histograms_(new PrerenderHistograms()), 178 histograms_(new PrerenderHistograms()) {
241 most_visited_(new MostVisitedSites(profile)) {
242 // There are some assumptions that the PrerenderManager is on the UI thread. 179 // There are some assumptions that the PrerenderManager is on the UI thread.
243 // Any other checks simply make sure that the PrerenderManager is accessed on 180 // Any other checks simply make sure that the PrerenderManager is accessed on
244 // the same thread that it was created on. 181 // the same thread that it was created on.
245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
246 } 183 }
247 184
248 PrerenderManager::~PrerenderManager() { 185 PrerenderManager::~PrerenderManager() {
249 DestroyAllContents(FINAL_STATUS_MANAGER_SHUTDOWN); 186 DestroyAllContents(FINAL_STATUS_MANAGER_SHUTDOWN);
250 STLDeleteElements(&prerender_conditions_); 187 STLDeleteElements(&prerender_conditions_);
251 } 188 }
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 DeletePendingDeleteEntries(); 952 DeletePendingDeleteEntries();
1016 } 953 }
1017 954
1018 void PrerenderManager::RecordFinalStatus(Origin origin, 955 void PrerenderManager::RecordFinalStatus(Origin origin,
1019 uint8 experiment_id, 956 uint8 experiment_id,
1020 FinalStatus final_status) const { 957 FinalStatus final_status) const {
1021 histograms_->RecordFinalStatus(origin, experiment_id, final_status); 958 histograms_->RecordFinalStatus(origin, experiment_id, final_status);
1022 } 959 }
1023 960
1024 } // namespace prerender 961 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_manager.h ('k') | chrome/browser/prerender/prerender_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698