| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/app_notify_channel_ui.h" | 5 #include "chrome/browser/extensions/app_notify_channel_ui.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/infobars/infobar_tab_helper.h" | 8 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/signin/signin_manager.h" |
| 11 #include "chrome/browser/signin/signin_manager_factory.h" |
| 10 #include "chrome/browser/sync/profile_sync_service.h" | 12 #include "chrome/browser/sync/profile_sync_service.h" |
| 11 #include "chrome/browser/sync/profile_sync_service_factory.h" | 13 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 12 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 14 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 14 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 18 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 15 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 19 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 20 #include "chrome/common/url_constants.h" |
| 16 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| 17 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
| 20 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
| 22 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 24 | 29 |
| 25 class AppNotifyChannelUIImpl::InfoBar : public ConfirmInfoBarDelegate { | 30 class AppNotifyChannelUIImpl::InfoBar : public ConfirmInfoBarDelegate { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 126 } |
| 122 | 127 |
| 123 InfoBarTabHelper* helper = wrapper_->infobar_tab_helper(); | 128 InfoBarTabHelper* helper = wrapper_->infobar_tab_helper(); |
| 124 helper->AddInfoBar(new AppNotifyChannelUIImpl::InfoBar( | 129 helper->AddInfoBar(new AppNotifyChannelUIImpl::InfoBar( |
| 125 this, helper, app_name_)); | 130 this, helper, app_name_)); |
| 126 } | 131 } |
| 127 | 132 |
| 128 void AppNotifyChannelUIImpl::OnInfoBarResult(bool accepted) { | 133 void AppNotifyChannelUIImpl::OnInfoBarResult(bool accepted) { |
| 129 if (accepted) { | 134 if (accepted) { |
| 130 StartObservingSync(); | 135 StartObservingSync(); |
| 131 LoginUIServiceFactory::GetForProfile(profile_)->ShowLoginUI(true); | 136 // Bring up the login page. |
| 132 } else { | 137 LoginUIService* login_ui_service = |
| 133 delegate_->OnSyncSetupResult(false); | 138 LoginUIServiceFactory::GetForProfile(profile_); |
| 139 LoginUIService::LoginUI* login_ui = login_ui_service->current_login_ui(); |
| 140 if (login_ui) { |
| 141 // Some sort of login UI is already visible. |
| 142 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
| 143 if (signin->GetAuthenticatedUsername().empty()) { |
| 144 // User is not logged in yet, so just bring up the login UI (could be |
| 145 // the promo UI). |
| 146 login_ui->FocusUI(); |
| 147 return; |
| 148 } else { |
| 149 // User is already logged in, so close whatever sync config UI the |
| 150 // user is looking at and display new login UI. |
| 151 login_ui->CloseUI(); |
| 152 DCHECK(!login_ui_service->current_login_ui()); |
| 153 } |
| 154 } |
| 155 // Any existing UI is now closed - display new login UI. |
| 156 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
| 157 if (browser) { |
| 158 browser->ShowOptionsTab(chrome::kSyncSetupForceLoginSubPage); |
| 159 return; |
| 160 } |
| 161 // Should not be possible to have no browser here, since we're in an |
| 162 // infobar callback. |
| 163 NOTREACHED(); |
| 134 } | 164 } |
| 165 delegate_->OnSyncSetupResult(false); |
| 135 } | 166 } |
| 136 | 167 |
| 137 void AppNotifyChannelUIImpl::OnStateChanged() { | 168 void AppNotifyChannelUIImpl::OnStateChanged() { |
| 138 #if !defined(OS_ANDROID) | 169 #if !defined(OS_ANDROID) |
| 139 ProfileSyncService* sync_service = | 170 ProfileSyncService* sync_service = |
| 140 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); | 171 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
| 141 LoginUIService* login_service = | 172 LoginUIService* login_service = |
| 142 LoginUIServiceFactory::GetForProfile(profile_); | 173 LoginUIServiceFactory::GetForProfile(profile_); |
| 143 | 174 |
| 144 bool wizard_visible = (login_service->current_login_ui() != NULL); | 175 bool wizard_visible = (login_service->current_login_ui() != NULL); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 163 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 194 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 164 profile_)->AddObserver(this); | 195 profile_)->AddObserver(this); |
| 165 } | 196 } |
| 166 | 197 |
| 167 void AppNotifyChannelUIImpl::StopObservingSync() { | 198 void AppNotifyChannelUIImpl::StopObservingSync() { |
| 168 CHECK(observing_sync_); | 199 CHECK(observing_sync_); |
| 169 observing_sync_ = false; | 200 observing_sync_ = false; |
| 170 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 201 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 171 profile_)->RemoveObserver(this); | 202 profile_)->RemoveObserver(this); |
| 172 } | 203 } |
| OLD | NEW |