NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / translate / translate_service.cc
blobdcff02729df35813a214db2d3c8a5c242baf8de7
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"
13 namespace {
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() {}
24 // static
25 void TranslateService::Initialize() {
26 if (g_translate_service)
27 return;
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());
42 // static
43 void TranslateService::Shutdown(bool cleanup_pending_fetcher) {
44 TranslateDownloadManager* download_manager =
45 TranslateDownloadManager::GetInstance();
46 if (cleanup_pending_fetcher) {
47 download_manager->Shutdown();
48 } else {
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();
57 if (!language_list) {
58 NOTREACHED();
59 return;
62 language_list->SetResourceRequestsAllowed(
63 resource_request_allowed_notifier_.ResourceRequestsAllowed());
66 // static
67 bool TranslateService::IsTranslateBubbleEnabled() {
68 #if defined(USE_AURA)
69 Initialize();
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);
75 #else
76 // The bubble UX is not implemented on the non-Aura platforms.
77 return false;
78 #endif
81 // static
82 void TranslateService::SetUseInfobar(bool value) {
83 Initialize();
84 g_translate_service->use_infobar_ = value;