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

Side by Side Diff: chrome/browser/translate/translate_script.h

Issue 17390018: Refactoring: Create TranslateScript from TranslateManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactoring-translate-url-fetcher
Patch Set: Removed the nits Created 7 years, 6 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
(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& data() { return data_; }
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 Clear() { data_.clear(); }
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 has a pending request.
42 bool HasPendingRequest() const { return fetcher_.get() != NULL; }
43
44 private:
45 // The callback when the script is fetched or a server error occured.
46 void OnScriptFetchComplete(int id, bool success, const std::string& data);
47
48 base::WeakPtrFactory<TranslateScript> weak_method_factory_;
49
50 // URL fetcher to fetch the translate script.
51 scoped_ptr<TranslateURLFetcher> fetcher_;
52
53 // The JS injected in the page to do the translation.
54 std::string data_;
55
56 // Delay after which the translate script is fetched again from the translate
57 // server.
58 base::TimeDelta expiration_delay_;
59
60 // The callback called when the server sends a response.
61 Callback callback_;
62
63 DISALLOW_COPY_AND_ASSIGN(TranslateScript);
64 };
65
66 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_SCRIPT_H_
OLDNEW
« no previous file with comments | « chrome/browser/translate/translate_manager_browsertest.cc ('k') | chrome/browser/translate/translate_script.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698