Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / translate / translate_language_list.h
blob4387a437a2ce6d4d46765f4c42077816daa7becb
1 // Copyright 2013 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_LANGUAGE_LIST_H_
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_LANGUAGE_LIST_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h"
14 #include "chrome/browser/web_resource/resource_request_allowed_notifier.h"
16 class TranslateURLFetcher;
18 // The TranslateLanguageList class is responsible for maintaining the latest
19 // supporting language list.
20 // This class is defined to be owned only by TranslateManager.
21 class TranslateLanguageList : public ResourceRequestAllowedNotifier::Observer {
22 public:
23 static const int kFetcherId = 1;
25 TranslateLanguageList();
26 virtual ~TranslateLanguageList();
28 // Returns the last-updated time when the language list is fetched from the
29 // Translate server. Returns null time if the list is yet to be fetched.
30 base::Time last_updated() { return last_updated_; }
32 // Fills |languages| with the list of languages that the translate server can
33 // translate to and from. |languages| will include alpha languages.
34 void GetSupportedLanguages(std::vector<std::string>* languages);
36 // Returns the language code that can be used with the Translate method for a
37 // specified |chrome_locale|.
38 std::string GetLanguageCode(const std::string& chrome_locale);
40 // Returns true if |language| is supported by the translation server. It also
41 // returns true against alpha languages.
42 bool IsSupportedLanguage(const std::string& language);
44 // Returns true if |language| is supported by the translation server as a
45 // alpha language.
46 bool IsAlphaLanguage(const std::string& language);
48 // Fetches the language list from the translate server. It will retry
49 // automatically when a server return 5xx errors and retry count doesn't
50 // reach to limits.
51 void RequestLanguageList();
53 // ResourceRequestAllowedNotifier::Observer implementation:
54 virtual void OnResourceRequestsAllowed() OVERRIDE;
56 // Disables the language list updater. This is used only for testing now.
57 static void DisableUpdate();
59 // static const values shared with our browser tests.
60 static const char kLanguageListCallbackName[];
61 static const char kTargetLanguagesKey[];
62 static const char kAlphaLanguagesKey[];
64 private:
65 // Callback function called when TranslateURLFetcher::Request() is finished.
66 void OnLanguageListFetchComplete(int id,
67 bool success,
68 const std::string& data);
70 // All the languages supported by the translation server.
71 std::set<std::string> all_supported_languages_;
73 // Alpha languages supported by the translation server.
74 std::set<std::string> alpha_languages_;
76 // A LanguageListFetcher instance to fetch a server providing supported
77 // language list including alpha languages.
78 scoped_ptr<TranslateURLFetcher> language_list_fetcher_;
80 // The last-updated time when the language list is sent.
81 base::Time last_updated_;
83 // Helper class to know if it's allowed to make network resource requests.
84 ResourceRequestAllowedNotifier resource_request_allowed_notifier_;
86 DISALLOW_COPY_AND_ASSIGN(TranslateLanguageList);
89 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_LANGUAGE_LIST_H_