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

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

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 #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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return; 101 return;
102 102
103 GURL url(path); 103 GURL url(path);
104 // Intercept requests for prepopulated pages if TopSites exists. 104 // Intercept requests for prepopulated pages if TopSites exists.
105 scoped_refptr<history::TopSites> top_sites = 105 scoped_refptr<history::TopSites> top_sites =
106 TopSitesFactory::GetForProfile(Profile::FromWebUI(web_ui())); 106 TopSitesFactory::GetForProfile(Profile::FromWebUI(web_ui()));
107 if (top_sites) { 107 if (top_sites) {
108 for (const auto& prepopulated_page : top_sites->GetPrepopulatedPages()) { 108 for (const auto& prepopulated_page : top_sites->GetPrepopulatedPages()) {
109 if (url == prepopulated_page.most_visited.url) { 109 if (url == prepopulated_page.most_visited.url) {
110 base::StringValue dom_id_value(dom_id); 110 base::StringValue dom_id_value(dom_id);
111 scoped_ptr<base::StringValue> color( 111 std::unique_ptr<base::StringValue> color(
112 SkColorToCss(prepopulated_page.color)); 112 SkColorToCss(prepopulated_page.color));
113 web_ui()->CallJavascriptFunction("ntp.setFaviconDominantColor", 113 web_ui()->CallJavascriptFunction("ntp.setFaviconDominantColor",
114 dom_id_value, *color); 114 dom_id_value, *color);
115 return; 115 return;
116 } 116 }
117 } 117 }
118 } 118 }
119 119
120 dom_id_map_[id_] = dom_id; 120 dom_id_map_[id_] = dom_id;
121 favicon_service->GetRawFaviconForPageURL( 121 favicon_service->GetRawFaviconForPageURL(
122 url, 122 url,
123 favicon_base::FAVICON, 123 favicon_base::FAVICON,
124 gfx::kFaviconSize, 124 gfx::kFaviconSize,
125 base::Bind(&FaviconWebUIHandler::OnFaviconDataAvailable, 125 base::Bind(&FaviconWebUIHandler::OnFaviconDataAvailable,
126 base::Unretained(this), 126 base::Unretained(this),
127 id_++), 127 id_++),
128 &cancelable_task_tracker_); 128 &cancelable_task_tracker_);
129 } 129 }
130 130
131 void FaviconWebUIHandler::OnFaviconDataAvailable( 131 void FaviconWebUIHandler::OnFaviconDataAvailable(
132 int id, 132 int id,
133 const favicon_base::FaviconRawBitmapResult& bitmap_result) { 133 const favicon_base::FaviconRawBitmapResult& bitmap_result) {
134 scoped_ptr<base::StringValue> color_value; 134 std::unique_ptr<base::StringValue> color_value;
135 135
136 if (bitmap_result.is_valid()) 136 if (bitmap_result.is_valid())
137 color_value.reset(GetDominantColorCssString(bitmap_result.bitmap_data)); 137 color_value.reset(GetDominantColorCssString(bitmap_result.bitmap_data));
138 else 138 else
139 color_value.reset(new base::StringValue("#919191")); 139 color_value.reset(new base::StringValue("#919191"));
140 140
141 base::StringValue dom_id(dom_id_map_[id]); 141 base::StringValue dom_id(dom_id_map_[id]);
142 web_ui()->CallJavascriptFunction("ntp.setFaviconDominantColor", 142 web_ui()->CallJavascriptFunction("ntp.setFaviconDominantColor",
143 dom_id, *color_value); 143 dom_id, *color_value);
144 dom_id_map_.erase(id); 144 dom_id_map_.erase(id);
(...skipping 15 matching lines...) Expand all
160 } 160 }
161 161
162 void FaviconWebUIHandler::NotifyAppIconReady(const std::string& extension_id) { 162 void FaviconWebUIHandler::NotifyAppIconReady(const std::string& extension_id) {
163 const SkBitmap& bitmap = app_icon_color_manager_->GetIcon(extension_id); 163 const SkBitmap& bitmap = app_icon_color_manager_->GetIcon(extension_id);
164 // TODO(estade): would be nice to avoid a round trip through png encoding. 164 // TODO(estade): would be nice to avoid a round trip through png encoding.
165 std::vector<unsigned char> bits; 165 std::vector<unsigned char> bits;
166 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) 166 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits))
167 return; 167 return;
168 scoped_refptr<base::RefCountedStaticMemory> bits_mem( 168 scoped_refptr<base::RefCountedStaticMemory> bits_mem(
169 new base::RefCountedStaticMemory(&bits.front(), bits.size())); 169 new base::RefCountedStaticMemory(&bits.front(), bits.size()));
170 scoped_ptr<base::StringValue> color_value( 170 std::unique_ptr<base::StringValue> color_value(
171 GetDominantColorCssString(bits_mem)); 171 GetDominantColorCssString(bits_mem));
172 base::StringValue id(extension_id); 172 base::StringValue id(extension_id);
173 web_ui()->CallJavascriptFunction( 173 web_ui()->CallJavascriptFunction(
174 "ntp.setFaviconDominantColor", id, *color_value); 174 "ntp.setFaviconDominantColor", id, *color_value);
175 } 175 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/favicon_webui_handler.h ('k') | chrome/browser/ui/webui/ntp/new_tab_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698