Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
| 11 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 11 #include "chrome/browser/sync/sync_setup_wizard.h" | 12 #include "chrome/browser/sync/sync_setup_wizard.h" |
| 12 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 13 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 15 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
| 16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/notification_types.h" | 21 #include "content/public/browser/notification_types.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 | 109 |
| 109 InfoBarTabHelper* helper = wrapper_->infobar_tab_helper(); | 110 InfoBarTabHelper* helper = wrapper_->infobar_tab_helper(); |
| 110 helper->AddInfoBar(new AppNotifyChannelUIImpl::InfoBar( | 111 helper->AddInfoBar(new AppNotifyChannelUIImpl::InfoBar( |
| 111 this, helper, app_name_)); | 112 this, helper, app_name_)); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void AppNotifyChannelUIImpl::OnInfoBarResult(bool accepted) { | 115 void AppNotifyChannelUIImpl::OnInfoBarResult(bool accepted) { |
| 115 if (accepted) { | 116 if (accepted) { |
| 116 StartObservingSync(); | 117 StartObservingSync(); |
| 117 ProfileSyncService* service = | 118 ProfileSyncService* service = |
| 118 browser_->profile()->GetOriginalProfile()->GetProfileSyncService(); | 119 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 120 browser_->profile()->GetOriginalProfile()); | |
| 119 service->ShowLoginDialog(); | 121 service->ShowLoginDialog(); |
| 120 } else { | 122 } else { |
| 121 delegate_->OnSyncSetupResult(false); | 123 delegate_->OnSyncSetupResult(false); |
| 122 } | 124 } |
| 123 } | 125 } |
| 124 | 126 |
| 125 void AppNotifyChannelUIImpl::OnStateChanged() { | 127 void AppNotifyChannelUIImpl::OnStateChanged() { |
| 128 // TODO(REVIEWERS): Why does this not use OriginalProfile but above we do? | |
|
asargent_no_longer_on_chrome
2012/01/27 00:49:20
This (and all the others below) can use OriginalPr
| |
| 126 ProfileSyncService* sync_service = | 129 ProfileSyncService* sync_service = |
| 127 browser_->profile()->GetProfileSyncService(); | 130 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 131 browser_->profile()); | |
| 128 bool wizard_visible = sync_service->WizardIsVisible(); | 132 bool wizard_visible = sync_service->WizardIsVisible(); |
| 129 // ProfileSyncService raises OnStateChanged many times. Even multiple | 133 // ProfileSyncService raises OnStateChanged many times. Even multiple |
| 130 // times before the wizard actually becomes visible for the first time. | 134 // times before the wizard actually becomes visible for the first time. |
| 131 // So we have to wait for the wizard to become visible once and then we | 135 // So we have to wait for the wizard to become visible once and then we |
| 132 // wait for it to get dismissed. | 136 // wait for it to get dismissed. |
| 133 bool finished = wizard_shown_to_user_ && !wizard_visible; | 137 bool finished = wizard_shown_to_user_ && !wizard_visible; |
| 134 if (wizard_visible) | 138 if (wizard_visible) |
| 135 wizard_shown_to_user_ = true; | 139 wizard_shown_to_user_ = true; |
| 136 | 140 |
| 137 if (finished) { | 141 if (finished) { |
| 138 StopObservingSync(); | 142 StopObservingSync(); |
| 139 delegate_->OnSyncSetupResult(sync_service->HasSyncSetupCompleted()); | 143 delegate_->OnSyncSetupResult(sync_service->HasSyncSetupCompleted()); |
| 140 } | 144 } |
| 141 } | 145 } |
| 142 | 146 |
| 143 void AppNotifyChannelUIImpl::StartObservingSync() { | 147 void AppNotifyChannelUIImpl::StartObservingSync() { |
| 144 CHECK(!observing_sync_); | 148 CHECK(!observing_sync_); |
| 145 observing_sync_ = true; | 149 observing_sync_ = true; |
| 146 browser_->profile()->GetProfileSyncService()->AddObserver(this); | 150 // TODO(REVIEWERS): Why does this not use OriginalProfile but above we do? |
| 151 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | |
| 152 browser_->profile())->AddObserver(this); | |
| 147 } | 153 } |
| 148 | 154 |
| 149 void AppNotifyChannelUIImpl::StopObservingSync() { | 155 void AppNotifyChannelUIImpl::StopObservingSync() { |
| 150 CHECK(observing_sync_); | 156 CHECK(observing_sync_); |
| 151 observing_sync_ = false; | 157 observing_sync_ = false; |
| 152 browser_->profile()->GetProfileSyncService()->RemoveObserver(this); | 158 // TODO(REVIEWERS): Why does this not use OriginalProfile but above we do? |
| 159 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | |
| 160 browser_->profile())->RemoveObserver(this); | |
| 153 } | 161 } |
| OLD | NEW |