Chromium Code Reviews| Index: chrome/browser/translate/translate_script.h |
| diff --git a/chrome/browser/translate/translate_script.h b/chrome/browser/translate/translate_script.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..16dbcc1667f3b7e2256026e7c9f1a04a38bf6a48 |
| --- /dev/null |
| +++ b/chrome/browser/translate/translate_script.h |
| @@ -0,0 +1,66 @@ |
| +// 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_SCRIPT_H_ |
| +#define CHROME_BROWSER_TRANSLATE_TRANSLATE_SCRIPT_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/time.h" |
| + |
| +class TranslateURLFetcher; |
| + |
| +class TranslateScript { |
| + public: |
| + typedef base::Callback<void(bool, const std::string&)> Callback; |
| + |
| + TranslateScript(); |
| + virtual ~TranslateScript(); |
| + |
| + // Returns the feched the translate script. |
| + 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.
|
| + |
| + // Used by unit-tests to override some defaults: |
| + // Delay after which the translate script is fetched again from the |
| + // translation server. |
| + void set_expiration_delay(int delay_ms) { |
| + expiration_delay_ = base::TimeDelta::FromMilliseconds(delay_ms); |
| + } |
| + |
| + // Clears the translate script, so it will be fetched next time we translate. |
| + 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.
|
| + |
| + // Fetches the JS translate script (the script that is injected in the page |
| + // to translate it). |
| + void Request(const Callback& callback); |
| + |
| + // 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.
|
| + bool IsFetching() const; |
| + |
| + private: |
| + 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.
|
| + |
| + // The callback when the script is fetched or a server error occured. |
| + void OnScriptFetchComplete(int id, bool success, const std::string& data); |
| + |
| + base::WeakPtrFactory<TranslateScript> weak_method_factory_; |
| + |
| + // URL fetcher to fetch the translate script. |
| + scoped_ptr<TranslateURLFetcher> fetcher_; |
| + |
| + // The JS injected in the page to do the translation. |
| + std::string translate_script_; |
|
Takashi Toyoshima
2013/06/20 06:59:53
script_ or data_
hajimehoshi
2013/06/20 08:50:08
Done.
|
| + |
| + // Delay after which the translate script is fetched again from the translate |
| + // server. |
| + base::TimeDelta expiration_delay_; |
| + |
| + // The callback called when the server sends a response. |
| + Callback callback_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_SCRIPT_H_ |