This source file includes following definitions.
- GetInstance
- script_
- Shutdown
- RequestLanguageList
- RequestLanguageList
- GetSupportedLanguages
- GetSupportedLanguagesLastUpdated
- GetLanguageCode
- IsSupportedLanguage
- IsAlphaLanguage
- ClearTranslateScriptForTesting
- ResetForTesting
- SetTranslateScriptExpirationDelay
#include "components/translate/core/browser/translate_download_manager.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/prefs/pref_service.h"
#include "components/translate/core/common/translate_pref_names.h"
#include "components/translate/core/common/translate_switches.h"
TranslateDownloadManager* TranslateDownloadManager::GetInstance() {
return Singleton<TranslateDownloadManager>::get();
}
TranslateDownloadManager::TranslateDownloadManager()
: language_list_(new TranslateLanguageList),
script_(new TranslateScript) {}
TranslateDownloadManager::~TranslateDownloadManager() {}
void TranslateDownloadManager::Shutdown() {
language_list_.reset();
script_.reset();
request_context_ = NULL;
}
void TranslateDownloadManager::RequestLanguageList() {
TranslateLanguageList* language_list = GetInstance()->language_list();
if (!language_list) {
NOTREACHED();
return;
}
language_list->RequestLanguageList();
}
void TranslateDownloadManager::RequestLanguageList(PrefService* prefs) {
DCHECK(prefs != NULL);
if (CommandLine::ForCurrentProcess()->HasSwitch(
translate::switches::kDisableTranslate) ||
!prefs->GetBoolean(prefs::kEnableTranslate)) {
return;
}
RequestLanguageList();
}
void TranslateDownloadManager::GetSupportedLanguages(
std::vector<std::string>* languages) {
TranslateLanguageList* language_list = GetInstance()->language_list();
if (!language_list) {
NOTREACHED();
return;
}
language_list->GetSupportedLanguages(languages);
}
base::Time TranslateDownloadManager::GetSupportedLanguagesLastUpdated() {
TranslateLanguageList* language_list = GetInstance()->language_list();
if (!language_list) {
NOTREACHED();
return base::Time();
}
return language_list->last_updated();
}
std::string TranslateDownloadManager::GetLanguageCode(
const std::string& language) {
TranslateLanguageList* language_list = GetInstance()->language_list();
if (!language_list) {
NOTREACHED();
return language;
}
return language_list->GetLanguageCode(language);
}
bool TranslateDownloadManager::IsSupportedLanguage(
const std::string& language) {
TranslateLanguageList* language_list = GetInstance()->language_list();
if (!language_list) {
NOTREACHED();
return false;
}
return language_list->IsSupportedLanguage(language);
}
bool TranslateDownloadManager::IsAlphaLanguage(const std::string& language) {
TranslateLanguageList* language_list = GetInstance()->language_list();
if (!language_list) {
NOTREACHED();
return false;
}
return language_list->IsAlphaLanguage(language);
}
void TranslateDownloadManager::ClearTranslateScriptForTesting() {
if (script_.get() == NULL) {
NOTREACHED();
return;
}
script_->Clear();
}
void TranslateDownloadManager::ResetForTesting() {
language_list_.reset(new TranslateLanguageList);
script_.reset(new TranslateScript);
}
void TranslateDownloadManager::SetTranslateScriptExpirationDelay(int delay_ms) {
if (script_.get() == NULL) {
NOTREACHED();
return;
}
script_->set_expiration_delay(delay_ms);
}