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

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

Issue 7397021: Re-land r93365 - add RefCountedString (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ntp_resource_cache.h" 5 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // Watch for pref changes that cause us to need to invalidate the HTML cache. 165 // Watch for pref changes that cause us to need to invalidate the HTML cache.
166 pref_change_registrar_.Init(profile_->GetPrefs()); 166 pref_change_registrar_.Init(profile_->GetPrefs());
167 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); 167 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this);
168 pref_change_registrar_.Add(prefs::kEnableBookmarkBar, this); 168 pref_change_registrar_.Add(prefs::kEnableBookmarkBar, this);
169 pref_change_registrar_.Add(prefs::kNTPShownSections, this); 169 pref_change_registrar_.Add(prefs::kNTPShownSections, this);
170 pref_change_registrar_.Add(prefs::kNTPShownPage, this); 170 pref_change_registrar_.Add(prefs::kNTPShownPage, this);
171 } 171 }
172 172
173 NTPResourceCache::~NTPResourceCache() {} 173 NTPResourceCache::~NTPResourceCache() {}
174 174
175 RefCountedBytes* NTPResourceCache::GetNewTabHTML(bool is_incognito) { 175 RefCountedMemory* NTPResourceCache::GetNewTabHTML(bool is_incognito) {
176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
177 if (is_incognito) { 177 if (is_incognito) {
178 if (!new_tab_incognito_html_.get()) 178 if (!new_tab_incognito_html_.get())
179 CreateNewTabIncognitoHTML(); 179 CreateNewTabIncognitoHTML();
180 } else { 180 } else {
181 if (!new_tab_html_.get()) 181 if (!new_tab_html_.get())
182 CreateNewTabHTML(); 182 CreateNewTabHTML();
183 } 183 }
184 return is_incognito ? new_tab_incognito_html_.get() 184 return is_incognito ? new_tab_incognito_html_.get()
185 : new_tab_html_.get(); 185 : new_tab_html_.get();
186 } 186 }
187 187
188 RefCountedBytes* NTPResourceCache::GetNewTabCSS(bool is_incognito) { 188 RefCountedMemory* NTPResourceCache::GetNewTabCSS(bool is_incognito) {
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
190 if (is_incognito) { 190 if (is_incognito) {
191 if (!new_tab_incognito_css_.get()) 191 if (!new_tab_incognito_css_.get())
192 CreateNewTabIncognitoCSS(); 192 CreateNewTabIncognitoCSS();
193 } else { 193 } else {
194 if (!new_tab_css_.get()) 194 if (!new_tab_css_.get())
195 CreateNewTabCSS(); 195 CreateNewTabCSS();
196 } 196 }
197 return is_incognito ? new_tab_incognito_css_.get() 197 return is_incognito ? new_tab_incognito_css_.get()
198 : new_tab_css_.get(); 198 : new_tab_css_.get();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 253
254 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings); 254 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings);
255 255
256 static const base::StringPiece incognito_tab_html( 256 static const base::StringPiece incognito_tab_html(
257 ResourceBundle::GetSharedInstance().GetRawDataResource( 257 ResourceBundle::GetSharedInstance().GetRawDataResource(
258 new_tab_html_idr)); 258 new_tab_html_idr));
259 259
260 std::string full_html = jstemplate_builder::GetI18nTemplateHtml( 260 std::string full_html = jstemplate_builder::GetI18nTemplateHtml(
261 incognito_tab_html, &localized_strings); 261 incognito_tab_html, &localized_strings);
262 262
263 new_tab_incognito_html_ = new RefCountedBytes; 263 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html);
264 new_tab_incognito_html_->data.resize(full_html.size());
265 std::copy(full_html.begin(), full_html.end(),
266 new_tab_incognito_html_->data.begin());
267 } 264 }
268 265
269 void NTPResourceCache::CreateNewTabHTML() { 266 void NTPResourceCache::CreateNewTabHTML() {
270 // TODO(estade): these strings should be defined in their relevant handlers 267 // TODO(estade): these strings should be defined in their relevant handlers
271 // (in GetLocalizedValues) and should have more legible names. 268 // (in GetLocalizedValues) and should have more legible names.
272 // Show the profile name in the title and most visited labels if the current 269 // Show the profile name in the title and most visited labels if the current
273 // profile is not the default. 270 // profile is not the default.
274 string16 apps = l10n_util::GetStringUTF16(IDS_NEW_TAB_APPS); 271 string16 apps = l10n_util::GetStringUTF16(IDS_NEW_TAB_APPS);
275 string16 title = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); 272 string16 title = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE);
276 string16 most_visited = l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED); 273 string16 most_visited = l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 full_html.append(json_html); 430 full_html.append(json_html);
434 size_t after_offset = pos + template_data_placeholder.size(); 431 size_t after_offset = pos + template_data_placeholder.size();
435 full_html.append(new_tab_html.data() + after_offset, 432 full_html.append(new_tab_html.data() + after_offset,
436 new_tab_html.size() - after_offset); 433 new_tab_html.size() - after_offset);
437 } else { 434 } else {
438 NOTREACHED(); 435 NOTREACHED();
439 full_html.assign(new_tab_html.data(), new_tab_html.size()); 436 full_html.assign(new_tab_html.data(), new_tab_html.size());
440 } 437 }
441 } 438 }
442 439
443 new_tab_html_ = new RefCountedBytes; 440 new_tab_html_ = base::RefCountedString::TakeString(&full_html);
444 new_tab_html_->data.resize(full_html.size());
445 std::copy(full_html.begin(), full_html.end(), new_tab_html_->data.begin());
446 } 441 }
447 442
448 void NTPResourceCache::CreateNewTabIncognitoCSS() { 443 void NTPResourceCache::CreateNewTabIncognitoCSS() {
449 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); 444 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
450 DCHECK(tp); 445 DCHECK(tp);
451 446
452 // Get our theme colors 447 // Get our theme colors
453 SkColor color_background = 448 SkColor color_background =
454 tp->GetColor(ThemeService::COLOR_NTP_BACKGROUND); 449 tp->GetColor(ThemeService::COLOR_NTP_BACKGROUND);
455 450
(...skipping 12 matching lines...) Expand all
468 463
469 // Get our template. 464 // Get our template.
470 static const base::StringPiece new_tab_theme_css( 465 static const base::StringPiece new_tab_theme_css(
471 ResourceBundle::GetSharedInstance().GetRawDataResource( 466 ResourceBundle::GetSharedInstance().GetRawDataResource(
472 IDR_NEW_INCOGNITO_TAB_THEME_CSS)); 467 IDR_NEW_INCOGNITO_TAB_THEME_CSS));
473 468
474 // Create the string from our template and the replacements. 469 // Create the string from our template and the replacements.
475 std::string full_css = ReplaceStringPlaceholders( 470 std::string full_css = ReplaceStringPlaceholders(
476 new_tab_theme_css, subst, NULL); 471 new_tab_theme_css, subst, NULL);
477 472
478 new_tab_incognito_css_ = new RefCountedBytes; 473 new_tab_incognito_css_ = base::RefCountedString::TakeString(&full_css);
479 new_tab_incognito_css_->data.resize(full_css.size());
480 std::copy(full_css.begin(), full_css.end(),
481 new_tab_incognito_css_->data.begin());
482 } 474 }
483 475
484 void NTPResourceCache::CreateNewTabCSS() { 476 void NTPResourceCache::CreateNewTabCSS() {
485 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); 477 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
486 DCHECK(tp); 478 DCHECK(tp);
487 479
488 // Get our theme colors 480 // Get our theme colors
489 SkColor color_background = 481 SkColor color_background =
490 tp->GetColor(ThemeService::COLOR_NTP_BACKGROUND); 482 tp->GetColor(ThemeService::COLOR_NTP_BACKGROUND);
491 SkColor color_text = tp->GetColor(ThemeService::COLOR_NTP_TEXT); 483 SkColor color_text = tp->GetColor(ThemeService::COLOR_NTP_TEXT);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 int ntp_css_resource_id = 558 int ntp_css_resource_id =
567 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4) ? 559 CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4) ?
568 IDR_NEW_TAB_4_THEME_CSS : IDR_NEW_TAB_THEME_CSS; 560 IDR_NEW_TAB_4_THEME_CSS : IDR_NEW_TAB_THEME_CSS;
569 static const base::StringPiece new_tab_theme_css( 561 static const base::StringPiece new_tab_theme_css(
570 ResourceBundle::GetSharedInstance().GetRawDataResource( 562 ResourceBundle::GetSharedInstance().GetRawDataResource(
571 ntp_css_resource_id)); 563 ntp_css_resource_id));
572 564
573 // Create the string from our template and the replacements. 565 // Create the string from our template and the replacements.
574 std::string css_string; 566 std::string css_string;
575 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); 567 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL);
576 new_tab_css_ = new RefCountedBytes; 568 new_tab_css_ = base::RefCountedString::TakeString(&css_string);
577 new_tab_css_->data.resize(css_string.size());
578 std::copy(css_string.begin(), css_string.end(),
579 new_tab_css_->data.begin());
580 } 569 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_resource_cache.h ('k') | chrome/browser/ui/webui/options/options_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698