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

Side by Side Diff: chrome/browser/dom_ui/dom_ui_favicon_source.cc

Issue 3061009: Speculative fix for crash in DOMUIThumbnailSource. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: msvc++ caught this Created 10 years, 5 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/dom_ui/dom_ui_favicon_source.h" 5 #include "chrome/browser/dom_ui/dom_ui_favicon_source.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "chrome/browser/chrome_thread.h"
9 #include "chrome/browser/profile.h" 10 #include "chrome/browser/profile.h"
10 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
11 #include "grit/app_resources.h" 12 #include "grit/app_resources.h"
12 13
13 DOMUIFavIconSource::DOMUIFavIconSource(Profile* profile) 14 DOMUIFavIconSource::DOMUIFavIconSource(Profile* profile)
14 : DataSource(chrome::kChromeUIFavIconHost, MessageLoop::current()), 15 : DataSource(chrome::kChromeUIFavIconHost, MessageLoop::current()),
15 profile_(profile) { 16 profile_(profile) {
16 } 17 }
17 18
19 DOMUIFavIconSource::~DOMUIFavIconSource() {
20 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
21 }
22
18 void DOMUIFavIconSource::StartDataRequest(const std::string& path, 23 void DOMUIFavIconSource::StartDataRequest(const std::string& path,
19 bool is_off_the_record, 24 bool is_off_the_record,
20 int request_id) { 25 int request_id) {
26 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
21 FaviconService* favicon_service = 27 FaviconService* favicon_service =
22 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); 28 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS);
23 if (favicon_service) { 29 if (favicon_service) {
24 FaviconService::Handle handle; 30 FaviconService::Handle handle;
25 if (path.size() > 8 && path.substr(0, 8) == "iconurl/") { 31 if (path.size() > 8 && path.substr(0, 8) == "iconurl/") {
26 handle = favicon_service->GetFavicon( 32 handle = favicon_service->GetFavicon(
27 GURL(path.substr(8)), 33 GURL(path.substr(8)),
28 &cancelable_consumer_, 34 &cancelable_consumer_,
29 NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable)); 35 NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable));
30 } else { 36 } else {
31 handle = favicon_service->GetFaviconForURL( 37 handle = favicon_service->GetFaviconForURL(
32 GURL(path), 38 GURL(path),
33 &cancelable_consumer_, 39 &cancelable_consumer_,
34 NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable)); 40 NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable));
35 } 41 }
36 // Attach the ChromeURLDataManager request ID to the history request. 42 // Attach the ChromeURLDataManager request ID to the history request.
37 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); 43 cancelable_consumer_.SetClientData(favicon_service, handle, request_id);
38 } else { 44 } else {
39 SendResponse(request_id, NULL); 45 SendResponse(request_id, NULL);
40 } 46 }
41 } 47 }
42 48
49 std::string DOMUIFavIconSource::GetMimeType(const std::string&) const {
50 // We need to explicitly return a mime type, otherwise if the user tries to
51 // drag the image they get no extension.
52 return "image/png";
53 }
54
43 void DOMUIFavIconSource::OnFavIconDataAvailable( 55 void DOMUIFavIconSource::OnFavIconDataAvailable(
44 FaviconService::Handle request_handle, 56 FaviconService::Handle request_handle,
45 bool know_favicon, 57 bool know_favicon,
46 scoped_refptr<RefCountedMemory> data, 58 scoped_refptr<RefCountedMemory> data,
47 bool expired, 59 bool expired,
48 GURL icon_url) { 60 GURL icon_url) {
61 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
49 FaviconService* favicon_service = 62 FaviconService* favicon_service =
50 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); 63 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS);
51 int request_id = cancelable_consumer_.GetClientData(favicon_service, 64 int request_id = cancelable_consumer_.GetClientData(favicon_service,
52 request_handle); 65 request_handle);
53 66
54 if (know_favicon && data.get() && data->size()) { 67 if (know_favicon && data.get() && data->size()) {
55 // Forward the data along to the networking system. 68 // Forward the data along to the networking system.
56 SendResponse(request_id, data); 69 SendResponse(request_id, data);
57 } else { 70 } else {
58 if (!default_favicon_.get()) { 71 if (!default_favicon_.get()) {
59 default_favicon_ = 72 default_favicon_ =
60 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( 73 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
61 IDR_DEFAULT_FAVICON); 74 IDR_DEFAULT_FAVICON);
62 } 75 }
63 76
64 SendResponse(request_id, default_favicon_); 77 SendResponse(request_id, default_favicon_);
65 } 78 }
66 } 79 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_favicon_source.h ('k') | chrome/browser/dom_ui/dom_ui_theme_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698