resources_linux.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2015 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.
  4. #include "remoting/host/resources.h"
  5. #include <dlfcn.h>
  6. #include "base/check.h"
  7. #include "base/files/file_path.h"
  8. #include "base/path_service.h"
  9. #include "ui/base/resource/resource_bundle.h"
  10. #include "ui/base/ui_base_paths.h"
  11. namespace remoting {
  12. namespace {
  13. const char kLocaleResourcesDirName[] = "remoting_locales";
  14. } // namespace
  15. bool LoadResources(const std::string& pref_locale) {
  16. if (ui::ResourceBundle::HasSharedInstance()) {
  17. ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources(pref_locale);
  18. } else {
  19. // Retrieve the path to the module containing this function.
  20. Dl_info info;
  21. CHECK(dladdr(reinterpret_cast<void*>(&LoadResources), &info) != 0);
  22. // Point DIR_LOCALES to 'remoting_locales'.
  23. base::FilePath path = base::FilePath(info.dli_fname).DirName();
  24. base::PathService::Override(ui::DIR_LOCALES,
  25. path.AppendASCII(kLocaleResourcesDirName));
  26. ui::ResourceBundle::InitSharedInstanceWithLocale(
  27. pref_locale, NULL, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
  28. }
  29. return true;
  30. }
  31. void UnloadResources() {
  32. ui::ResourceBundle::CleanupSharedInstance();
  33. }
  34. } // namespace remoting