Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / translate / translate_service.h
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.
4
5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_SERVICE_H_
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_SERVICE_H_
7
8 #include "chrome/browser/web_resource/resource_request_allowed_notifier.h"
9
10 class GURL;
11 class PrefService;
12
13 // Singleton managing the resources required for Translate.
14 class TranslateService : public ResourceRequestAllowedNotifier::Observer {
15  public:
16    // Must be called before the Translate feature can be used.
17   static void Initialize();
18
19   // Must be called to shut down the Translate feature.
20   static void Shutdown(bool cleanup_pending_fetcher);
21
22   // Initializes the TranslateService in a way that it can be initialized
23   // multiple times in a unit test suite (once for each test). Should be paired
24   // with ShutdownForTesting at the end of the test.
25   static void InitializeForTesting();
26
27   // Shuts down the TranslateService at the end of a test in a way that the next
28   // test can initialize and use the service.
29   static void ShutdownForTesting();
30
31   // Let the caller decide if and when we should fetch the language list from
32   // the translate server. This is a NOOP if switches::kDisableTranslate is set
33   // or if prefs::kEnableTranslate is set to false.
34   static void FetchLanguageListFromTranslateServer(PrefService* prefs);
35
36   // Returns true if the new translate bubble is enabled.
37   static bool IsTranslateBubbleEnabled();
38
39   // Returns the language to translate to. The language returned is the
40   // first language found in the following list that is supported by the
41   // translation service:
42   //     the UI language
43   //     the accept-language list
44   // If no language is found then an empty string is returned.
45   static std::string GetTargetLanguage(PrefService* prefs);
46
47   // Returns true if the URL can be translated.
48   static bool IsTranslatableURL(const GURL& url);
49
50  private:
51   TranslateService();
52   ~TranslateService();
53
54   // ResourceRequestAllowedNotifier::Observer methods.
55   void OnResourceRequestsAllowed() override;
56
57   // Helper class to know if it's allowed to make network resource requests.
58   ResourceRequestAllowedNotifier resource_request_allowed_notifier_;
59 };
60
61 #endif  // CHROME_BROWSER_TRANSLATE_TRANSLATE_SERVICE_H_