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

Side by Side Diff: ui/base/resource/resource_bundle.cc

Issue 100303003: Move more uses of string16 to specify base:: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
« no previous file with comments | « ui/base/resource/resource_bundle.h ('k') | ui/base/text/bytes_formatting.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/base/resource/resource_bundle.h" 5 #include "ui/base/resource/resource_bundle.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 for (size_t i = 0; i < data_packs_.size(); i++) { 435 for (size_t i = 0; i < data_packs_.size(); i++) {
436 if ((data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_100P || 436 if ((data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_100P ||
437 data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE) && 437 data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE) &&
438 data_packs_[i]->GetStringPiece(resource_id, &data)) 438 data_packs_[i]->GetStringPiece(resource_id, &data))
439 return data; 439 return data;
440 } 440 }
441 441
442 return base::StringPiece(); 442 return base::StringPiece();
443 } 443 }
444 444
445 string16 ResourceBundle::GetLocalizedString(int message_id) { 445 base::string16 ResourceBundle::GetLocalizedString(int message_id) {
446 string16 string; 446 base::string16 string;
447 if (delegate_ && delegate_->GetLocalizedString(message_id, &string)) 447 if (delegate_ && delegate_->GetLocalizedString(message_id, &string))
448 return string; 448 return string;
449 449
450 // Ensure that ReloadLocaleResources() doesn't drop the resources while 450 // Ensure that ReloadLocaleResources() doesn't drop the resources while
451 // we're using them. 451 // we're using them.
452 base::AutoLock lock_scope(*locale_resources_data_lock_); 452 base::AutoLock lock_scope(*locale_resources_data_lock_);
453 453
454 // If for some reason we were unable to load the resources , return an empty 454 // If for some reason we were unable to load the resources , return an empty
455 // string (better than crashing). 455 // string (better than crashing).
456 if (!locale_resources_data_.get()) { 456 if (!locale_resources_data_.get()) {
457 LOG(WARNING) << "locale resources are not loaded"; 457 LOG(WARNING) << "locale resources are not loaded";
458 return string16(); 458 return base::string16();
459 } 459 }
460 460
461 base::StringPiece data; 461 base::StringPiece data;
462 if (!locale_resources_data_->GetStringPiece(message_id, &data)) { 462 if (!locale_resources_data_->GetStringPiece(message_id, &data)) {
463 // Fall back on the main data pack (shouldn't be any strings here except in 463 // Fall back on the main data pack (shouldn't be any strings here except in
464 // unittests). 464 // unittests).
465 data = GetRawDataResource(message_id); 465 data = GetRawDataResource(message_id);
466 if (data.empty()) { 466 if (data.empty()) {
467 NOTREACHED() << "unable to find resource: " << message_id; 467 NOTREACHED() << "unable to find resource: " << message_id;
468 return string16(); 468 return base::string16();
469 } 469 }
470 } 470 }
471 471
472 // Strings should not be loaded from a data pack that contains binary data. 472 // Strings should not be loaded from a data pack that contains binary data.
473 ResourceHandle::TextEncodingType encoding = 473 ResourceHandle::TextEncodingType encoding =
474 locale_resources_data_->GetTextEncodingType(); 474 locale_resources_data_->GetTextEncodingType();
475 DCHECK(encoding == ResourceHandle::UTF16 || encoding == ResourceHandle::UTF8) 475 DCHECK(encoding == ResourceHandle::UTF16 || encoding == ResourceHandle::UTF8)
476 << "requested localized string from binary pack file"; 476 << "requested localized string from binary pack file";
477 477
478 // Data pack encodes strings as either UTF8 or UTF16. 478 // Data pack encodes strings as either UTF8 or UTF16.
479 string16 msg; 479 base::string16 msg;
480 if (encoding == ResourceHandle::UTF16) { 480 if (encoding == ResourceHandle::UTF16) {
481 msg = string16(reinterpret_cast<const char16*>(data.data()), 481 msg = base::string16(reinterpret_cast<const base::char16*>(data.data()),
482 data.length() / 2); 482 data.length() / 2);
483 } else if (encoding == ResourceHandle::UTF8) { 483 } else if (encoding == ResourceHandle::UTF8) {
484 msg = UTF8ToUTF16(data); 484 msg = UTF8ToUTF16(data);
485 } 485 }
486 return msg; 486 return msg;
487 } 487 }
488 488
489 const gfx::FontList& ResourceBundle::GetFontList(FontStyle style) { 489 const gfx::FontList& ResourceBundle::GetFontList(FontStyle style) {
490 { 490 {
491 base::AutoLock lock_scope(*images_and_fonts_lock_); 491 base::AutoLock lock_scope(*images_and_fonts_lock_);
492 LoadFontsIfNecessary(); 492 LoadFontsIfNecessary();
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 // static 796 // static
797 bool ResourceBundle::DecodePNG(const unsigned char* buf, 797 bool ResourceBundle::DecodePNG(const unsigned char* buf,
798 size_t size, 798 size_t size,
799 SkBitmap* bitmap, 799 SkBitmap* bitmap,
800 bool* fell_back_to_1x) { 800 bool* fell_back_to_1x) {
801 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); 801 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size);
802 return gfx::PNGCodec::Decode(buf, size, bitmap); 802 return gfx::PNGCodec::Decode(buf, size, bitmap);
803 } 803 }
804 804
805 } // namespace ui 805 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/resource/resource_bundle.h ('k') | ui/base/text/bytes_formatting.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698