| 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" | 10 #include "chrome/browser/signin/signin_manager.h" |
| 11 #include "chrome/browser/signin/signin_manager_factory.h" | 11 #include "chrome/browser/signin/signin_manager_factory.h" |
| 12 #include "chrome/browser/sync/profile_sync_service.h" | 12 #include "chrome/browser/sync/profile_sync_service.h" |
| 13 #include "chrome/browser/sync/profile_sync_service_factory.h" | 13 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 14 #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" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_finder.h" | 16 #include "chrome/browser/ui/browser_finder.h" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 18 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 18 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 19 #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" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 24 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
| 25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
| 27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 | 86 |
| 87 void AppNotifyChannelUIImpl::InfoBar::InfoBarDismissed() { | 87 void AppNotifyChannelUIImpl::InfoBar::InfoBarDismissed() { |
| 88 Cancel(); | 88 Cancel(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 | 91 |
| 92 AppNotifyChannelUIImpl::AppNotifyChannelUIImpl( | 92 AppNotifyChannelUIImpl::AppNotifyChannelUIImpl( |
| 93 Profile* profile, | 93 Profile* profile, |
| 94 TabContentsWrapper* wrapper, | 94 TabContents* tab_contents, |
| 95 const std::string& app_name, | 95 const std::string& app_name, |
| 96 AppNotifyChannelUI::UIType ui_type) | 96 AppNotifyChannelUI::UIType ui_type) |
| 97 : profile_(profile->GetOriginalProfile()), | 97 : profile_(profile->GetOriginalProfile()), |
| 98 wrapper_(wrapper), | 98 tab_contents_(tab_contents), |
| 99 app_name_(app_name), | 99 app_name_(app_name), |
| 100 ui_type_(ui_type), | 100 ui_type_(ui_type), |
| 101 delegate_(NULL), | 101 delegate_(NULL), |
| 102 observing_sync_(false), | 102 observing_sync_(false), |
| 103 wizard_shown_to_user_(false) { | 103 wizard_shown_to_user_(false) { |
| 104 } | 104 } |
| 105 | 105 |
| 106 AppNotifyChannelUIImpl::~AppNotifyChannelUIImpl() { | 106 AppNotifyChannelUIImpl::~AppNotifyChannelUIImpl() { |
| 107 // We should have either not started observing sync, or already called | 107 // We should have either not started observing sync, or already called |
| 108 // StopObservingSync by this point. | 108 // StopObservingSync by this point. |
| 109 CHECK(!observing_sync_); | 109 CHECK(!observing_sync_); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void AppNotifyChannelUIImpl::PromptSyncSetup( | 112 void AppNotifyChannelUIImpl::PromptSyncSetup( |
| 113 AppNotifyChannelUI::Delegate* delegate) { | 113 AppNotifyChannelUI::Delegate* delegate) { |
| 114 CHECK(delegate_ == NULL); | 114 CHECK(delegate_ == NULL); |
| 115 delegate_ = delegate; | 115 delegate_ = delegate; |
| 116 | 116 |
| 117 if (!ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | 117 if (!ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( |
| 118 profile_)) { | 118 profile_)) { |
| 119 delegate_->OnSyncSetupResult(false); | 119 delegate_->OnSyncSetupResult(false); |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 | 122 |
| 123 if (ui_type_ == NO_INFOBAR) { | 123 if (ui_type_ == NO_INFOBAR) { |
| 124 OnInfoBarResult(true); | 124 OnInfoBarResult(true); |
| 125 return; | 125 return; |
| 126 } | 126 } |
| 127 | 127 |
| 128 InfoBarTabHelper* helper = wrapper_->infobar_tab_helper(); | 128 InfoBarTabHelper* helper = tab_contents_->infobar_tab_helper(); |
| 129 helper->AddInfoBar(new AppNotifyChannelUIImpl::InfoBar( | 129 helper->AddInfoBar(new AppNotifyChannelUIImpl::InfoBar( |
| 130 this, helper, app_name_)); | 130 this, helper, app_name_)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void AppNotifyChannelUIImpl::OnInfoBarResult(bool accepted) { | 133 void AppNotifyChannelUIImpl::OnInfoBarResult(bool accepted) { |
| 134 if (accepted) { | 134 if (accepted) { |
| 135 StartObservingSync(); | 135 StartObservingSync(); |
| 136 // Bring up the login page. | 136 // Bring up the login page. |
| 137 LoginUIService* login_ui_service = | 137 LoginUIService* login_ui_service = |
| 138 LoginUIServiceFactory::GetForProfile(profile_); | 138 LoginUIServiceFactory::GetForProfile(profile_); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 194 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 195 profile_)->AddObserver(this); | 195 profile_)->AddObserver(this); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void AppNotifyChannelUIImpl::StopObservingSync() { | 198 void AppNotifyChannelUIImpl::StopObservingSync() { |
| 199 CHECK(observing_sync_); | 199 CHECK(observing_sync_); |
| 200 observing_sync_ = false; | 200 observing_sync_ = false; |
| 201 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 201 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 202 profile_)->RemoveObserver(this); | 202 profile_)->RemoveObserver(this); |
| 203 } | 203 } |
| OLD | NEW |