OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/predictors/resource_prefetch_predictor.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "chrome/browser/history/history.h" | 15 #include "chrome/browser/history/history.h" |
16 #include "chrome/browser/history/history_notifications.h" | 16 #include "chrome/browser/history/history_notifications.h" |
17 #include "chrome/browser/history/in_memory_database.h" | 17 #include "chrome/browser/history/in_memory_database.h" |
18 #include "chrome/browser/history/url_database.h" | 18 #include "chrome/browser/history/url_database.h" |
19 #include "chrome/browser/predictors/predictor_database.h" | 19 #include "chrome/browser/predictors/predictor_database.h" |
20 #include "chrome/browser/predictors/predictor_database_factory.h" | 20 #include "chrome/browser/predictors/predictor_database_factory.h" |
| 21 #include "chrome/browser/prerender/prerender_field_trial.h" |
21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/load_from_memory_cache_details.h" | 27 #include "content/public/browser/load_from_memory_cache_details.h" |
27 #include "content/public/browser/navigation_controller.h" | 28 #include "content/public/browser/navigation_controller.h" |
28 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
29 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
30 #include "content/public/browser/notification_types.h" | 31 #include "content/public/browser/notification_types.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 initialization_state_(NOT_INITIALIZED), | 108 initialization_state_(NOT_INITIALIZED), |
108 tables_(PredictorDatabaseFactory::GetForProfile( | 109 tables_(PredictorDatabaseFactory::GetForProfile( |
109 profile)->resource_prefetch_tables()) { | 110 profile)->resource_prefetch_tables()) { |
110 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 111 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
111 } | 112 } |
112 | 113 |
113 ResourcePrefetchPredictor::~ResourcePrefetchPredictor() { | 114 ResourcePrefetchPredictor::~ResourcePrefetchPredictor() { |
114 } | 115 } |
115 | 116 |
116 // static | 117 // static |
117 bool ResourcePrefetchPredictor::IsEnabled() { | 118 bool ResourcePrefetchPredictor::IsEnabled(Profile* profile) { |
118 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 119 return prerender::IsSpeculativeResourcePrefetchingLearningEnabled(profile); |
119 return command_line->HasSwitch( | |
120 switches::kEnableSpeculativeResourcePrefetching); | |
121 } | 120 } |
122 | 121 |
123 void ResourcePrefetchPredictor::LazilyInitialize() { | 122 void ResourcePrefetchPredictor::LazilyInitialize() { |
124 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
125 | 124 |
126 DCHECK_EQ(initialization_state_, NOT_INITIALIZED); | 125 DCHECK_EQ(initialization_state_, NOT_INITIALIZED); |
127 initialization_state_ = INITIALIZING; | 126 initialization_state_ = INITIALIZING; |
128 | 127 |
129 // Request the in-memory database from the history to force it to load so it's | 128 // Request the in-memory database from the history to force it to load so it's |
130 // available as soon as possible. | 129 // available as soon as possible. |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 tables_, | 762 tables_, |
764 urls_to_delete)); | 763 urls_to_delete)); |
765 } | 764 } |
766 | 765 |
767 void ResourcePrefetchPredictor::SetTablesForTesting( | 766 void ResourcePrefetchPredictor::SetTablesForTesting( |
768 scoped_refptr<ResourcePrefetchPredictorTables> tables) { | 767 scoped_refptr<ResourcePrefetchPredictorTables> tables) { |
769 tables_ = tables; | 768 tables_ = tables; |
770 } | 769 } |
771 | 770 |
772 } // namespace predictors | 771 } // namespace predictors |
OLD | NEW |