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

Side by Side Diff: chrome/browser/ui/webui/ntp/favicon_webui_handler.cc

Issue 10828263: Moving FaviconService to a ProfileKeyedService. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: 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/ui/webui/ntp/favicon_webui_handler.h" 5 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/string_split.h" 9 #include "base/string_split.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/history/top_sites.h" 13 #include "chrome/browser/history/top_sites.h"
14 #include "chrome/browser/extensions/extension_icon_manager.h" 14 #include "chrome/browser/extensions/extension_icon_manager.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/favicon/favicon_service_factory.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/extensions/extension_resource.h" 18 #include "chrome/common/extensions/extension_resource.h"
18 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
19 #include "content/public/browser/web_ui.h" 20 #include "content/public/browser/web_ui.h"
20 #include "grit/ui_resources.h" 21 #include "grit/ui_resources.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 22 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/gfx/codec/png_codec.h" 24 #include "ui/gfx/codec/png_codec.h"
24 #include "ui/gfx/color_analysis.h" 25 #include "ui/gfx/color_analysis.h"
25 26
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 void FaviconWebUIHandler::HandleGetFaviconDominantColor(const ListValue* args) { 82 void FaviconWebUIHandler::HandleGetFaviconDominantColor(const ListValue* args) {
82 std::string path; 83 std::string path;
83 CHECK(args->GetString(0, &path)); 84 CHECK(args->GetString(0, &path));
84 DCHECK(StartsWithASCII(path, "chrome://favicon/size/16/", false)) << 85 DCHECK(StartsWithASCII(path, "chrome://favicon/size/16/", false)) <<
85 "path is " << path; 86 "path is " << path;
86 path = path.substr(arraysize("chrome://favicon/size/16/") - 1); 87 path = path.substr(arraysize("chrome://favicon/size/16/") - 1);
87 88
88 std::string dom_id; 89 std::string dom_id;
89 CHECK(args->GetString(1, &dom_id)); 90 CHECK(args->GetString(1, &dom_id));
90 91
91 FaviconService* favicon_service = 92 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
92 Profile::FromWebUI(web_ui())->GetFaviconService(Profile::EXPLICIT_ACCESS); 93 Profile::FromWebUI(web_ui()), Profile::EXPLICIT_ACCESS);
93 if (!favicon_service || path.empty()) 94 if (!favicon_service || path.empty())
94 return; 95 return;
95 96
96 GURL url(path); 97 GURL url(path);
97 // Intercept requests for prepopulated pages. 98 // Intercept requests for prepopulated pages.
98 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) { 99 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) {
99 if (url.spec() == 100 if (url.spec() ==
100 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { 101 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) {
101 StringValue dom_id_value(dom_id); 102 StringValue dom_id_value(dom_id);
102 scoped_ptr<StringValue> color( 103 scoped_ptr<StringValue> color(
(...skipping 10 matching lines...) Expand all
113 history::FAVICON, 114 history::FAVICON,
114 &consumer_, 115 &consumer_,
115 base::Bind(&FaviconWebUIHandler::OnFaviconDataAvailable, 116 base::Bind(&FaviconWebUIHandler::OnFaviconDataAvailable,
116 base::Unretained(this))); 117 base::Unretained(this)));
117 consumer_.SetClientData(favicon_service, handle, id_++); 118 consumer_.SetClientData(favicon_service, handle, id_++);
118 } 119 }
119 120
120 void FaviconWebUIHandler::OnFaviconDataAvailable( 121 void FaviconWebUIHandler::OnFaviconDataAvailable(
121 FaviconService::Handle request_handle, 122 FaviconService::Handle request_handle,
122 history::FaviconData favicon) { 123 history::FaviconData favicon) {
123 FaviconService* favicon_service = 124 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
124 Profile::FromWebUI(web_ui())->GetFaviconService(Profile::EXPLICIT_ACCESS); 125 Profile::FromWebUI(web_ui()), Profile::EXPLICIT_ACCESS);
125 int id = consumer_.GetClientData(favicon_service, request_handle); 126 int id = consumer_.GetClientData(favicon_service, request_handle);
126 scoped_ptr<StringValue> color_value; 127 scoped_ptr<StringValue> color_value;
127 128
128 if (favicon.is_valid()) 129 if (favicon.is_valid())
129 color_value.reset(GetDominantColorCssString(favicon.image_data)); 130 color_value.reset(GetDominantColorCssString(favicon.image_data));
130 else 131 else
131 color_value.reset(new StringValue("#919191")); 132 color_value.reset(new StringValue("#919191"));
132 133
133 StringValue dom_id(dom_id_map_[id]); 134 StringValue dom_id(dom_id_map_[id]);
134 web_ui()->CallJavascriptFunction("ntp.setStripeColor", dom_id, *color_value); 135 web_ui()->CallJavascriptFunction("ntp.setStripeColor", dom_id, *color_value);
(...skipping 20 matching lines...) Expand all
155 std::vector<unsigned char> bits; 156 std::vector<unsigned char> bits;
156 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) 157 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits))
157 return; 158 return;
158 scoped_refptr<base::RefCountedStaticMemory> bits_mem( 159 scoped_refptr<base::RefCountedStaticMemory> bits_mem(
159 new base::RefCountedStaticMemory(&bits.front(), bits.size())); 160 new base::RefCountedStaticMemory(&bits.front(), bits.size()));
160 scoped_ptr<StringValue> color_value(GetDominantColorCssString(bits_mem)); 161 scoped_ptr<StringValue> color_value(GetDominantColorCssString(bits_mem));
161 StringValue id(extension_id); 162 StringValue id(extension_id);
162 web_ui()->CallJavascriptFunction( 163 web_ui()->CallJavascriptFunction(
163 "ntp.setStripeColor", id, *color_value); 164 "ntp.setStripeColor", id, *color_value);
164 } 165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698