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 "chrome/browser/translate/translate_service.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/translate/translate_manager.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "components/translate/core/browser/translate_download_manager.h"
14 // The singleton instance of TranslateService.
15 TranslateService
* g_translate_service
= NULL
;
18 TranslateService::TranslateService() : use_infobar_(false) {
19 resource_request_allowed_notifier_
.Init(this);
22 TranslateService::~TranslateService() {}
25 void TranslateService::Initialize() {
26 if (g_translate_service
)
29 g_translate_service
= new TranslateService
;
30 // Initialize the allowed state for resource requests.
31 g_translate_service
->OnResourceRequestsAllowed();
32 // Create the TranslateManager singleton.
33 TranslateManager::GetInstance();
34 TranslateDownloadManager
* download_manager
=
35 TranslateDownloadManager::GetInstance();
36 download_manager
->set_request_context(
37 g_browser_process
->system_request_context());
38 download_manager
->set_application_locale(
39 g_browser_process
->GetApplicationLocale());
43 void TranslateService::Shutdown(bool cleanup_pending_fetcher
) {
44 TranslateDownloadManager
* download_manager
=
45 TranslateDownloadManager::GetInstance();
46 if (cleanup_pending_fetcher
) {
47 download_manager
->Shutdown();
49 // This path is only used by tests.
50 download_manager
->set_request_context(NULL
);
54 void TranslateService::OnResourceRequestsAllowed() {
55 TranslateLanguageList
* language_list
=
56 TranslateDownloadManager::GetInstance()->language_list();
62 language_list
->SetResourceRequestsAllowed(
63 resource_request_allowed_notifier_
.ResourceRequestsAllowed());
67 bool TranslateService::IsTranslateBubbleEnabled() {
70 return !g_translate_service
->use_infobar_
;
71 #elif defined(OS_MACOSX)
72 // The bubble UX is experimental on Mac OS X.
73 return CommandLine::ForCurrentProcess()->HasSwitch(
74 switches::kEnableTranslateNewUX
);
76 // The bubble UX is not implemented on the non-Aura platforms.
82 void TranslateService::SetUseInfobar(bool value
) {
84 g_translate_service
->use_infobar_
= value
;