Move TranslateManager::IsTranslatableURL to be a client-level concept.
[chromium-blink-merge.git] / chrome / browser / translate / translate_service.h
blobc92e7cb337bf8b1d2ce9477e34d62757c89a7723
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 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_SERVICE_H_
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_SERVICE_H_
8 #include "chrome/browser/web_resource/resource_request_allowed_notifier.h"
10 class GURL;
11 class PrefService;
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();
19 // Must be called to shut down the Translate feature.
20 static void Shutdown(bool cleanup_pending_fetcher);
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();
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();
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);
36 // Returns true if the new translate bubble is enabled.
37 static bool IsTranslateBubbleEnabled();
39 // Sets whether of not the infobar UI is used. This method is intended to be
40 // used only for tests.
41 static void SetUseInfobar(bool value);
43 // Returns the language to translate to. The language returned is the
44 // first language found in the following list that is supported by the
45 // translation service:
46 // the UI language
47 // the accept-language list
48 // If no language is found then an empty string is returned.
49 static std::string GetTargetLanguage(PrefService* prefs);
51 // Returns true if the URL can be translated.
52 static bool IsTranslatableURL(const GURL& url);
54 private:
55 TranslateService();
56 ~TranslateService();
58 // ResourceRequestAllowedNotifier::Observer methods.
59 virtual void OnResourceRequestsAllowed() OVERRIDE;
61 // Helper class to know if it's allowed to make network resource requests.
62 ResourceRequestAllowedNotifier resource_request_allowed_notifier_;
64 // Whether or not the infobar is used. This is intended to be used
65 // only for testing.
66 bool use_infobar_;
69 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_SERVICE_H_