[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / components / translate / core / browser / translate_download_manager.cc
blobb953547f470356666804249bc876c5a46084a948
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"
14 namespace translate {
16 // static
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();
29 script_.reset();
30 request_context_ = NULL;
33 // static
34 void TranslateDownloadManager::RequestLanguageList() {
35 TranslateLanguageList* language_list = GetInstance()->language_list();
36 if (!language_list) {
37 NOTREACHED();
38 return;
41 language_list->RequestLanguageList();
44 // static
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)) {
51 return;
54 RequestLanguageList();
57 // static
58 void TranslateDownloadManager::GetSupportedLanguages(
59 std::vector<std::string>* languages) {
60 TranslateLanguageList* language_list = GetInstance()->language_list();
61 if (!language_list) {
62 NOTREACHED();
63 return;
66 language_list->GetSupportedLanguages(languages);
69 // static
70 base::Time TranslateDownloadManager::GetSupportedLanguagesLastUpdated() {
71 TranslateLanguageList* language_list = GetInstance()->language_list();
72 if (!language_list) {
73 NOTREACHED();
74 return base::Time();
77 return language_list->last_updated();
80 // static
81 std::string TranslateDownloadManager::GetLanguageCode(
82 const std::string& language) {
83 TranslateLanguageList* language_list = GetInstance()->language_list();
84 if (!language_list) {
85 NOTREACHED();
86 return language;
89 return language_list->GetLanguageCode(language);
92 // static
93 bool TranslateDownloadManager::IsSupportedLanguage(
94 const std::string& language) {
95 TranslateLanguageList* language_list = GetInstance()->language_list();
96 if (!language_list) {
97 NOTREACHED();
98 return false;
101 return language_list->IsSupportedLanguage(language);
104 // static
105 bool TranslateDownloadManager::IsAlphaLanguage(const std::string& language) {
106 TranslateLanguageList* language_list = GetInstance()->language_list();
107 if (!language_list) {
108 NOTREACHED();
109 return false;
112 return language_list->IsAlphaLanguage(language);
115 void TranslateDownloadManager::ClearTranslateScriptForTesting() {
116 if (script_.get() == NULL) {
117 NOTREACHED();
118 return;
120 script_->Clear();
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) {
130 NOTREACHED();
131 return;
133 script_->set_expiration_delay(delay_ms);
136 } // namespace translate