15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chromecast/common/cast_resource_delegate.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/files/file_path.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/path_service.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/image/image.h"
10
11namespace chromecast {
12
13namespace {
14
15CastResourceDelegate* g_instance = NULL;
16
17}  // namespace
18
19// static
20CastResourceDelegate* CastResourceDelegate::GetInstance() {
21  DCHECK(g_instance);
22  return g_instance;
23}
24
25CastResourceDelegate::CastResourceDelegate() {
26  DCHECK(!g_instance) << "Cannot initialize resource bundle delegate twice.";
27  g_instance = this;
28}
29
30CastResourceDelegate::~CastResourceDelegate() {
31  DCHECK_EQ(g_instance, this);
32  g_instance = NULL;
33}
34
35base::FilePath CastResourceDelegate::GetPathForResourcePack(
36    const base::FilePath& pack_path,
37    ui::ScaleFactor scale_factor) {
38  return pack_path;
39};
40
41base::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)) {
46    NOTREACHED();
47  }
48  return product_dir.
49      Append(FILE_PATH_LITERAL("chromecast_locales")).
50      Append(FILE_PATH_LITERAL(locale)).
51      AddExtension(FILE_PATH_LITERAL("pak"));
52};
53
54gfx::Image CastResourceDelegate::GetImageNamed(int resource_id) {
55  return gfx::Image();
56};
57
58gfx::Image CastResourceDelegate::GetNativeImageNamed(
59    int resource_id,
60    ui::ResourceBundle::ImageRTL rtl) {
61  return gfx::Image();
62};
63
64base::RefCountedStaticMemory* CastResourceDelegate::LoadDataResourceBytes(
65    int resource_id,
66    ui::ScaleFactor scale_factor) {
67  return NULL;
68};
69
70bool CastResourceDelegate::GetRawDataResource(int resource_id,
71                                              ui::ScaleFactor scale_factor,
72                                              base::StringPiece* value) {
73  return false;
74};
75
76bool 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()) {
81    *value = it->second;
82    return true;
83  }
84  return false;
85};
86
87void CastResourceDelegate::AddExtraLocalizedString(
88    int resource_id,
89    const base::string16& localized) {
90  RemoveExtraLocalizedString(resource_id);
91  extra_localized_strings_.insert(std::make_pair(resource_id, localized));
92}
93
94void CastResourceDelegate::RemoveExtraLocalizedString(int resource_id) {
95  extra_localized_strings_.erase(resource_id);
96}
97
98void CastResourceDelegate::ClearAllExtraLocalizedStrings() {
99  extra_localized_strings_.clear();
100}
101
102scoped_ptr<gfx::Font> CastResourceDelegate::GetFont(
103    ui::ResourceBundle::FontStyle style) {
104  return scoped_ptr<gfx::Font>();
105};
106
107}  // namespace chromecast
108