diff options
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.cc | 31 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.h | 25 | ||||
-rw-r--r-- | chrome/browser/gtk/standard_menus.cc | 5 | ||||
-rw-r--r-- | chrome/browser/gtk/sync_setup_wizard_gtk.cc | 121 | ||||
-rw-r--r-- | chrome/browser/gtk/sync_setup_wizard_gtk.h | 51 | ||||
-rw-r--r-- | chrome/browser/sync/glue/bookmark_model_worker.h | 1 | ||||
-rw-r--r-- | chrome/browser/sync/glue/model_associator.h | 1 | ||||
-rw-r--r-- | chrome/browser/sync/notifier/communicator/login.cc | 33 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service.cc | 20 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service.h | 8 | ||||
-rw-r--r-- | chrome/browser/views/sync/sync_setup_wizard.h | 14 |
11 files changed, 280 insertions, 30 deletions
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index eb71258..191844c 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -118,6 +118,10 @@ BookmarkBarGtk::BookmarkBarGtk(BrowserWindowGtk* window, model_(NULL), instructions_label_(NULL), instructions_(NULL), +#ifdef CHROME_PERSONALIZATION + sync_error_button_(NULL), + sync_service_(NULL), +#endif dragged_node_(NULL), toolbar_drop_item_(NULL), theme_provider_(GtkThemeProvider::GetFrom(profile)), @@ -125,6 +129,15 @@ BookmarkBarGtk::BookmarkBarGtk(BrowserWindowGtk* window, menu_bar_helper_(this), floating_(false), last_allocation_width_(-1) { +#ifdef CHROME_PERSONALIZATION + if (profile->GetProfileSyncService()) { + // Obtain a pointer to the profile sync service and add our instance as an + // observer. + sync_service_ = profile->GetProfileSyncService(); + sync_service_->AddObserver(this); + } +#endif + Init(profile); SetProfile(profile); // Force an update by simulating being in the wrong state. @@ -142,6 +155,11 @@ BookmarkBarGtk::~BookmarkBarGtk() { RemoveAllBookmarkButtons(); bookmark_toolbar_.Destroy(); event_box_.Destroy(); + +#ifdef CHROME_PERSONALIZATION + if (sync_service_) + sync_service_->RemoveObserver(this); +#endif } void BookmarkBarGtk::SetProfile(Profile* profile) { @@ -248,6 +266,13 @@ void BookmarkBarGtk::Init(Profile* profile) { g_signal_connect(vseparator, "expose-event", G_CALLBACK(OnSeparatorExpose), this); +#ifdef CHROME_PERSONALIZATION + sync_error_button_ = theme_provider_->BuildChromeButton(); + ConnectFolderButtonEvents(sync_error_button_); + gtk_box_pack_start(GTK_BOX(bookmark_hbox_), sync_error_button_, + FALSE, FALSE, 0); +#endif + // We pack the button manually (rather than using gtk_button_set_*) so that // we can have finer control over its label. other_bookmarks_button_ = theme_provider_->BuildChromeButton(); @@ -311,6 +336,12 @@ void BookmarkBarGtk::Hide(bool animate) { } } +#ifdef CHROME_PERSONALIZATION +void BookmarkBarGtk::OnStateChanged() { + // TODO(zork): TODO +} +#endif + void BookmarkBarGtk::EnterFullscreen() { UpdateFloatingState(); if (!floating_) diff --git a/chrome/browser/gtk/bookmark_bar_gtk.h b/chrome/browser/gtk/bookmark_bar_gtk.h index e353ec1..bc9b24c 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.h +++ b/chrome/browser/gtk/bookmark_bar_gtk.h @@ -15,6 +15,7 @@ #include "chrome/browser/bookmarks/bookmark_model_observer.h" #include "chrome/browser/gtk/menu_bar_helper.h" #include "chrome/browser/gtk/view_id_util.h" +#include "chrome/browser/sync/profile_sync_service.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/owned_widget_gtk.h" @@ -31,6 +32,9 @@ class TabstripOriginProvider; struct GtkThemeProvider; class BookmarkBarGtk : public AnimationDelegate, +#ifdef CHROME_PERSONALIZATION + public ProfileSyncServiceObserver, +#endif public BookmarkModelObserver, public MenuBarHelper::Delegate, public NotificationObserver { @@ -247,6 +251,18 @@ class BookmarkBarGtk : public AnimationDelegate, static gboolean OnSeparatorExpose(GtkWidget* widget, GdkEventExpose* event, BookmarkBarGtk* window); +#ifdef CHROME_PERSONALIZATION + // 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(); +#endif + Profile* profile_; // Used for opening urls. @@ -291,6 +307,15 @@ class BookmarkBarGtk : public AnimationDelegate, // The other bookmarks button. GtkWidget* other_bookmarks_button_; +#ifdef CHROME_PERSONALIZATION + // The sync re-login indicator which appears when the user needs to re-enter + // credentials in order to continue syncing. + GtkWidget* sync_error_button_; + + // A pointer to the ProfileSyncService instance if one exists. + ProfileSyncService* sync_service_; +#endif + // The BookmarkNode from the model being dragged. NULL when we aren't // dragging. const BookmarkNode* dragged_node_; diff --git a/chrome/browser/gtk/standard_menus.cc b/chrome/browser/gtk/standard_menus.cc index 261375e..ce71769 100644 --- a/chrome/browser/gtk/standard_menus.cc +++ b/chrome/browser/gtk/standard_menus.cc @@ -93,7 +93,10 @@ struct MenuCreateMaterial standard_app_menu_materials[] = { { MENU_NORMAL, IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS, 0, NULL, GDK_j, GDK_CONTROL_MASK }, { MENU_SEPARATOR }, - // TODO(erg): P13N stuff goes here as soon as they get IDS strings. +#ifdef CHROME_PERSONALIZATION + { MENU_NORMAL, IDC_SYNC_BOOKMARKS, IDS_SYNC_MY_BOOKMARKS_LABEL}, + { MENU_SEPARATOR }, +#endif { MENU_NORMAL, IDC_OPTIONS, IDS_OPTIONS, IDS_PRODUCT_NAME }, { MENU_NORMAL, IDC_ABOUT, IDS_ABOUT, IDS_PRODUCT_NAME }, { MENU_NORMAL, IDC_HELP_PAGE, IDS_HELP_PAGE, 0, NULL, GDK_F1 }, diff --git a/chrome/browser/gtk/sync_setup_wizard_gtk.cc b/chrome/browser/gtk/sync_setup_wizard_gtk.cc new file mode 100644 index 0000000..e2f46a9 --- /dev/null +++ b/chrome/browser/gtk/sync_setup_wizard_gtk.cc @@ -0,0 +1,121 @@ +// Copyright (c) 2009 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. + +#include "chrome/browser/gtk/sync_setup_wizard_gtk.h" + +#include "chrome/browser/browser_list.h" +#include "chrome/browser/browser_window.h" +#include "chrome/browser/sync/profile_sync_service.h" +#include "chrome/browser/views/sync/sync_setup_wizard.h" +#include "chrome/common/gtk_util.h" + +SyncSetupWizard::SyncSetupWizard(ProfileSyncService* service) + : username_textbox_(NULL), + password_textbox_(NULL), + service_(service), + visible_(false) { +} + +SyncSetupWizard::~SyncSetupWizard() { +} + +void SyncSetupWizard::Step(State advance_state) { + switch (advance_state) { + case GAIA_LOGIN: + SyncSetupWizardGtk::Show(service_, this); + break; + case GAIA_SUCCESS: + case MERGE_AND_SYNC: + case FATAL_ERROR: + case DONE: + // TODO(zork): Implement + break; + default: + NOTREACHED(); + } +} + +bool SyncSetupWizard::IsVisible() const { + return visible_; +} + +// static +void SyncSetupWizardGtk::Show(ProfileSyncService* service, + SyncSetupWizard *wizard) { + Browser* b = BrowserList::GetLastActive(); + new SyncSetupWizardGtk(b->window()->GetNativeHandle(), service, wizard); +} + +SyncSetupWizardGtk::SyncSetupWizardGtk(GtkWindow* parent, + ProfileSyncService* service, + SyncSetupWizard *wizard) + : service_(service), + wizard_(wizard) { + // TODO(zork): Put in proper localized strings. + // + // Build the dialog. + GtkWidget* dialog = gtk_dialog_new_with_buttons( + "Setting up Bookmarks Sync", + parent, + (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), + GTK_STOCK_CANCEL, + GTK_RESPONSE_REJECT, + NULL); + gtk_util::AddButtonToDialog(dialog, + "Accept", + GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); + + GtkWidget* content_area = GTK_DIALOG(dialog)->vbox; + gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); + + GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); + gtk_container_add(GTK_CONTAINER(content_area), vbox); + + // Description. + GtkWidget* description = gtk_label_new( + "Google Chrome can store your bookmark data with your Google account.\n" + "Bookmarks that you create on this computer will instantly be made\n" + "available on all the computers synced to this account.\n"); + gtk_misc_set_alignment(GTK_MISC(description), 0, 0); + gtk_container_add(GTK_CONTAINER(content_area), description); + + // Label on top of the username. + GtkWidget* email = gtk_label_new("Email:"); + gtk_misc_set_alignment(GTK_MISC(email), 0, 0); + gtk_container_add(GTK_CONTAINER(content_area), email); + + // Username text box + username_textbox_= gtk_entry_new(); + gtk_container_add(GTK_CONTAINER(content_area), username_textbox_); + + // Label on top of the password. + GtkWidget* password = gtk_label_new("Password:"); + gtk_misc_set_alignment(GTK_MISC(password), 0, 0); + gtk_container_add(GTK_CONTAINER(content_area), password); + + // Password text box + password_textbox_= gtk_entry_new(); + gtk_entry_set_visibility(GTK_ENTRY(password_textbox_), FALSE); + gtk_container_add(GTK_CONTAINER(content_area), password_textbox_); + + g_signal_connect(dialog, "response", + G_CALLBACK(HandleOnResponseDialog), this); + gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); + gtk_widget_show_all(dialog); +} + +void SyncSetupWizardGtk::OnDialogResponse(GtkWidget* widget, int response) { + wizard_->SetVisible(false); + if (response == GTK_RESPONSE_ACCEPT) { + service_->OnUserSubmittedAuth( + gtk_entry_get_text(GTK_ENTRY(username_textbox_)), + gtk_entry_get_text(GTK_ENTRY(password_textbox_))); + + service_->SetSyncSetupCompleted(); + } + service_->OnUserCancelledDialog(); + + delete this; + gtk_widget_destroy(GTK_WIDGET(widget)); +} diff --git a/chrome/browser/gtk/sync_setup_wizard_gtk.h b/chrome/browser/gtk/sync_setup_wizard_gtk.h new file mode 100644 index 0000000..2d76046 --- /dev/null +++ b/chrome/browser/gtk/sync_setup_wizard_gtk.h @@ -0,0 +1,51 @@ +// Copyright (c) 2009 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_GTK_SYNC_SETUP_WIZARD_GTK_H_ +#define CHROME_BROWSER_GTK_SYNC_SETUP_WIZARD_GTK_H_ + +#include <gtk/gtk.h> + +#include "base/basictypes.h" +#include "base/string16.h" +#include "googleurl/src/gurl.h" + +typedef struct _GtkWidget GtkWidget; +typedef struct _GtkWindow GtkWindow; + +class ProfileSyncService; + +class SyncSetupWizard; + +class SyncSetupWizardGtk { + public: + // Displays the dialog box to setup sync. + static void Show(ProfileSyncService* service, + SyncSetupWizard *wizard); + + private: + SyncSetupWizardGtk(GtkWindow* parent, ProfileSyncService* service, + SyncSetupWizard *wizard); + ~SyncSetupWizardGtk() { } + + // Handler to respond to Ok and Cancel responses from the dialog. + static void HandleOnResponseDialog(GtkWidget* widget, + int response, SyncSetupWizardGtk* setup_wizard) { + setup_wizard->OnDialogResponse(widget, response); + } + + void OnDialogResponse(GtkWidget* widget, int response); + + // UI elements. + GtkWidget* username_textbox_; + GtkWidget* password_textbox_; + + // We need this to write the sentinel "setup completed" pref. + ProfileSyncService* service_; + SyncSetupWizard* wizard_; + + DISALLOW_COPY_AND_ASSIGN(SyncSetupWizardGtk); +}; + +#endif // CHROME_BROWSER_GTK_SYNC_SETUP_WIZARD_GTK_H_ diff --git a/chrome/browser/sync/glue/bookmark_model_worker.h b/chrome/browser/sync/glue/bookmark_model_worker.h index 7ac61e8..2c4520c 100644 --- a/chrome/browser/sync/glue/bookmark_model_worker.h +++ b/chrome/browser/sync/glue/bookmark_model_worker.h @@ -132,4 +132,3 @@ class BookmarkModelWorker #endif // CHROME_BROWSER_SYNC_GLUE_BOOKMARK_MODEL_WORKER_H_ #endif // CHROME_PERSONALIZATION - diff --git a/chrome/browser/sync/glue/model_associator.h b/chrome/browser/sync/glue/model_associator.h index 6c3776e..70fc486 100644 --- a/chrome/browser/sync/glue/model_associator.h +++ b/chrome/browser/sync/glue/model_associator.h @@ -141,4 +141,3 @@ class ModelAssociator #endif // CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCATOR_H_ #endif // CHROME_PERSONALIZATION - diff --git a/chrome/browser/sync/notifier/communicator/login.cc b/chrome/browser/sync/notifier/communicator/login.cc index 4e2feb1..90a0e70 100644 --- a/chrome/browser/sync/notifier/communicator/login.cc +++ b/chrome/browser/sync/notifier/communicator/login.cc @@ -70,20 +70,23 @@ Login::Login(talk_base::Task* parent, network_status->Start(); } } - network_status->SignalNetworkStateDetected.connect( - this, &Login::OnNetworkStateDetected); - auto_reconnect_.reset(new AutoReconnect(parent_, network_status)); - auto_reconnect_->SignalStartConnection.connect(this, - &Login::StartConnection); - auto_reconnect_->SignalTimerStartStop.connect( - this, - &Login::OnAutoReconnectTimerChange); - SignalClientStateChange.connect(auto_reconnect_.get(), - &AutoReconnect::OnClientStateChange); - SignalIdleChange.connect(auto_reconnect_.get(), - &AutoReconnect::set_idle); - SignalPowerSuspended.connect(auto_reconnect_.get(), - &AutoReconnect::OnPowerSuspend); + + if (network_status) { + network_status->SignalNetworkStateDetected.connect( + this, &Login::OnNetworkStateDetected); + auto_reconnect_.reset(new AutoReconnect(parent_, network_status)); + auto_reconnect_->SignalStartConnection.connect(this, + &Login::StartConnection); + auto_reconnect_->SignalTimerStartStop.connect( + this, + &Login::OnAutoReconnectTimerChange); + SignalClientStateChange.connect(auto_reconnect_.get(), + &AutoReconnect::OnClientStateChange); + SignalIdleChange.connect(auto_reconnect_.get(), + &AutoReconnect::set_idle); + SignalPowerSuspended.connect(auto_reconnect_.get(), + &AutoReconnect::OnPowerSuspend); + } } // Defined so that the destructors are executed here (and the corresponding @@ -190,7 +193,7 @@ void Login::OnClientStateChange(buzz::XmppEngine::State state) { void Login::HandleClientStateChange(ConnectionState new_state) { // Do we need to transition between the retrying and closed states? - if (auto_reconnect_->is_retrying()) { + if (auto_reconnect_.get() && auto_reconnect_->is_retrying()) { if (new_state == STATE_CLOSED) { new_state = STATE_RETRYING; } diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 9b2c3f2..3dbf1d7 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -45,8 +45,8 @@ ProfileSyncService::ProfileSyncService(Profile* profile) backend_initialized_(false), expecting_first_run_auth_needed_event_(false), is_auth_in_progress_(false), - unrecoverable_error_detected_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(wizard_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(wizard_(this)), + unrecoverable_error_detected_(false) { change_processor_.reset(new ChangeProcessor(this)); } @@ -72,7 +72,7 @@ void ProfileSyncService::Initialize() { void ProfileSyncService::InitSettings() { const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - // Override the sync server URL from the command-line, if sync server + // Override the sync server URL from the command-line, if sync server // command-line argument exists. if (command_line.HasSwitch(switches::kSyncServiceURL)) { std::wstring value(command_line.GetSwitchValue(switches::kSyncServiceURL)); @@ -152,7 +152,7 @@ void ProfileSyncService::Shutdown(bool sync_disabled) { } void ProfileSyncService::EnableForUser() { - if (wizard_.IsVisible()) { + if (WizardIsVisible()) { // TODO(timsteele): Focus wizard. return; } @@ -163,7 +163,7 @@ void ProfileSyncService::EnableForUser() { } void ProfileSyncService::DisableForUser() { - if (wizard_.IsVisible()) { + if (WizardIsVisible()) { // TODO(timsteele): Focus wizard. return; } @@ -212,6 +212,7 @@ void ProfileSyncService::UpdateLastSyncedTime() { void ProfileSyncService::OnUnrecoverableError() { unrecoverable_error_detected_ = true; change_processor_->Stop(); + if (SetupInProgress()) wizard_.Step(SyncSetupWizard::FATAL_ERROR); FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); @@ -240,7 +241,7 @@ void ProfileSyncService::OnAuthError() { // Protect against the in-your-face dialogs that pop out of nowhere. // Require the user to click somewhere to run the setup wizard in the case // of a steady-state auth failure. - if (wizard_.IsVisible() || expecting_first_run_auth_needed_event_) { + if (WizardIsVisible() || expecting_first_run_auth_needed_event_) { wizard_.Step(AUTH_ERROR_NONE == backend_->GetAuthErrorState() ? SyncSetupWizard::GAIA_SUCCESS : SyncSetupWizard::GAIA_LOGIN); } @@ -250,7 +251,7 @@ void ProfileSyncService::OnAuthError() { expecting_first_run_auth_needed_event_ = false; } - if (!wizard_.IsVisible()) { + if (!WizardIsVisible()) { auth_error_time_ == base::TimeTicks::Now(); } @@ -266,7 +267,7 @@ void ProfileSyncService::OnAuthError() { } void ProfileSyncService::ShowLoginDialog() { - if (wizard_.IsVisible()) + if (WizardIsVisible()) return; if (!auth_error_time_.is_null()) { @@ -275,8 +276,9 @@ void ProfileSyncService::ShowLoginDialog() { auth_error_time_ = base::TimeTicks(); // Reset auth_error_time_ to null. } - if (last_auth_error_ != AUTH_ERROR_NONE) + if (last_auth_error_ != AUTH_ERROR_NONE) { wizard_.Step(SyncSetupWizard::GAIA_LOGIN); + } } SyncBackendHost::StatusSummary ProfileSyncService::QuerySyncStatusSummary() { diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index 011f55f..fab7ea5 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -144,7 +144,9 @@ class ProfileSyncService : public NotificationObserver, bool SetupInProgress() const { return !HasSyncSetupCompleted() && WizardIsVisible(); } - bool WizardIsVisible() const { return wizard_.IsVisible(); } + bool WizardIsVisible() const { + return wizard_.IsVisible(); + } void ShowLoginDialog(); // Pretty-printed strings for a given StatusSummary. @@ -298,13 +300,13 @@ class ProfileSyncService : public NotificationObserver, // As its name suggests, this should NOT be used for anything other than UI. bool is_auth_in_progress_; + SyncSetupWizard wizard_; + // True if an unrecoverable error (e.g. violation of an assumed invariant) // occurred during syncer operation. This value should be checked before // doing any work that might corrupt things further. bool unrecoverable_error_detected_; - SyncSetupWizard wizard_; - ObserverList<Observer> observers_; DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); diff --git a/chrome/browser/views/sync/sync_setup_wizard.h b/chrome/browser/views/sync/sync_setup_wizard.h index fe1ed03..f51ba64 100644 --- a/chrome/browser/views/sync/sync_setup_wizard.h +++ b/chrome/browser/views/sync/sync_setup_wizard.h @@ -7,7 +7,12 @@ #include "base/basictypes.h" +#if defined(OS_WIN) class SyncSetupFlowContainer; +#elif defined(OS_LINUX) +typedef struct _GtkWidget GtkWidget; +typedef struct _GtkWindow GtkWindow; +#endif class ProfileSyncService; @@ -35,6 +40,10 @@ class SyncSetupWizard { // if various buttons in the UI should be enabled or disabled. bool IsVisible() const; +#if defined(OS_LINUX) + void SetVisible(bool visible) { visible_ = visible; } +#endif + private: // If we just need to pop open an individual dialog, say to collect // gaia credentials in the event of a steady-state auth failure, this is @@ -43,7 +52,12 @@ class SyncSetupWizard { static State GetEndStateForDiscreteRun(State start_state); ProfileSyncService* service_; + +#if defined(OS_WIN) SyncSetupFlowContainer* flow_container_; +#elif defined(OS_LINUX) + bool visible_; +#endif DISALLOW_COPY_AND_ASSIGN(SyncSetupWizard); }; |