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

Side by Side Diff: components/translate/core/browser/translate_download_manager.h

Issue 143003020: Move TranslateLanguageList to the Translate component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@removeDelegate
Patch Set: gn build Created 6 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWER_TRANSLATE_DOWNLOAD_MANAGER_H_ 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWER_TRANSLATE_DOWNLOAD_MANAGER_H_
6 #define COMPONENTS_TRANSLATE_CORE_BROWER_TRANSLATE_DOWNLOAD_MANAGER_H_ 6 #define COMPONENTS_TRANSLATE_CORE_BROWER_TRANSLATE_DOWNLOAD_MANAGER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "components/translate/core/browser/translate_language_list.h"
12 #include "net/url_request/url_request_context_getter.h" 14 #include "net/url_request/url_request_context_getter.h"
13 15
14 template <typename T> struct DefaultSingletonTraits; 16 template <typename T> struct DefaultSingletonTraits;
15 17
18 class PrefService;
19
16 // Manages the downloaded resources for Translate, such as the translate script 20 // Manages the downloaded resources for Translate, such as the translate script
17 // and the language list. 21 // and the language list.
18 // TODO(droger): TranslateDownloadManager should own TranslateLanguageList and 22 // TODO(droger): TranslateDownloadManager should own TranslateScript.
19 // TranslateScript. See http://crbug.com/335074 and http://crbug.com/335077. 23 // See http://crbug.com/335074.
20 class TranslateDownloadManager { 24 class TranslateDownloadManager {
21 public: 25 public:
22 // Returns the singleton instance. 26 // Returns the singleton instance.
23 static TranslateDownloadManager* GetInstance(); 27 static TranslateDownloadManager* GetInstance();
24 28
25 // The request context used to download the resources. 29 // The request context used to download the resources.
26 // Should be set before this class can be used. 30 // Should be set before this class can be used.
27 net::URLRequestContextGetter* request_context() { return request_context_; } 31 net::URLRequestContextGetter* request_context() { return request_context_; }
28 void set_request_context(net::URLRequestContextGetter* context) { 32 void set_request_context(net::URLRequestContextGetter* context) {
29 request_context_ = context; 33 request_context_ = context;
30 } 34 }
31 35
32 // The application locale. 36 // The application locale.
33 // Should be set before this class can be used. 37 // Should be set before this class can be used.
34 const std::string& application_locale() { 38 const std::string& application_locale() {
35 DCHECK(!application_locale_.empty()); 39 DCHECK(!application_locale_.empty());
36 return application_locale_; 40 return application_locale_;
37 } 41 }
38 void set_application_locale(const std::string& locale) { 42 void set_application_locale(const std::string& locale) {
39 application_locale_ = locale; 43 application_locale_ = locale;
40 } 44 }
41 45
46 // The language list.
47 TranslateLanguageList* language_list() { return language_list_.get(); }
48
49 // Let the caller decide if and when we should fetch the language list from
50 // the translate server. This is a NOOP if switches::kDisableTranslate is set
51 // or if prefs::kEnableTranslate is set to false.
52 static void RequestLanguageList(PrefService* prefs);
53
54 // Fetches the language list from the translate server.
55 static void RequestLanguageList();
56
57 // Fills |languages| with the list of languages that the translate server can
58 // translate to and from.
59 static void GetSupportedLanguages(std::vector<std::string>* languages);
60
61 // Returns the last-updated time when Chrome receives a language list from a
MAD 2014/02/03 14:02:43 receives -> received?
62 // Translate server. Returns null time if Chrome hasn't received any lists.
63 static base::Time GetSupportedLanguagesLastUpdated();
64
65 // Returns the language code that can be used with the Translate method for a
66 // specified |chrome_locale|.
67 static std::string GetLanguageCode(const std::string& chrome_locale);
68
69 // Returns true if |language| is supported by the translation server.
70 static bool IsSupportedLanguage(const std::string& language);
71
72 // Returns true if |language| is supported by the translation server as a
73 // alpha language.
MAD 2014/02/03 14:02:43 a alpha -> an alpha?
74 static bool IsAlphaLanguage(const std::string& language);
75
76 // Must be called to shut Translate down. Cancels any pending fetches.
77 void Shutdown();
78
42 private: 79 private:
43 friend struct DefaultSingletonTraits<TranslateDownloadManager>; 80 friend struct DefaultSingletonTraits<TranslateDownloadManager>;
44 TranslateDownloadManager(); 81 TranslateDownloadManager();
45 virtual ~TranslateDownloadManager(); 82 virtual ~TranslateDownloadManager();
46 83
84 scoped_ptr<TranslateLanguageList> language_list_;
47 std::string application_locale_; 85 std::string application_locale_;
48 scoped_refptr<net::URLRequestContextGetter> request_context_; 86 scoped_refptr<net::URLRequestContextGetter> request_context_;
49 }; 87 };
50 88
51 #endif // COMPONENTS_TRANSLATE_CORE_BROWER_TRANSLATE_DOWNLOAD_MANAGER_H_ 89 #endif // COMPONENTS_TRANSLATE_CORE_BROWER_TRANSLATE_DOWNLOAD_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698