Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Unified Diff: chrome/browser/translate/translate_language_list.h

Issue 15317007: Translate: split supporting language list handling to TranslateLanguageList (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: plan b Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/translate/translate_language_list.h
diff --git a/chrome/browser/translate/translate_language_list.h b/chrome/browser/translate/translate_language_list.h
new file mode 100644
index 0000000000000000000000000000000000000000..d7a67320c6960e5c634b7a5a6982edce45b7d584
--- /dev/null
+++ b/chrome/browser/translate/translate_language_list.h
@@ -0,0 +1,67 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_LANGUAGE_LIST_H_
+#define CHROME_BROWSER_TRANSLATE_TRANSLATE_LANGUAGE_LIST_H_
+
+#include <set>
+#include <string>
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "net/url_request/url_fetcher_delegate.h"
+
+namespace net {
+class URLFetcher;
+}
+
+// The TranslateLanguageList class is responsible for maintaining the latest
+// supporting language list.
+// This class is defined to be owned only by TranslateManager.
+class TranslateLanguageList : public net::URLFetcherDelegate {
+ public:
+ TranslateLanguageList();
+ virtual ~TranslateLanguageList();
+
+ // net::URLFetcherDelegate implementation:
+ virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
+
+ // Fills |languages| with the list of languages that the translate server can
+ // translate to and from.
+ void GetSupportedLanguages(std::vector<std::string>* languages);
+
+ // Returns the language code that can be used with the Translate method for a
+ // specified |chrome_locale|.
+ std::string GetLanguageCode(const std::string& chrome_locale);
+
+ // Returns true if |language| is supported by the translation server.
+ bool IsSupportedLanguage(const std::string& language);
+
+ // TODO(toyoshim): Add IsSupportedAlphaLanguage() here.
+
+ // Fetches the language list from the translate server. It will not retry
+ // more than kMaxRetryLanguageListFetch times.
+ void RequestLanguageList();
+
+ // static const values shared with our browser tests.
+ static const char kLanguageListCallbackName[];
+ static const char kTargetLanguagesKey[];
+
+ private:
+ // Parses |language_list| and fills |supported_languages_| with the list of
+ // languages that the translate server can translate to and from.
+ void SetSupportedLanguages(const std::string& language_list);
+
+ // The languages supported by the translation server.
+ std::set<std::string> supported_languages_;
+
+ // URLFetcher runs in IO thread. This object should be destructed explicitly
+ // 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.
+ // destructed at problematic timing.
+ scoped_ptr<net::URLFetcher> url_fetcher_;
+
+ DISALLOW_COPY_AND_ASSIGN(TranslateLanguageList);
+};
+
+#endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_LANGUAGE_LIST_H_

Powered by Google App Engine
This is Rietveld 408576698