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

Unified Diff: chrome/browser/translate/translate_infobar_delegate.h

Issue 10952016: Simplify the translate infobar code some. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/translate/translate_infobar_delegate.h
===================================================================
--- chrome/browser/translate/translate_infobar_delegate.h (revision 157463)
+++ chrome/browser/translate/translate_infobar_delegate.h (working copy)
@@ -10,13 +10,14 @@
#include <vector>
#include "base/compiler_specific.h"
+#include "base/logging.h"
#include "chrome/browser/api/infobars/infobar_delegate.h"
#include "chrome/browser/translate/translate_prefs.h"
+#include "chrome/common/chrome_constants.h"
#include "chrome/common/translate_errors.h"
class InfoBarTabHelper;
class PrefService;
-class TranslateInfoBarView;
class TranslateInfoBarDelegate : public InfoBarDelegate {
public:
@@ -61,30 +62,45 @@
virtual ~TranslateInfoBarDelegate();
// Returns the number of languages supported.
- size_t GetLanguageCount() const { return languages_.size(); }
+ size_t num_languages() const { return languages_.size(); }
// Returns the ISO code for the language at |index|.
- std::string GetLanguageCodeAt(size_t index) const;
+ std::string language_code_at(size_t index) const {
+ DCHECK_LT(index, num_languages());
+ return languages_[index].first;
+ }
// Returns the displayable name for the language at |index|.
- string16 GetLanguageDisplayableNameAt(size_t index) const;
+ string16 language_name_at(size_t index) const {
+ DCHECK_LT(index, num_languages());
+ return languages_[index].second;
+ }
Type type() const { return type_; }
TranslateErrors::Type error() const { return error_; }
size_t original_language_index() const { return original_language_index_; }
+ void set_original_language_index(size_t language_index) {
+ DCHECK_LT(language_index, num_languages());
+ original_language_index_ = language_index;
+ }
size_t target_language_index() const { return target_language_index_; }
+ void set_target_language_index(size_t language_index) {
+ DCHECK_LT(language_index, num_languages());
+ target_language_index_ = language_index;
+ }
// Convenience methods.
- std::string GetOriginalLanguageCode() const;
- std::string GetTargetLanguageCode() const;
+ std::string original_language_code() const {
+ return (original_language_index() == kNoIndex) ?
+ chrome::kUnknownLanguageCode :
+ language_code_at(original_language_index());
+ }
+ std::string target_language_code() const {
+ return language_code_at(target_language_index());
+ }
- // Called by the InfoBar to notify that the original/target language has
- // changed and is now the language at |language_index|.
- virtual void SetOriginalLanguage(size_t language_index);
- virtual void SetTargetLanguage(size_t language_index);
-
// Returns true if the current infobar indicates an error (in which case it
// should get a yellow background instead of a blue one).
bool IsError() const { return type_ == TRANSLATION_ERROR; }
@@ -97,11 +113,11 @@
virtual void Translate();
virtual void RevertTranslation();
- virtual void ReportLanguageDetectionError();
+ void ReportLanguageDetectionError();
// Called when the user declines to translate a page, by either closing the
// infobar or pressing the "Don't translate" button.
- void TranslationDeclined();
+ virtual void TranslationDeclined();
// Methods called by the Options menu delegate.
virtual bool IsLanguageBlacklisted();
@@ -114,8 +130,8 @@
// Methods called by the extra-buttons that can appear on the "before
// translate" infobar (when the user has accepted/declined the translation
// several times).
- virtual void AlwaysTranslatePageLanguage();
- virtual void NeverTranslatePageLanguage();
+ void AlwaysTranslatePageLanguage();
+ void NeverTranslatePageLanguage();
// The following methods are called by the infobar that displays the status
// while translating and also the one displaying the error message.
@@ -201,9 +217,6 @@
// The error that occurred when trying to translate (NONE if no error).
TranslateErrors::Type error_;
- // The current infobar view.
- TranslateInfoBarView* infobar_view_;
-
// The translation related preferences.
TranslatePrefs prefs_;

Powered by Google App Engine
This is Rietveld 408576698