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" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 void AppNotifyChannelUIImpl::InfoBar::InfoBarDismissed() { | 81 void AppNotifyChannelUIImpl::InfoBar::InfoBarDismissed() { |
82 Cancel(); | 82 Cancel(); |
83 } | 83 } |
84 | 84 |
85 | 85 |
86 AppNotifyChannelUIImpl::AppNotifyChannelUIImpl(Browser* browser, | 86 AppNotifyChannelUIImpl::AppNotifyChannelUIImpl(Browser* browser, |
87 TabContentsWrapper* wrapper, | 87 TabContentsWrapper* wrapper, |
88 const std::string& app_name) | 88 const std::string& app_name) |
89 : browser_(browser), wrapper_(wrapper), app_name_(app_name), | 89 : browser_(browser), wrapper_(wrapper), app_name_(app_name), |
90 delegate_(NULL), observing_sync_(false), got_first_sync_callback_(false) { | 90 delegate_(NULL), observing_sync_(false), wizard_shown_to_user_(false) { |
91 } | 91 } |
92 | 92 |
93 AppNotifyChannelUIImpl::~AppNotifyChannelUIImpl() { | 93 AppNotifyChannelUIImpl::~AppNotifyChannelUIImpl() { |
94 // We should have either not started observing sync, or already called | 94 // We should have either not started observing sync, or already called |
95 // StopObservingSync by this point. | 95 // StopObservingSync by this point. |
96 CHECK(!observing_sync_); | 96 CHECK(!observing_sync_); |
97 } | 97 } |
98 | 98 |
99 void AppNotifyChannelUIImpl::PromptSyncSetup( | 99 void AppNotifyChannelUIImpl::PromptSyncSetup( |
100 AppNotifyChannelUI::Delegate* delegate) { | 100 AppNotifyChannelUI::Delegate* delegate) { |
(...skipping 17 matching lines...) Expand all Loading... |
118 browser_->profile()->GetOriginalProfile()->GetProfileSyncService(); | 118 browser_->profile()->GetOriginalProfile()->GetProfileSyncService(); |
119 service->ShowLoginDialog(); | 119 service->ShowLoginDialog(); |
120 } else { | 120 } else { |
121 delegate_->OnSyncSetupResult(false); | 121 delegate_->OnSyncSetupResult(false); |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 void AppNotifyChannelUIImpl::OnStateChanged() { | 125 void AppNotifyChannelUIImpl::OnStateChanged() { |
126 ProfileSyncService* sync_service = | 126 ProfileSyncService* sync_service = |
127 browser_->profile()->GetProfileSyncService(); | 127 browser_->profile()->GetProfileSyncService(); |
128 bool finished = got_first_sync_callback_ && !sync_service->SetupInProgress(); | 128 bool wizard_visible = sync_service->WizardIsVisible(); |
129 got_first_sync_callback_ = true; | 129 // ProfileSyncService raises OnStateChanged many times. Even multiple |
| 130 // 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 |
| 132 // wait for it to get dismissed. |
| 133 bool finished = wizard_shown_to_user_ && !wizard_visible; |
| 134 if (wizard_visible) |
| 135 wizard_shown_to_user_ = true; |
130 | 136 |
131 if (finished) { | 137 if (finished) { |
132 StopObservingSync(); | 138 StopObservingSync(); |
133 delegate_->OnSyncSetupResult(sync_service->HasSyncSetupCompleted()); | 139 delegate_->OnSyncSetupResult(sync_service->HasSyncSetupCompleted()); |
134 } | 140 } |
135 } | 141 } |
136 | 142 |
137 void AppNotifyChannelUIImpl::StartObservingSync() { | 143 void AppNotifyChannelUIImpl::StartObservingSync() { |
138 CHECK(!observing_sync_); | 144 CHECK(!observing_sync_); |
139 observing_sync_ = true; | 145 observing_sync_ = true; |
140 browser_->profile()->GetProfileSyncService()->AddObserver(this); | 146 browser_->profile()->GetProfileSyncService()->AddObserver(this); |
141 } | 147 } |
142 | 148 |
143 void AppNotifyChannelUIImpl::StopObservingSync() { | 149 void AppNotifyChannelUIImpl::StopObservingSync() { |
144 CHECK(observing_sync_); | 150 CHECK(observing_sync_); |
145 observing_sync_ = false; | 151 observing_sync_ = false; |
146 browser_->profile()->GetProfileSyncService()->RemoveObserver(this); | 152 browser_->profile()->GetProfileSyncService()->RemoveObserver(this); |
147 } | 153 } |
OLD | NEW |