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 "components/translate/core/browser/translate_download_manager.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/memory/singleton.h"
10 #include "base/prefs/pref_service.h"
11 #include "components/translate/core/common/translate_pref_names.h"
12 #include "components/translate/core/common/translate_switches.h"
17 TranslateDownloadManager
* TranslateDownloadManager::GetInstance() {
18 return Singleton
<TranslateDownloadManager
>::get();
21 TranslateDownloadManager::TranslateDownloadManager()
22 : language_list_(new TranslateLanguageList
),
23 script_(new TranslateScript
) {}
25 TranslateDownloadManager::~TranslateDownloadManager() {}
27 void TranslateDownloadManager::Shutdown() {
28 language_list_
.reset();
30 request_context_
= NULL
;
34 void TranslateDownloadManager::RequestLanguageList() {
35 TranslateLanguageList
* language_list
= GetInstance()->language_list();
41 language_list
->RequestLanguageList();
45 void TranslateDownloadManager::RequestLanguageList(PrefService
* prefs
) {
46 // We don't want to do this when translate is disabled.
47 DCHECK(prefs
!= NULL
);
48 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
49 translate::switches::kDisableTranslate
) ||
50 !prefs
->GetBoolean(prefs::kEnableTranslate
)) {
54 RequestLanguageList();
58 void TranslateDownloadManager::GetSupportedLanguages(
59 std::vector
<std::string
>* languages
) {
60 TranslateLanguageList
* language_list
= GetInstance()->language_list();
66 language_list
->GetSupportedLanguages(languages
);
70 base::Time
TranslateDownloadManager::GetSupportedLanguagesLastUpdated() {
71 TranslateLanguageList
* language_list
= GetInstance()->language_list();
77 return language_list
->last_updated();
81 std::string
TranslateDownloadManager::GetLanguageCode(
82 const std::string
& language
) {
83 TranslateLanguageList
* language_list
= GetInstance()->language_list();
89 return language_list
->GetLanguageCode(language
);
93 bool TranslateDownloadManager::IsSupportedLanguage(
94 const std::string
& language
) {
95 TranslateLanguageList
* language_list
= GetInstance()->language_list();
101 return language_list
->IsSupportedLanguage(language
);
105 bool TranslateDownloadManager::IsAlphaLanguage(const std::string
& language
) {
106 TranslateLanguageList
* language_list
= GetInstance()->language_list();
107 if (!language_list
) {
112 return language_list
->IsAlphaLanguage(language
);
115 void TranslateDownloadManager::ClearTranslateScriptForTesting() {
116 if (script_
.get() == NULL
) {
123 void TranslateDownloadManager::ResetForTesting() {
124 language_list_
.reset(new TranslateLanguageList
);
125 script_
.reset(new TranslateScript
);
128 void TranslateDownloadManager::SetTranslateScriptExpirationDelay(int delay_ms
) {
129 if (script_
.get() == NULL
) {
133 script_
->set_expiration_delay(delay_ms
);
136 } // namespace translate