Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_LANGUAGE_LIST_H_ | |
| 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_LANGUAGE_LIST_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "net/url_request/url_fetcher_delegate.h" | |
| 14 | |
| 15 namespace net { | |
| 16 class URLFetcher; | |
| 17 } | |
| 18 | |
| 19 // The TranslateLanguageList class is responsible for maintaining the latest | |
| 20 // supporting language list. | |
| 21 // This class is defined to be owned only by TranslateManager. | |
| 22 class TranslateLanguageList : public net::URLFetcherDelegate { | |
| 23 public: | |
| 24 TranslateLanguageList(); | |
| 25 virtual ~TranslateLanguageList(); | |
| 26 | |
| 27 // net::URLFetcherDelegate implementation: | |
| 28 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
| 29 | |
| 30 // Fills |languages| with the list of languages that the translate server can | |
| 31 // translate to and from. | |
| 32 void GetSupportedLanguages(std::vector<std::string>* languages); | |
| 33 | |
| 34 // Returns the language code that can be used with the Translate method for a | |
| 35 // specified |chrome_locale|. | |
| 36 std::string GetLanguageCode(const std::string& chrome_locale); | |
| 37 | |
| 38 // Returns true if |language| is supported by the translation server. | |
| 39 bool IsSupportedLanguage(const std::string& language); | |
| 40 | |
| 41 // TODO(toyoshim): Add IsSupportedAlphaLanguage() here. | |
| 42 | |
| 43 // Fetches the language list from the translate server. It will not retry | |
| 44 // more than kMaxRetryLanguageListFetch times. | |
| 45 void RequestLanguageList(); | |
| 46 | |
| 47 // static const values shared with our browser tests. | |
| 48 static const char kLanguageListCallbackName[]; | |
| 49 static const char kTargetLanguagesKey[]; | |
| 50 | |
| 51 private: | |
| 52 // Parses |language_list| and fills |supported_languages_| with the list of | |
| 53 // languages that the translate server can translate to and from. | |
| 54 void SetSupportedLanguages(const std::string& language_list); | |
| 55 | |
| 56 // The languages supported by the translation server. | |
| 57 std::set<std::string> supported_languages_; | |
| 58 | |
| 59 // URLFetcher runs in IO thread. This object should be destructed explicitly | |
| 60 // before killing IO thread because this class is singleton, and it may be | |
|
MAD
2013/05/27 21:34:35
Comment about singleton should be updated.
Takashi Toyoshima
2013/05/28 07:35:28
Done.
| |
| 61 // destructed at problematic timing. | |
| 62 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(TranslateLanguageList); | |
| 65 }; | |
| 66 | |
| 67 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_LANGUAGE_LIST_H_ | |
| OLD | NEW |