diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-06 22:27:39 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-06 22:27:39 +0000 |
commit | 06eee70c5530309d7e17f47e5297c7218fa0a5f1 (patch) | |
tree | 87272869ba78f9bdde7c6b0835b07cf7c43a064a /chrome | |
parent | 8f1a633e90ac9bf4f959baeff321e35d5e031830 (diff) | |
download | chromium_src-06eee70c5530309d7e17f47e5297c7218fa0a5f1.zip chromium_src-06eee70c5530309d7e17f47e5297c7218fa0a5f1.tar.gz chromium_src-06eee70c5530309d7e17f47e5297c7218fa0a5f1.tar.bz2 |
sync: Add two functions to sync_ui_util header and update the callers accordingly.
* ShouldShowSyncErrorButton: added.
* GetSyncMenuLabel: added.
(original code review: http://codereview.chromium.org/501142 , patch by thiago.farina@gmail.com )
Review URL: http://codereview.chromium.org/519069
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35656 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/app_menu_model.cc | 16 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.cc | 11 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 16 | ||||
-rw-r--r-- | chrome/browser/sync/sync_ui_util.cc | 16 | ||||
-rw-r--r-- | chrome/browser/sync/sync_ui_util.h | 9 | ||||
-rw-r--r-- | chrome/browser/views/bookmark_bar_view.cc | 25 | ||||
-rw-r--r-- | chrome/browser/views/bookmark_bar_view.h | 4 |
8 files changed, 36 insertions, 65 deletions
diff --git a/chrome/browser/app_menu_model.cc b/chrome/browser/app_menu_model.cc index 020e1b1..38aca15 100644 --- a/chrome/browser/app_menu_model.cc +++ b/chrome/browser/app_menu_model.cc @@ -57,20 +57,8 @@ void AppMenuModel::Build() { AddSeparator(); if (ProfileSyncService::IsSyncEnabled()) { - string16 label; - string16 link; - // TODO(akalin): use sync_ui_util::GetStatus instead. - sync_ui_util::MessageType type = sync_ui_util::GetStatusLabels( - browser_->profile()->GetOriginalProfile()->GetProfileSyncService(), - &label, &link); - if (type == sync_ui_util::SYNCED) { - label = l10n_util::GetStringUTF16(IDS_SYNC_MENU_BOOKMARKS_SYNCED_LABEL); - } else if (type == sync_ui_util::SYNC_ERROR) { - label = l10n_util::GetStringUTF16( - IDS_SYNC_MENU_BOOKMARK_SYNC_ERROR_LABEL); - } else { - label = l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL); - } + string16 label = sync_ui_util::GetSyncMenuLabel( + browser_->profile()->GetOriginalProfile()->GetProfileSyncService()); AddItem(IDC_SYNC_BOOKMARKS, label); AddSeparator(); } diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index 31a7058..932e6ed 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -311,7 +311,7 @@ void BookmarkBarGtk::Show(bool animate) { gdk_window_lower(event_box_->window); } - if (ShouldShowSyncErrorButton()) { + if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) { gtk_widget_show(sync_error_button_); } else { gtk_widget_hide(sync_error_button_); @@ -343,7 +343,7 @@ void BookmarkBarGtk::Hide(bool animate) { } void BookmarkBarGtk::OnStateChanged() { - if (ShouldShowSyncErrorButton()) { + if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) { gtk_widget_show(sync_error_button_); } else { gtk_widget_hide(sync_error_button_); @@ -1297,10 +1297,3 @@ void BookmarkBarGtk::PopupForButtonNextTo(GtkWidget* button, button_idx = (button_idx + shift + folder_list.size()) % folder_list.size(); PopupForButton(folder_list[button_idx]); } - -// The sync state reported by the profile sync service determines whether or -// not the re-login indicator button should be visible. -bool BookmarkBarGtk::ShouldShowSyncErrorButton() { - return sync_service_ && sync_service_->HasSyncSetupCompleted() && - (sync_ui_util::GetStatus(sync_service_) == sync_ui_util::SYNC_ERROR); -} diff --git a/chrome/browser/gtk/bookmark_bar_gtk.h b/chrome/browser/gtk/bookmark_bar_gtk.h index 6a58e17..18450c8 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.h +++ b/chrome/browser/gtk/bookmark_bar_gtk.h @@ -266,10 +266,6 @@ class BookmarkBarGtk : public AnimationDelegate, // ProfileSyncServiceObserver method. virtual void OnStateChanged(); - // Determines whether the sync error button should appear on the bookmarks - // bar. - bool ShouldShowSyncErrorButton(); - // Creates the sync error button and adds it as a child view. GtkWidget* CreateSyncErrorButton(); diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index a2f8e42..13a0508 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -699,15 +699,8 @@ void BrowserToolbarGtk::OnDragDataReceived(GtkWidget* widget, void BrowserToolbarGtk::OnStateChanged() { DCHECK(sync_service_); - sync_ui_util::MessageType type = sync_ui_util::GetStatus(sync_service_); - - // TODO(akalin): Refactor this logic into a function called GetSyncMenuLabel - // in sync_ui_util.h. And use the function in Windows/Mac code too. - int menu_label = type == sync_ui_util::SYNCED ? - IDS_SYNC_MENU_BOOKMARKS_SYNCED_LABEL : - type == sync_ui_util::SYNC_ERROR ? - IDS_SYNC_MENU_BOOKMARK_SYNC_ERROR_LABEL : - IDS_SYNC_START_SYNC_BUTTON_LABEL; + std::string menu_label = UTF16ToUTF8( + sync_ui_util::GetSyncMenuLabel(sync_service_)); gtk_container_foreach(GTK_CONTAINER(app_menu_->widget()), &SetSyncMenuLabel, &menu_label); @@ -720,9 +713,8 @@ void BrowserToolbarGtk::SetSyncMenuLabel(GtkWidget* widget, gpointer userdata) { g_object_get_data(G_OBJECT(widget), "menu-data")); if (data) { if (data->id == IDC_SYNC_BOOKMARKS) { - std::string label; - label = l10n_util::GetStringUTF8(*((int *)userdata)); - label = gtk_util::ConvertAcceleratorsFromWindowsStyle(label); + std::string label = gtk_util::ConvertAcceleratorsFromWindowsStyle( + *reinterpret_cast<const std::string*>(userdata)); GtkWidget *menu_label = gtk_bin_get_child(GTK_BIN(widget)); gtk_label_set_label(GTK_LABEL(menu_label), label.c_str()); } diff --git a/chrome/browser/sync/sync_ui_util.cc b/chrome/browser/sync/sync_ui_util.cc index c82482a..5edd4db 100644 --- a/chrome/browser/sync/sync_ui_util.cc +++ b/chrome/browser/sync/sync_ui_util.cc @@ -160,6 +160,22 @@ MessageType GetStatus(ProfileSyncService* service) { return sync_ui_util::GetStatusInfo(service, NULL, NULL); } +bool ShouldShowSyncErrorButton(ProfileSyncService* service) { + return service && service->HasSyncSetupCompleted() && + (GetStatus(service) == sync_ui_util::SYNC_ERROR); +} + +string16 GetSyncMenuLabel(ProfileSyncService* service) { + MessageType type = GetStatus(service); + + if (type == sync_ui_util::SYNCED) + return l10n_util::GetStringUTF16(IDS_SYNC_MENU_BOOKMARKS_SYNCED_LABEL); + else if (type == sync_ui_util::SYNC_ERROR) + return l10n_util::GetStringUTF16(IDS_SYNC_MENU_BOOKMARK_SYNC_ERROR_LABEL); + else + return l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL); +} + void OpenSyncMyBookmarksDialog( Profile* profile, ProfileSyncService::SyncEventCodes code) { ProfileSyncService* service = diff --git a/chrome/browser/sync/sync_ui_util.h b/chrome/browser/sync/sync_ui_util.h index 53f0036..0b9483e 100644 --- a/chrome/browser/sync/sync_ui_util.h +++ b/chrome/browser/sync/sync_ui_util.h @@ -20,6 +20,9 @@ enum MessageType { SYNC_ERROR, // A sync error (such as invalid credentials) has occurred. }; +// TODO(akalin): audit the use of ProfileSyncService* service below, +// and use const ProfileSyncService& service where possible. + // Create status and link labels for the current status labels and link text // by querying |service|. MessageType GetStatusLabels(ProfileSyncService* service, @@ -28,6 +31,12 @@ MessageType GetStatusLabels(ProfileSyncService* service, MessageType GetStatus(ProfileSyncService* service); +// Determines whether or not the sync error button should be visible. +bool ShouldShowSyncErrorButton(ProfileSyncService* service); + +// Returns a string with the synchronization status. +string16 GetSyncMenuLabel(ProfileSyncService* service); + // Open the appropriate sync dialog for the given profile (which can be // incognito). |code| should be one of the START_FROM_* codes. void OpenSyncMyBookmarksDialog( diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index 2a2cece..67936a7 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -487,7 +487,7 @@ gfx::Size BookmarkBarView::GetMinimumSize() { int sync_error_total_width = 0; gfx::Size sync_error_button_pref = sync_error_button_->GetPreferredSize(); - if (ShouldShowSyncErrorButton()) + if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) sync_error_total_width += kButtonPadding + sync_error_button_pref.width(); gfx::Size other_bookmarked_pref = @@ -1607,8 +1607,7 @@ gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { int sync_error_total_width = 0; gfx::Size sync_error_button_pref = sync_error_button_->GetPreferredSize(); - const bool should_show_sync_error_button = ShouldShowSyncErrorButton(); - if (should_show_sync_error_button) { + if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) { sync_error_total_width += kButtonPadding + sync_error_button_pref.width(); } const int max_x = width - other_bookmarked_pref.width() - kButtonPadding - @@ -1681,7 +1680,7 @@ gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { // Set the real bounds of the sync error button only if it needs to appear on // the bookmarks bar. - if (should_show_sync_error_button) { + if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) { x += kButtonPadding; if (!compute_bounds_only) { sync_error_button_->SetBounds( @@ -1712,24 +1711,6 @@ gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { return prefsize; } -// The sync state reported by the profile sync service determines whether or -// not the re-login indicator button should be visible. -bool BookmarkBarView::ShouldShowSyncErrorButton() { - bool show_sync_error_button(false); - if (sync_service_ && sync_service_->HasSyncSetupCompleted()) { - string16 status_text; - string16 link_text; - // TODO(akalin): use sync_ui_util::GetStatus instead. - sync_ui_util::MessageType sync_status; - sync_status = sync_ui_util::GetStatusLabels( - sync_service_, &status_text, &link_text); - if (sync_status == sync_ui_util::SYNC_ERROR) { - show_sync_error_button = true; - } - } - return show_sync_error_button; -} - views::TextButton* BookmarkBarView::CreateSyncErrorButton() { views::TextButton* sync_error_button = new views::TextButton(this, diff --git a/chrome/browser/views/bookmark_bar_view.h b/chrome/browser/views/bookmark_bar_view.h index ad6cc76..797ec51 100644 --- a/chrome/browser/views/bookmark_bar_view.h +++ b/chrome/browser/views/bookmark_bar_view.h @@ -425,10 +425,6 @@ class BookmarkBarView : public DetachableToolbarView, // desired bounds. If |compute_bounds_only| = FALSE, the bounds are set. gfx::Size LayoutItems(bool compute_bounds_only); - // Determines whether the sync error button should appear on the bookmarks - // bar. - bool ShouldShowSyncErrorButton(); - // Creates the sync error button and adds it as a child view. views::TextButton* CreateSyncErrorButton(); |