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

Side by Side Diff: chrome/browser/favicon/favicon_handler.h

Issue 261403003: Removes usage of NavigationEntry from favicon_handler.* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 (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 #ifndef CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ 5 #ifndef CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_
6 #define CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ 6 #define CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
(...skipping 10 matching lines...) Expand all
21 #include "url/gurl.h" 21 #include "url/gurl.h"
22 22
23 class FaviconClient; 23 class FaviconClient;
24 class FaviconDriver; 24 class FaviconDriver;
25 class SkBitmap; 25 class SkBitmap;
26 26
27 namespace base { 27 namespace base {
28 class RefCountedMemory; 28 class RefCountedMemory;
29 } 29 }
30 30
31 namespace content { 31 // FaviconHandler works with FaviconDriver to fetch the specific type of
32 class NavigationEntry;
33 }
34
35 // FaviconHandler works with FaviconTabHelper to fetch the specific type of
36 // favicon. 32 // favicon.
37 // 33 //
38 // FetchFavicon requests the favicon from the favicon service which in turn 34 // FetchFavicon requests the favicon from the favicon service which in turn
39 // requests the favicon from the history database. At this point 35 // requests the favicon from the history database. At this point
40 // we only know the URL of the page, and not necessarily the url of the 36 // we only know the URL of the page, and not necessarily the url of the
41 // favicon. To ensure we handle reloading stale favicons as well as 37 // favicon. To ensure we handle reloading stale favicons as well as
42 // reloading a favicon on page reload we always request the favicon from 38 // reloading a favicon on page reload we always request the favicon from
43 // history regardless of whether the NavigationEntry has a favicon. 39 // history regardless of whether the active favicon is valid.
44 // 40 //
45 // After the navigation two types of events are delivered (which is 41 // After the navigation two types of events are delivered (which is
46 // first depends upon who is faster): notification from the history 42 // first depends upon who is faster): notification from the history
47 // db on our request for the favicon 43 // db on our request for the favicon
48 // (OnFaviconDataForInitialURLFromFaviconService), or a message from the 44 // (OnFaviconDataForInitialURLFromFaviconService), or a message from the
49 // renderer giving us the URL of the favicon for the page (SetFaviconURL). 45 // renderer giving us the URL of the favicon for the page (SetFaviconURL).
50 // . If the history db has a valid up to date favicon for the page, we update 46 // . If the history db has a valid up to date favicon for the page, we update
51 // the NavigationEntry and use the favicon. 47 // the NavigationEntry and use the favicon.
52 // . When we receive the favicon url if it matches that of the NavigationEntry 48 // . When we receive the favicon url if it matches that of the NavigationEntry
53 // and the NavigationEntry's favicon is set, we do nothing (everything is 49 // and the NavigationEntry's favicon is set, we do nothing (everything is
54 // ok). 50 // ok).
55 // . On the other hand if the database does not know the favicon for url, or 51 // . On the other hand if the database does not know the favicon for url, or
56 // the favicon is out date, or the URL from the renderer does not match that 52 // the favicon is out date, or the URL from the renderer does not match that
57 // NavigationEntry we proceed to DownloadFaviconOrAskHistory. Before we 53 // of the current page we proceed to DownloadFaviconOrAskHistory. Before we
58 // invoke DownloadFaviconOrAskHistory we wait until we've received both 54 // invoke DownloadFaviconOrAskHistory we wait until we've received both
59 // the favicon url and the callback from history. We wait to ensure we 55 // the favicon url and the callback from history. We wait to ensure we
60 // truly know both the favicon url and the state of the database. 56 // truly know both the favicon url and the state of the database.
61 // 57 //
62 // DownloadFaviconOrAskHistory does the following: 58 // DownloadFaviconOrAskHistory does the following:
63 // . If we have a valid favicon, but it is expired we ask the renderer to 59 // . If we have a valid favicon, but it is expired we ask the renderer to
64 // download the favicon. 60 // download the favicon.
65 // . Otherwise we ask the history database to update the mapping from 61 // . Otherwise we ask the history database to update the mapping from
66 // page url to favicon url and call us back with the favicon. Remember, it is 62 // page url to favicon url and call us back with the favicon. Remember, it is
67 // possible for the db to already have the favicon, just not the mapping 63 // possible for the db to already have the favicon, just not the mapping
68 // between page to favicon url. The callback for this is OnFaviconData. 64 // between page to favicon url. The callback for this is OnFaviconData.
69 // 65 //
70 // OnFaviconData either updates the favicon of the NavigationEntry (if the 66 // OnFaviconData either updates the favicon of the NavigationEntry (if the
71 // db knew about the favicon), or requests the renderer to download the 67 // db knew about the favicon), or requests the renderer to download the
72 // favicon. 68 // favicon.
73 // 69 //
74 // When the renderer downloads favicons, it considers the entire list of 70 // When the renderer downloads favicons, it considers the entire list of
75 // favicon candidates, if |download_largest_favicon_| is true, the largest 71 // favicon candidates, if |download_largest_favicon_| is true, the largest
76 // favicon will be used, otherwise the one that best matches the preferred size 72 // favicon will be used, otherwise the one that best matches the preferred size
77 // is chosen (or the first one if there is no preferred size). Once the 73 // is chosen (or the first one if there is no preferred size). Once the
78 // matching favicon has been determined, SetFavicon is called which updates 74 // matching favicon has been determined, SetFavicon is called which updates
79 // the favicon of the NavigationEntry and notifies the database to save the 75 // the page's favicon and notifies the database to save the favicon.
80 // favicon.
81 76
82 class FaviconHandler { 77 class FaviconHandler {
83 public: 78 public:
84 enum Type { 79 enum Type {
85 FAVICON, 80 FAVICON,
86 TOUCH, 81 TOUCH,
87 }; 82 };
88 83
89 FaviconHandler(FaviconClient* client, 84 FaviconHandler(FaviconClient* client,
90 FaviconDriver* driver, 85 FaviconDriver* driver,
(...skipping 25 matching lines...) Expand all
116 111
117 // For testing. 112 // For testing.
118 const std::vector<content::FaviconURL>& image_urls() const { 113 const std::vector<content::FaviconURL>& image_urls() const {
119 return image_urls_; 114 return image_urls_;
120 } 115 }
121 116
122 protected: 117 protected:
123 // These virtual methods make FaviconHandler testable and are overridden by 118 // These virtual methods make FaviconHandler testable and are overridden by
124 // TestFaviconHandler. 119 // TestFaviconHandler.
125 120
126 // Return the NavigationEntry for the active entry, or NULL if the active
127 // entries URL does not match that of the URL last passed to FetchFavicon.
128 virtual content::NavigationEntry* GetEntry();
129
130 // Asks the render to download favicon, returns the request id. 121 // Asks the render to download favicon, returns the request id.
131 virtual int DownloadFavicon(const GURL& image_url, int max_bitmap_size); 122 virtual int DownloadFavicon(const GURL& image_url, int max_bitmap_size);
132 123
133 // Ask the favicon from history 124 // Ask the favicon from history
134 virtual void UpdateFaviconMappingAndFetch( 125 virtual void UpdateFaviconMappingAndFetch(
135 const GURL& page_url, 126 const GURL& page_url,
136 const GURL& icon_url, 127 const GURL& icon_url,
137 favicon_base::IconType icon_type, 128 favicon_base::IconType icon_type,
138 const FaviconService::FaviconResultsCallback& callback, 129 const FaviconService::FaviconResultsCallback& callback,
139 base::CancelableTaskTracker* tracker); 130 base::CancelableTaskTracker* tracker);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 const gfx::Image& image, 216 const gfx::Image& image,
226 float score, 217 float score,
227 favicon_base::IconType icon_type); 218 favicon_base::IconType icon_type);
228 219
229 // Sets the image data for the favicon. 220 // Sets the image data for the favicon.
230 void SetFavicon(const GURL& url, 221 void SetFavicon(const GURL& url,
231 const GURL& icon_url, 222 const GURL& icon_url,
232 const gfx::Image& image, 223 const gfx::Image& image,
233 favicon_base::IconType icon_type); 224 favicon_base::IconType icon_type);
234 225
235 // Sets the favicon's data on the NavigationEntry. 226 // Sets the favicon's data.
236 // If the WebContents has a delegate, it is invalidated (INVALIDATE_TYPE_TAB). 227 // If the WebContents has a delegate, it is invalidated (INVALIDATE_TYPE_TAB).
237 void SetFaviconOnNavigationEntry( 228 void SetFaviconOnNavigationEntry(
blundell 2014/05/09 14:30:34 s/OnNavigationEntry// ? Is line 227 obsolete now?
jif 2014/05/11 13:41:22 Correct.
238 content::NavigationEntry* entry,
239 const std::vector<favicon_base::FaviconBitmapResult>& 229 const std::vector<favicon_base::FaviconBitmapResult>&
240 favicon_bitmap_results); 230 favicon_bitmap_results);
241 void SetFaviconOnNavigationEntry(content::NavigationEntry* entry, 231 void SetFaviconOnNavigationEntry(const GURL& icon_url,
242 const GURL& icon_url,
243 const gfx::Image& image); 232 const gfx::Image& image);
244 233
245 // Return the current candidate if any. 234 // Return the current candidate if any.
246 content::FaviconURL* current_candidate() { 235 content::FaviconURL* current_candidate() {
247 return (!image_urls_.empty()) ? &image_urls_.front() : NULL; 236 return (!image_urls_.empty()) ? &image_urls_.front() : NULL;
248 } 237 }
249 238
239 // Returns wheter the page's url changed since requesting the favicon.
blundell 2014/05/09 14:30:34 s/requesting the favicon/the favicon was requested
jif 2014/05/11 13:41:22 Done.
240 bool PageChangedSinceFaviconWasRequested();
241
250 // Returns the preferred size of the image. 0 means no preference (any size 242 // Returns the preferred size of the image. 0 means no preference (any size
251 // will do). 243 // will do).
252 int preferred_icon_size() const { 244 int preferred_icon_size() const {
253 if (download_largest_icon_) 245 if (download_largest_icon_)
254 return 0; 246 return 0;
255 return icon_types_ == favicon_base::FAVICON ? gfx::kFaviconSize : 0; 247 return icon_types_ == favicon_base::FAVICON ? gfx::kFaviconSize : 0;
256 } 248 }
257 249
258 // Sorts the entries in |image_urls_| by icon size in descending order. 250 // Sorts the entries in |image_urls_| by icon size in descending order.
259 // Additionally removes any entries whose sizes are all greater than the max 251 // Additionally removes any entries whose sizes are all greater than the max
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 // Best image we've seen so far. As images are downloaded from the page they 292 // Best image we've seen so far. As images are downloaded from the page they
301 // are stored here. When there is an exact match, or no more images are 293 // are stored here. When there is an exact match, or no more images are
302 // available the favicon service and the NavigationEntry are updated (assuming 294 // available the favicon service and the NavigationEntry are updated (assuming
303 // the image is for a favicon). 295 // the image is for a favicon).
304 FaviconCandidate best_favicon_candidate_; 296 FaviconCandidate best_favicon_candidate_;
305 297
306 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); 298 DISALLOW_COPY_AND_ASSIGN(FaviconHandler);
307 }; 299 };
308 300
309 #endif // CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ 301 #endif // CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/favicon/favicon_handler.cc » ('j') | chrome/browser/favicon/favicon_tab_helper.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698