1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromecast/common/cast_resource_delegate.h"
7 #include "base/files/file_path.h"
8 #include "base/path_service.h"
9 #include "ui/gfx/image/image.h"
11 namespace chromecast
{
15 CastResourceDelegate
* g_instance
= NULL
;
20 CastResourceDelegate
* CastResourceDelegate::GetInstance() {
25 CastResourceDelegate::CastResourceDelegate() {
26 DCHECK(!g_instance
) << "Cannot initialize resource bundle delegate twice.";
30 CastResourceDelegate::~CastResourceDelegate() {
31 DCHECK_EQ(g_instance
, this);
35 base::FilePath
CastResourceDelegate::GetPathForResourcePack(
36 const base::FilePath
& pack_path
,
37 ui::ScaleFactor scale_factor
) {
41 base::FilePath
CastResourceDelegate::GetPathForLocalePack(
42 const base::FilePath
& pack_path
,
43 const std::string
& locale
) {
44 base::FilePath product_dir
;
45 if (!PathService::Get(base::DIR_MODULE
, &product_dir
)) {
49 Append(FILE_PATH_LITERAL("chromecast_locales")).
50 Append(FILE_PATH_LITERAL(locale
)).
51 AddExtension(FILE_PATH_LITERAL("pak"));
54 gfx::Image
CastResourceDelegate::GetImageNamed(int resource_id
) {
58 gfx::Image
CastResourceDelegate::GetNativeImageNamed(
60 ui::ResourceBundle::ImageRTL rtl
) {
64 base::RefCountedStaticMemory
* CastResourceDelegate::LoadDataResourceBytes(
66 ui::ScaleFactor scale_factor
) {
70 bool CastResourceDelegate::GetRawDataResource(int resource_id
,
71 ui::ScaleFactor scale_factor
,
72 base::StringPiece
* value
) {
76 bool CastResourceDelegate::GetLocalizedString(int message_id
,
77 base::string16
* value
) {
78 ExtraLocaledStringMap::const_iterator it
=
79 extra_localized_strings_
.find(message_id
);
80 if (it
!= extra_localized_strings_
.end()) {
87 void CastResourceDelegate::AddExtraLocalizedString(
89 const base::string16
& localized
) {
90 RemoveExtraLocalizedString(resource_id
);
91 extra_localized_strings_
.insert(std::make_pair(resource_id
, localized
));
94 void CastResourceDelegate::RemoveExtraLocalizedString(int resource_id
) {
95 extra_localized_strings_
.erase(resource_id
);
98 void CastResourceDelegate::ClearAllExtraLocalizedStrings() {
99 extra_localized_strings_
.clear();
102 scoped_ptr
<gfx::Font
> CastResourceDelegate::GetFont(
103 ui::ResourceBundle::FontStyle style
) {
104 return scoped_ptr
<gfx::Font
>();
107 } // namespace chromecast