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_SCRIPT_H_ | |
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_SCRIPT_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "base/time.h" | |
14 | |
15 class TranslateURLFetcher; | |
16 | |
17 class TranslateScript { | |
18 public: | |
19 typedef base::Callback<void(bool, const std::string&)> Callback; | |
20 | |
21 TranslateScript(); | |
22 virtual ~TranslateScript(); | |
23 | |
24 // Returns the feched the translate script. | |
25 const std::string& translate_script() { return translate_script_; } | |
Takashi Toyoshima
2013/06/20 06:59:53
just data(), script(), or something looks better.
hajimehoshi
2013/06/20 08:50:08
Done.
| |
26 | |
27 // Used by unit-tests to override some defaults: | |
28 // Delay after which the translate script is fetched again from the | |
29 // translation server. | |
30 void set_expiration_delay(int delay_ms) { | |
31 expiration_delay_ = base::TimeDelta::FromMilliseconds(delay_ms); | |
32 } | |
33 | |
34 // Clears the translate script, so it will be fetched next time we translate. | |
35 void ClearTranslateScript() { translate_script_.clear(); } | |
Takashi Toyoshima
2013/06/20 06:59:53
[optional] just Clear() looks fine for now.
hajimehoshi
2013/06/20 08:50:08
Done.
| |
36 | |
37 // Fetches the JS translate script (the script that is injected in the page | |
38 // to translate it). | |
39 void Request(const Callback& callback); | |
40 | |
41 // Returns true if this is now fetching the script. | |
Takashi Toyoshima
2013/06/20 06:59:53
HasPendingRequest() looks better because this func
hajimehoshi
2013/06/20 08:50:08
Done.
| |
42 bool IsFetching() const; | |
43 | |
44 private: | |
45 DISALLOW_COPY_AND_ASSIGN(TranslateScript); | |
Takashi Toyoshima
2013/06/20 06:59:53
from style rule,
"the DISALLOW_COPY_AND_ASSIGN mac
hajimehoshi
2013/06/20 08:50:08
Done.
| |
46 | |
47 // The callback when the script is fetched or a server error occured. | |
48 void OnScriptFetchComplete(int id, bool success, const std::string& data); | |
49 | |
50 base::WeakPtrFactory<TranslateScript> weak_method_factory_; | |
51 | |
52 // URL fetcher to fetch the translate script. | |
53 scoped_ptr<TranslateURLFetcher> fetcher_; | |
54 | |
55 // The JS injected in the page to do the translation. | |
56 std::string translate_script_; | |
Takashi Toyoshima
2013/06/20 06:59:53
script_ or data_
hajimehoshi
2013/06/20 08:50:08
Done.
| |
57 | |
58 // Delay after which the translate script is fetched again from the translate | |
59 // server. | |
60 base::TimeDelta expiration_delay_; | |
61 | |
62 // The callback called when the server sends a response. | |
63 Callback callback_; | |
64 }; | |
65 | |
66 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_SCRIPT_H_ | |
OLD | NEW |