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

Side by Side Diff: components/precache/content/precache_manager.h

Issue 1266243003: Tweaks to the precache triggering code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. 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
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 #ifndef COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ 5 #ifndef COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_
6 #define COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ 6 #define COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 class PrecacheManager : public KeyedService, 53 class PrecacheManager : public KeyedService,
54 public PrecacheFetcher::PrecacheDelegate, 54 public PrecacheFetcher::PrecacheDelegate,
55 public base::SupportsWeakPtr<PrecacheManager> { 55 public base::SupportsWeakPtr<PrecacheManager> {
56 public: 56 public:
57 typedef base::Closure PrecacheCompletionCallback; 57 typedef base::Closure PrecacheCompletionCallback;
58 58
59 PrecacheManager(content::BrowserContext* browser_context, 59 PrecacheManager(content::BrowserContext* browser_context,
60 const sync_driver::SyncService* const sync_service); 60 const sync_driver::SyncService* const sync_service);
61 ~PrecacheManager() override; 61 ~PrecacheManager() override;
62 62
63 // Returns true if precaching is enabled as part of a field trial or by the 63 // Returns true if precaching is allowed for the browser context based on user
64 // command line flag. This method can be called on any thread. 64 // settings, and enabled as part of a field trial or by commandline flag.
65 static bool IsPrecachingEnabled(); 65 // Virtual for testing.
66 virtual bool ShouldRun() const;
bengr 2015/08/07 17:21:45 I'm not a huge fan of these names, but am ok with
twifkak 2015/08/07 17:57:08 I'm not a huge fan of them either. When I introduc
66 67
67 // Returns true if precaching is allowed for the browser context. 68 // Returns true if precaching is allowed for the browser context based on user
68 bool IsPrecachingAllowed(); 69 // settings. Virtual for testing.
70 virtual bool WouldRun() const;
69 71
70 // Starts precaching resources that the user is predicted to fetch in the 72 // Starts precaching resources that the user is predicted to fetch in the
71 // future. If precaching is already currently in progress, then this method 73 // future. If precaching is already currently in progress, then this method
72 // does nothing. The |precache_completion_callback| will be run when 74 // does nothing. The |precache_completion_callback| will be run when
73 // precaching finishes, but will not be run if precaching is canceled. 75 // precaching finishes, but will not be run if precaching is canceled.
74 void StartPrecaching( 76 void StartPrecaching(
75 const PrecacheCompletionCallback& precache_completion_callback, 77 const PrecacheCompletionCallback& precache_completion_callback,
76 const history::HistoryService& history_service); 78 const history::HistoryService& history_service);
77 79
78 // Cancels precaching if it is in progress. 80 // Cancels precaching if it is in progress.
(...skipping 15 matching lines...) Expand all
94 private: 96 private:
95 // From KeyedService. 97 // From KeyedService.
96 void Shutdown() override; 98 void Shutdown() override;
97 99
98 // From PrecacheFetcher::PrecacheDelegate. 100 // From PrecacheFetcher::PrecacheDelegate.
99 void OnDone() override; 101 void OnDone() override;
100 102
101 // From history::HistoryService::TopHosts. 103 // From history::HistoryService::TopHosts.
102 void OnHostsReceived(const history::TopHostsList& host_counts); 104 void OnHostsReceived(const history::TopHostsList& host_counts);
103 105
106 // Returns true if precaching is enabled as part of a field trial or by the
107 // command line flag. This has a different meaning from the
108 // "is_precaching_enabled" pref set in PrecacheServiceLauncher. This method
109 // can be called on any thread.
110 static bool IsPrecachingEnabled();
111
112 // Returns true if precaching is allowed for the browser context.
113 bool IsPrecachingAllowed() const;
114
104 // The browser context that owns this PrecacheManager. 115 // The browser context that owns this PrecacheManager.
105 content::BrowserContext* const browser_context_; 116 content::BrowserContext* const browser_context_;
106 117
107 // The sync service corresponding to the browser context. Used to determine 118 // The sync service corresponding to the browser context. Used to determine
108 // whether precache can run. May be null. 119 // whether precache can run. May be null.
109 const sync_driver::SyncService* const sync_service_; 120 const sync_driver::SyncService* const sync_service_;
110 121
111 // The PrecacheFetcher used to precache resources. Should only be used on the 122 // The PrecacheFetcher used to precache resources. Should only be used on the
112 // UI thread. 123 // UI thread.
113 scoped_ptr<PrecacheFetcher> precache_fetcher_; 124 scoped_ptr<PrecacheFetcher> precache_fetcher_;
114 125
115 // The callback that will be run if precaching finishes without being 126 // The callback that will be run if precaching finishes without being
116 // canceled. 127 // canceled.
117 PrecacheCompletionCallback precache_completion_callback_; 128 PrecacheCompletionCallback precache_completion_callback_;
118 129
119 // The PrecacheDatabase for tracking precache metrics. Should only be used on 130 // The PrecacheDatabase for tracking precache metrics. Should only be used on
120 // the DB thread. 131 // the DB thread.
121 const scoped_refptr<PrecacheDatabase> precache_database_; 132 const scoped_refptr<PrecacheDatabase> precache_database_;
122 133
123 // Flag indicating whether or not precaching is currently in progress. 134 // Flag indicating whether or not precaching is currently in progress.
124 bool is_precaching_; 135 bool is_precaching_;
125 136
126 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); 137 DISALLOW_COPY_AND_ASSIGN(PrecacheManager);
127 }; 138 };
128 139
129 } // namespace precache 140 } // namespace precache
130 141
131 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ 142 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698