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

Side by Side Diff: chrome/browser/favicon/favicon_service.cc

Issue 10857037: Make FaviconService a ProfileKeyedService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Override Shutdown() in FaviconService to NULL the profile_ pointer. Created 8 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 | Annotate | Revision Log
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 #include "chrome/browser/favicon/favicon_service.h" 5 #include "chrome/browser/favicon/favicon_service.h"
6 6
7 #include "chrome/browser/history/history.h" 7 #include "chrome/browser/history/history.h"
8 #include "chrome/browser/history/history_backend.h" 8 #include "chrome/browser/history/history_backend.h"
9 #include "chrome/browser/history/history_service_factory.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 9 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
12 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
13 11
14 FaviconService::FaviconService(Profile* profile) : profile_(profile) { 12 FaviconService::FaviconService(scoped_refptr<HistoryService> hs,
13 Profile* profile)
14 : history_service_(hs), profile_(profile) {
15 } 15 }
16 16
17 FaviconService::Handle FaviconService::GetFavicon( 17 FaviconService::Handle FaviconService::GetFavicon(
18 const GURL& icon_url, 18 const GURL& icon_url,
19 history::IconType icon_type, 19 history::IconType icon_type,
20 CancelableRequestConsumerBase* consumer, 20 CancelableRequestConsumerBase* consumer,
21 const FaviconDataCallback& callback) { 21 const FaviconDataCallback& callback) {
22 GetFaviconRequest* request = new GetFaviconRequest(callback); 22 GetFaviconRequest* request = new GetFaviconRequest(callback);
23 AddRequest(request, consumer); 23 AddRequest(request, consumer);
24 HistoryService* hs = 24 if (history_service_)
25 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 25 history_service_->GetFavicon(request, icon_url, icon_type);
26 if (hs)
27 hs->GetFavicon(request, icon_url, icon_type);
28 else 26 else
29 ForwardEmptyResultAsync(request); 27 ForwardEmptyResultAsync(request);
30 return request->handle(); 28 return request->handle();
31 } 29 }
32 30
33 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( 31 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch(
34 const GURL& page_url, 32 const GURL& page_url,
35 const GURL& icon_url, 33 const GURL& icon_url,
36 history::IconType icon_type, 34 history::IconType icon_type,
37 CancelableRequestConsumerBase* consumer, 35 CancelableRequestConsumerBase* consumer,
38 const FaviconDataCallback& callback) { 36 const FaviconDataCallback& callback) {
39 GetFaviconRequest* request = new GetFaviconRequest(callback); 37 GetFaviconRequest* request = new GetFaviconRequest(callback);
40 AddRequest(request, consumer); 38 AddRequest(request, consumer);
41 HistoryService* hs = 39 if (history_service_)
42 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 40 history_service_->UpdateFaviconMappingAndFetch(
43 if (hs) 41 request, page_url, icon_url, icon_type);
44 hs->UpdateFaviconMappingAndFetch(request, page_url, icon_url, icon_type);
45 else 42 else
46 ForwardEmptyResultAsync(request); 43 ForwardEmptyResultAsync(request);
47 return request->handle(); 44 return request->handle();
48 } 45 }
49 46
50 FaviconService::Handle FaviconService::GetFaviconForURL( 47 FaviconService::Handle FaviconService::GetFaviconForURL(
51 const GURL& page_url, 48 const GURL& page_url,
52 int icon_types, 49 int icon_types,
53 CancelableRequestConsumerBase* consumer, 50 CancelableRequestConsumerBase* consumer,
54 const FaviconDataCallback& callback) { 51 const FaviconDataCallback& callback) {
55 GetFaviconRequest* request = new GetFaviconRequest(callback); 52 GetFaviconRequest* request = new GetFaviconRequest(callback);
56 AddRequest(request, consumer); 53 AddRequest(request, consumer);
57 FaviconService::Handle handle = request->handle(); 54 FaviconService::Handle handle = request->handle();
58 if (page_url.SchemeIs(chrome::kChromeUIScheme) || 55 if (page_url.SchemeIs(chrome::kChromeUIScheme) ||
59 page_url.SchemeIs(chrome::kExtensionScheme)) { 56 page_url.SchemeIs(chrome::kExtensionScheme)) {
57 DCHECK(profile_) << "FaviconService::Shutdown() was already called!";
60 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL( 58 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL(
61 profile_, request, page_url); 59 profile_, request, page_url);
62 } else { 60 } else {
63 HistoryService* hs = HistoryServiceFactory::GetForProfile( 61 if (history_service_)
64 profile_, Profile::EXPLICIT_ACCESS); 62 history_service_->GetFaviconForURL(request, page_url, icon_types);
65 if (hs)
66 hs->GetFaviconForURL(request, page_url, icon_types);
67 else 63 else
68 ForwardEmptyResultAsync(request); 64 ForwardEmptyResultAsync(request);
69 } 65 }
70 return handle; 66 return handle;
71 } 67 }
72 68
73 // Requests the favicon for |favicon_id|. The |consumer| is notified when the 69 // Requests the favicon for |favicon_id|. The |consumer| is notified when the
74 // bits have been fetched. 70 // bits have been fetched.
75 FaviconService::Handle FaviconService::GetFaviconForID( 71 FaviconService::Handle FaviconService::GetFaviconForID(
76 history::FaviconID favicon_id, 72 history::FaviconID favicon_id,
77 CancelableRequestConsumerBase* consumer, 73 CancelableRequestConsumerBase* consumer,
78 const FaviconDataCallback& callback) { 74 const FaviconDataCallback& callback) {
79 GetFaviconRequest* request = new GetFaviconRequest(callback); 75 GetFaviconRequest* request = new GetFaviconRequest(callback);
80 AddRequest(request, consumer); 76 AddRequest(request, consumer);
81 FaviconService::Handle handle = request->handle(); 77 FaviconService::Handle handle = request->handle();
82 HistoryService* hs = 78 if (history_service_)
83 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 79 history_service_->GetFaviconForID(request, favicon_id);
84 if (hs)
85 hs->GetFaviconForID(request, favicon_id);
86 else 80 else
87 ForwardEmptyResultAsync(request); 81 ForwardEmptyResultAsync(request);
88 82
89 return handle; 83 return handle;
90 } 84 }
91 85
92 86
93 void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) { 87 void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) {
94 HistoryService* hs = 88 if (history_service_)
95 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 89 history_service_->SetFaviconOutOfDateForPage(page_url);
96 if (hs)
97 hs->SetFaviconOutOfDateForPage(page_url);
98 } 90 }
99 91
100 void FaviconService::CloneFavicon(const GURL& old_page_url, 92 void FaviconService::CloneFavicon(const GURL& old_page_url,
101 const GURL& new_page_url) { 93 const GURL& new_page_url) {
102 HistoryService* hs = 94 if (history_service_)
103 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 95 history_service_->CloneFavicon(old_page_url, new_page_url);
104 if (hs)
105 hs->CloneFavicon(old_page_url, new_page_url);
106 } 96 }
107 97
108 void FaviconService::SetImportedFavicons( 98 void FaviconService::SetImportedFavicons(
109 const std::vector<history::ImportedFaviconUsage>& favicon_usage) { 99 const std::vector<history::ImportedFaviconUsage>& favicon_usage) {
110 HistoryService* hs = 100 if (history_service_)
111 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 101 history_service_->SetImportedFavicons(favicon_usage);
112 if (hs)
113 hs->SetImportedFavicons(favicon_usage);
114 } 102 }
115 103
116 void FaviconService::SetFavicon(const GURL& page_url, 104 void FaviconService::SetFavicon(const GURL& page_url,
117 const GURL& icon_url, 105 const GURL& icon_url,
118 const std::vector<unsigned char>& image_data, 106 const std::vector<unsigned char>& image_data,
119 history::IconType icon_type) { 107 history::IconType icon_type) {
120 HistoryService* hs = 108 if (history_service_)
121 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 109 history_service_->SetFavicon(page_url, icon_url, image_data, icon_type);
122 if (hs)
123 hs->SetFavicon(page_url, icon_url, image_data, icon_type);
124 } 110 }
125 111
126 FaviconService::~FaviconService() { 112 FaviconService::~FaviconService() {
127 } 113 }
128 114
115 void FaviconService::Shutdown() {
116 profile_ = NULL;
117 }
118
129 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { 119 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) {
130 request->ForwardResultAsync(request->handle(), history::FaviconData()); 120 request->ForwardResultAsync(request->handle(), history::FaviconData());
131 } 121 }
OLDNEW
« no previous file with comments | « chrome/browser/favicon/favicon_service.h ('k') | chrome/browser/favicon/favicon_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698