summaryrefslogtreecommitdiffstats
path: root/chrome/browser/translate
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-08 04:20:40 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-08 04:20:40 +0000
commitec8f51164d477d8d83726fe61c68977d17b03149 (patch)
treede1ea01984caab5a5841c8a7c1593805157ce60d /chrome/browser/translate
parentef47ded033e48098e83bb94e63b6e44ca6b511b4 (diff)
downloadchromium_src-ec8f51164d477d8d83726fe61c68977d17b03149.zip
chromium_src-ec8f51164d477d8d83726fe61c68977d17b03149.tar.gz
chromium_src-ec8f51164d477d8d83726fe61c68977d17b03149.tar.bz2
Cleanup:
* Change int to size_t in a few APIs. * Rename infobar_delegate_count() to infobar_count() in preparation for TabContents owning InfoBars rather than InfoBarDelegates. * Move some code from PluginInstallerInfoBarDelegate to PluginObserver since it's more related to who's instantiating the infobar(delegate)s. * Unify InfoBarDelegate behavior by making no delegates auto-add themselves to tabs (callers now all do this explicitly). * Eliminate unused member TabContentsSSLHelper::SSLAddCertData::handler_. * De-inline a couple classes. * Make more functions private. * Add some consts. * Change DCHECK() to DCHECK_EQ() where possible. * Rename the delegates in plugin_observer.cc to have "Delegate" in the names. * Remove unnecessary qualifiers. * Simplify. * Misc. style issues, naming issues, etc. BUG=none TEST=none Review URL: http://codereview.chromium.org/6250172 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74086 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/translate')
-rw-r--r--chrome/browser/translate/languages_menu_model.cc14
-rw-r--r--chrome/browser/translate/translate_infobar_delegate.cc27
-rw-r--r--chrome/browser/translate/translate_infobar_delegate.h24
-rw-r--r--chrome/browser/translate/translate_infobar_view.h6
-rw-r--r--chrome/browser/translate/translate_manager.cc2
-rw-r--r--chrome/browser/translate/translate_manager_unittest.cc10
6 files changed, 45 insertions, 38 deletions
diff --git a/chrome/browser/translate/languages_menu_model.cc b/chrome/browser/translate/languages_menu_model.cc
index bd3ec10..8e5eb436 100644
--- a/chrome/browser/translate/languages_menu_model.cc
+++ b/chrome/browser/translate/languages_menu_model.cc
@@ -13,22 +13,23 @@ LanguagesMenuModel::LanguagesMenuModel(
: ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
translate_infobar_delegate_(translate_delegate),
language_type_(language_type) {
- for (int i = 0; i < translate_delegate->GetLanguageCount(); ++i)
- AddCheckItem(i, translate_delegate->GetLanguageDisplayableNameAt(i));
+ for (size_t i = 0; i < translate_delegate->GetLanguageCount(); ++i)
+ AddCheckItem(static_cast<int>(i),
+ translate_delegate->GetLanguageDisplayableNameAt(i));
}
LanguagesMenuModel::~LanguagesMenuModel() {
}
bool LanguagesMenuModel::IsCommandIdChecked(int command_id) const {
- return command_id == ((language_type_ == ORIGINAL) ?
+ return static_cast<size_t>(command_id) == ((language_type_ == ORIGINAL) ?
translate_infobar_delegate_->original_language_index() :
translate_infobar_delegate_->target_language_index());
}
bool LanguagesMenuModel::IsCommandIdEnabled(int command_id) const {
// Prevent the same language from being selectable in original and target.
- return command_id != ((language_type_ == ORIGINAL) ?
+ return static_cast<size_t>(command_id) != ((language_type_ == ORIGINAL) ?
translate_infobar_delegate_->target_language_index() :
translate_infobar_delegate_->original_language_index());
}
@@ -40,11 +41,12 @@ bool LanguagesMenuModel::GetAcceleratorForCommandId(
}
void LanguagesMenuModel::ExecuteCommand(int command_id) {
+ size_t command_id_size_t = static_cast<size_t>(command_id);
if (language_type_ == ORIGINAL) {
UMA_HISTOGRAM_COUNTS("Translate.ModifyOriginalLang", 1);
- translate_infobar_delegate_->SetOriginalLanguage(command_id);
+ translate_infobar_delegate_->SetOriginalLanguage(command_id_size_t);
return;
}
UMA_HISTOGRAM_COUNTS("Translate.ModifyTargetLang", 1);
- translate_infobar_delegate_->SetTargetLanguage(command_id);
+ translate_infobar_delegate_->SetTargetLanguage(command_id_size_t);
}
diff --git a/chrome/browser/translate/translate_infobar_delegate.cc b/chrome/browser/translate/translate_infobar_delegate.cc
index c803b19..0d9b688 100644
--- a/chrome/browser/translate/translate_infobar_delegate.cc
+++ b/chrome/browser/translate/translate_infobar_delegate.cc
@@ -19,6 +19,9 @@
#include "ui/base/resource/resource_bundle.h"
// static
+const size_t TranslateInfoBarDelegate::kNoIndex = static_cast<size_t>(-1);
+
+// static
TranslateInfoBarDelegate* TranslateInfoBarDelegate::CreateDelegate(
Type type,
TabContents* tab_contents,
@@ -37,7 +40,7 @@ TranslateInfoBarDelegate* TranslateInfoBarDelegate::CreateDelegate(
TranslateInfoBarDelegate* delegate =
new TranslateInfoBarDelegate(type, TranslateErrors::NONE, tab_contents,
original_language, target_language);
- DCHECK_NE(-1, delegate->target_language_index());
+ DCHECK_NE(kNoIndex, delegate->target_language_index());
return delegate;
}
@@ -53,19 +56,19 @@ TranslateInfoBarDelegate* TranslateInfoBarDelegate::CreateErrorDelegate(
TranslateInfoBarDelegate::~TranslateInfoBarDelegate() {
}
-std::string TranslateInfoBarDelegate::GetLanguageCodeAt(int index) const {
- DCHECK(index >= 0 && index < GetLanguageCount());
+std::string TranslateInfoBarDelegate::GetLanguageCodeAt(size_t index) const {
+ DCHECK_LT(index, GetLanguageCount());
return languages_[index].first;
}
string16 TranslateInfoBarDelegate::GetLanguageDisplayableNameAt(
- int index) const {
- DCHECK(index >= 0 && index < GetLanguageCount());
+ size_t index) const {
+ DCHECK_LT(index, GetLanguageCount());
return languages_[index].second;
}
std::string TranslateInfoBarDelegate::GetOriginalLanguageCode() const {
- return (original_language_index() == -1) ?
+ return (original_language_index() == kNoIndex) ?
chrome::kUnknownLanguageCode :
GetLanguageCodeAt(original_language_index());
}
@@ -74,7 +77,7 @@ std::string TranslateInfoBarDelegate::GetTargetLanguageCode() const {
return GetLanguageCodeAt(target_language_index());
}
-void TranslateInfoBarDelegate::SetOriginalLanguage(int language_index) {
+void TranslateInfoBarDelegate::SetOriginalLanguage(size_t language_index) {
DCHECK_LT(language_index, GetLanguageCount());
original_language_index_ = language_index;
if (infobar_view_)
@@ -83,7 +86,7 @@ void TranslateInfoBarDelegate::SetOriginalLanguage(int language_index) {
Translate();
}
-void TranslateInfoBarDelegate::SetTargetLanguage(int language_index) {
+void TranslateInfoBarDelegate::SetTargetLanguage(size_t language_index) {
DCHECK_LT(language_index, GetLanguageCount());
target_language_index_ = language_index;
if (infobar_view_)
@@ -306,9 +309,9 @@ TranslateInfoBarDelegate::TranslateInfoBarDelegate(
type_(type),
background_animation_(NONE),
tab_contents_(tab_contents),
- original_language_index_(-1),
- initial_original_language_index_(-1),
- target_language_index_(-1),
+ original_language_index_(kNoIndex),
+ initial_original_language_index_(kNoIndex),
+ target_language_index_(kNoIndex),
error_(error),
infobar_view_(NULL),
prefs_(tab_contents_->profile()->GetPrefs()) {
@@ -362,7 +365,7 @@ SkBitmap* TranslateInfoBarDelegate::GetIcon() const {
}
InfoBarDelegate::Type TranslateInfoBarDelegate::GetInfoBarType() const {
- return InfoBarDelegate::PAGE_ACTION_TYPE;
+ return PAGE_ACTION_TYPE;
}
TranslateInfoBarDelegate*
diff --git a/chrome/browser/translate/translate_infobar_delegate.h b/chrome/browser/translate/translate_infobar_delegate.h
index 1bc8a98..5dd2e73 100644
--- a/chrome/browser/translate/translate_infobar_delegate.h
+++ b/chrome/browser/translate/translate_infobar_delegate.h
@@ -33,6 +33,8 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
ERROR_TO_NORMAL
};
+ static const size_t kNoIndex;
+
// Factory method to create a non-error translate infobar.
// The original and target language specified are the ASCII language codes
// (ex: en, fr...).
@@ -54,13 +56,13 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
virtual ~TranslateInfoBarDelegate();
// Returns the number of languages supported.
- int GetLanguageCount() const { return static_cast<int>(languages_.size()); }
+ size_t GetLanguageCount() const { return languages_.size(); }
// Returns the ISO code for the language at |index|.
- std::string GetLanguageCodeAt(int index) const;
+ std::string GetLanguageCodeAt(size_t index) const;
// Returns the displayable name for the language at |index|.
- string16 GetLanguageDisplayableNameAt(int index) const;
+ string16 GetLanguageDisplayableNameAt(size_t index) const;
TabContents* tab_contents() const { return tab_contents_; }
@@ -68,8 +70,8 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
TranslateErrors::Type error() const { return error_; }
- int original_language_index() const { return original_language_index_; }
- int target_language_index() const { return target_language_index_; }
+ size_t original_language_index() const { return original_language_index_; }
+ size_t target_language_index() const { return target_language_index_; }
// Convenience methods.
std::string GetOriginalLanguageCode() const;
@@ -77,8 +79,8 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
// Called by the InfoBar to notify that the original/target language has
// changed and is now the language at |language_index|.
- virtual void SetOriginalLanguage(int language_index);
- virtual void SetTargetLanguage(int 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).
@@ -156,7 +158,7 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
private:
typedef std::pair<std::string, string16> LanguageNamePair;
- // InfoBarDelegate implementation:
+ // InfoBarDelegate:
virtual InfoBar* CreateInfoBar();
virtual void InfoBarDismissed();
virtual void InfoBarClosed();
@@ -181,17 +183,17 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
std::vector<LanguageNamePair> languages_;
// The index for language the page is originally in.
- int original_language_index_;
+ size_t original_language_index_;
// The index for language the page is originally in that was originally
// reported (original_language_index_ changes if the user selects a new
// original language, but this one does not). This is necessary to report
// language detection errors with the right original language even if the user
// changed the original language.
- int initial_original_language_index_;
+ size_t initial_original_language_index_;
// The index for language the page should be translated to.
- int target_language_index_;
+ size_t target_language_index_;
// The error that occurred when trying to translate (NONE if no error).
TranslateErrors::Type error_;
diff --git a/chrome/browser/translate/translate_infobar_view.h b/chrome/browser/translate/translate_infobar_view.h
index 2b4af28..e9b282f 100644
--- a/chrome/browser/translate/translate_infobar_view.h
+++ b/chrome/browser/translate/translate_infobar_view.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -10,8 +10,8 @@
// sense) of the TranslateInfoBarDelegate (which is the model).
class TranslateInfoBarView {
public:
- virtual void OriginalLanguageChanged() = 0;
- virtual void TargetLanguageChanged() = 0;
+ virtual void OriginalLanguageChanged() {}
+ virtual void TargetLanguageChanged() {}
protected:
virtual ~TranslateInfoBarView() {}
diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc
index a07a52a..9146f3d 100644
--- a/chrome/browser/translate/translate_manager.cc
+++ b/chrome/browser/translate/translate_manager.cc
@@ -631,7 +631,7 @@ std::string TranslateManager::GetTargetLanguage() {
// static
TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate(
TabContents* tab) {
- for (int i = 0; i < tab->infobar_delegate_count(); ++i) {
+ for (size_t i = 0; i < tab->infobar_count(); ++i) {
TranslateInfoBarDelegate* delegate =
tab->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate();
if (delegate)
diff --git a/chrome/browser/translate/translate_manager_unittest.cc b/chrome/browser/translate/translate_manager_unittest.cc
index 11087f2..d093b38 100644
--- a/chrome/browser/translate/translate_manager_unittest.cc
+++ b/chrome/browser/translate/translate_manager_unittest.cc
@@ -86,7 +86,7 @@ class TranslateManagerTest : public RenderViewHostTestHarness,
// Returns the translate infobar if there is 1 infobar and it is a translate
// infobar.
TranslateInfoBarDelegate* GetTranslateInfoBar() {
- return (contents()->infobar_delegate_count() == 1) ?
+ return (contents()->infobar_count() == 1) ?
contents()->GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate() :
NULL;
}
@@ -545,21 +545,21 @@ TEST_F(TranslateManagerTest, MultipleOnPageContents) {
// Simulate clicking 'Nope' (don't translate).
EXPECT_TRUE(DenyTranslation());
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
// Send a new PageContents, we should not show an infobar.
SimulateOnPageContents(GURL("http://www.google.fr"), 0, "Le Google", "fr",
true);
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
// Do the same steps but simulate closing the infobar this time.
SimulateNavigation(GURL("http://www.youtube.fr"), "Le YouTube", "fr",
true);
EXPECT_TRUE(CloseTranslateInfoBar());
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
SimulateOnPageContents(GURL("http://www.youtube.fr"), 1, "Le YouTube", "fr",
true);
- EXPECT_EQ(0, contents()->infobar_delegate_count());
+ EXPECT_EQ(0U, contents()->infobar_count());
}
// Test that reloading the page brings back the infobar.