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

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

Issue 2839433002: [translate] Fix shutdown race for translate ranker model loader. (Closed)
Patch Set: fdoray part deux Created 3 years, 8 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_BROWSER_TRANSLATE_DOWNLOAD_MANAGER_H_ 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_DOWNLOAD_MANAGER_H_
6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_DOWNLOAD_MANAGER_H_ 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_DOWNLOAD_MANAGER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/sequence_checker.h"
12 #include "components/translate/core/browser/translate_language_list.h" 13 #include "components/translate/core/browser/translate_language_list.h"
13 #include "components/translate/core/browser/translate_script.h" 14 #include "components/translate/core/browser/translate_script.h"
14 #include "net/url_request/url_request_context_getter.h" 15 #include "net/url_request/url_request_context_getter.h"
15 16
16 namespace base { 17 namespace base {
17 template <typename T> struct DefaultSingletonTraits; 18 template <typename T> struct DefaultSingletonTraits;
18 } 19 }
19 20
20 class PrefService; 21 class PrefService;
21 22
22 namespace translate { 23 namespace translate {
23 24
24 // Manages the downloaded resources for Translate, such as the translate script 25 // Manages the downloaded resources for Translate, such as the translate script
25 // and the language list. 26 // and the language list.
26 class TranslateDownloadManager { 27 class TranslateDownloadManager {
27 public: 28 public:
28 // Returns the singleton instance. 29 // Returns the singleton instance.
29 static TranslateDownloadManager* GetInstance(); 30 static TranslateDownloadManager* GetInstance();
30 31
31 // The request context used to download the resources. 32 // The request context used to download the resources.
32 // Should be set before this class can be used. 33 // Should be set before this class can be used.
33 net::URLRequestContextGetter* request_context() { 34 net::URLRequestContextGetter* request_context() {
35 DCHECK(sequence_checker_.CalledOnValidSequence());
34 return request_context_.get(); 36 return request_context_.get();
35 } 37 }
36 void set_request_context(net::URLRequestContextGetter* context) { 38 void set_request_context(net::URLRequestContextGetter* context) {
37 request_context_ = context; 39 DCHECK(sequence_checker_.CalledOnValidSequence());
40 request_context_ = context;
38 } 41 }
39 42
40 // The application locale. 43 // The application locale.
41 // Should be set before this class can be used. 44 // Should be set before this class can be used.
42 const std::string& application_locale() { return application_locale_; } 45 const std::string& application_locale() {
46 DCHECK(sequence_checker_.CalledOnValidSequence());
47 return application_locale_;
48 }
43 void set_application_locale(const std::string& locale) { 49 void set_application_locale(const std::string& locale) {
50 DCHECK(sequence_checker_.CalledOnValidSequence());
44 application_locale_ = locale; 51 application_locale_ = locale;
45 } 52 }
46 53
47 // The language list. 54 // The language list.
48 TranslateLanguageList* language_list() { return language_list_.get(); } 55 TranslateLanguageList* language_list() {
56 DCHECK(sequence_checker_.CalledOnValidSequence());
57 return language_list_.get();
58 }
49 59
50 // The translate script. 60 // The translate script.
51 TranslateScript* script() { return script_.get(); } 61 TranslateScript* script() {
62 DCHECK(sequence_checker_.CalledOnValidSequence());
63 return script_.get();
64 }
52 65
53 // Let the caller decide if and when we should fetch the language list from 66 // Let the caller decide if and when we should fetch the language list from
54 // the translate server. This is a NOOP if prefs::kEnableTranslate is set to 67 // the translate server. This is a NOOP if prefs::kEnableTranslate is set to
55 // false. 68 // false.
56 static void RequestLanguageList(PrefService* prefs); 69 static void RequestLanguageList(PrefService* prefs);
57 70
58 // Fills |languages| with the list of languages that the translate server can 71 // Fills |languages| with the list of languages that the translate server can
59 // translate to and from. 72 // translate to and from.
60 static void GetSupportedLanguages(std::vector<std::string>* languages); 73 static void GetSupportedLanguages(std::vector<std::string>* languages);
61 74
(...skipping 21 matching lines...) Expand all
83 // Used by unit-tests to override some defaults: 96 // Used by unit-tests to override some defaults:
84 // Delay after which the translate script is fetched again from the 97 // Delay after which the translate script is fetched again from the
85 // translation server. 98 // translation server.
86 void SetTranslateScriptExpirationDelay(int delay_ms); 99 void SetTranslateScriptExpirationDelay(int delay_ms);
87 100
88 private: 101 private:
89 friend struct base::DefaultSingletonTraits<TranslateDownloadManager>; 102 friend struct base::DefaultSingletonTraits<TranslateDownloadManager>;
90 TranslateDownloadManager(); 103 TranslateDownloadManager();
91 virtual ~TranslateDownloadManager(); 104 virtual ~TranslateDownloadManager();
92 105
106 // Validates that accesses to the download manager are performed on the same
107 // sequence.
108 base::SequenceChecker sequence_checker_;
109
93 std::unique_ptr<TranslateLanguageList> language_list_; 110 std::unique_ptr<TranslateLanguageList> language_list_;
94 111
95 // An instance of TranslateScript which manages JavaScript source for 112 // An instance of TranslateScript which manages JavaScript source for
96 // Translate. 113 // Translate.
97 std::unique_ptr<TranslateScript> script_; 114 std::unique_ptr<TranslateScript> script_;
98 115
99 std::string application_locale_; 116 std::string application_locale_;
100 scoped_refptr<net::URLRequestContextGetter> request_context_; 117 scoped_refptr<net::URLRequestContextGetter> request_context_;
101 }; 118 };
102 119
103 } // namespace translate 120 } // namespace translate
104 121
105 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_DOWNLOAD_MANAGER_H_ 122 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_DOWNLOAD_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698