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/ui/app_list/app_list_view_delegate.h" | 5 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 23 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
24 #include "chrome/browser/ui/app_list/search/search_controller.h" | 24 #include "chrome/browser/ui/app_list/search/search_controller.h" |
25 #include "chrome/browser/ui/app_list/start_page_service.h" | 25 #include "chrome/browser/ui/app_list/start_page_service.h" |
26 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
27 #include "chrome/browser/ui/chrome_pages.h" | 27 #include "chrome/browser/ui/chrome_pages.h" |
28 #include "chrome/browser/ui/host_desktop.h" | 28 #include "chrome/browser/ui/host_desktop.h" |
29 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 29 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
30 #include "chrome/browser/web_applications/web_app.h" | 30 #include "chrome/browser/web_applications/web_app.h" |
31 #include "chrome/common/extensions/extension_constants.h" | 31 #include "chrome/common/extensions/extension_constants.h" |
32 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 33 #include "components/signin/core/browser/signin_manager.h" |
33 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/page_navigator.h" | 35 #include "content/public/browser/page_navigator.h" |
35 #include "content/public/browser/user_metrics.h" | 36 #include "content/public/browser/user_metrics.h" |
36 #include "grit/theme_resources.h" | 37 #include "grit/theme_resources.h" |
37 #include "ui/app_list/app_list_switches.h" | 38 #include "ui/app_list/app_list_switches.h" |
38 #include "ui/app_list/app_list_view_delegate_observer.h" | 39 #include "ui/app_list/app_list_view_delegate_observer.h" |
39 #include "ui/app_list/search_box_model.h" | 40 #include "ui/app_list/search_box_model.h" |
40 #include "ui/app_list/speech_ui_model.h" | 41 #include "ui/app_list/speech_ui_model.h" |
41 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
42 | 43 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 user.profile_path = profile_info.GetPathOfProfileAtIndex(i); | 97 user.profile_path = profile_info.GetPathOfProfileAtIndex(i); |
97 user.active = active_profile_path == user.profile_path; | 98 user.active = active_profile_path == user.profile_path; |
98 users->push_back(user); | 99 users->push_back(user); |
99 } | 100 } |
100 } | 101 } |
101 | 102 |
102 } // namespace | 103 } // namespace |
103 | 104 |
104 AppListViewDelegate::AppListViewDelegate(Profile* profile, | 105 AppListViewDelegate::AppListViewDelegate(Profile* profile, |
105 AppListControllerDelegate* controller) | 106 AppListControllerDelegate* controller) |
106 : controller_(controller), profile_(profile), model_(NULL) { | 107 : controller_(controller), |
| 108 profile_(profile), |
| 109 model_(NULL), |
| 110 scoped_observer_(this) { |
107 CHECK(controller_); | 111 CHECK(controller_); |
| 112 // The SigninManagerFactor and the SigninManagers are observed to keep the |
| 113 // profile switcher menu up to date, with the correct list of profiles and the |
| 114 // correct email address (or none for signed out users) for each. |
| 115 SigninManagerFactory::GetInstance()->AddObserver(this); |
108 | 116 |
| 117 // Start observing all already-created SigninManagers. |
109 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 118 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 119 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
| 120 for (std::vector<Profile*>::iterator i = profiles.begin(); |
| 121 i != profiles.end(); |
| 122 ++i) { |
| 123 SigninManagerBase* manager = |
| 124 SigninManagerFactory::GetForProfileIfExists(*i); |
| 125 if (manager) { |
| 126 DCHECK(!scoped_observer_.IsObserving(manager)); |
| 127 scoped_observer_.Add(manager); |
| 128 } |
| 129 } |
| 130 |
110 profile_manager->GetProfileInfoCache().AddObserver(this); | 131 profile_manager->GetProfileInfoCache().AddObserver(this); |
111 | 132 |
112 app_list::StartPageService* service = | 133 app_list::StartPageService* service = |
113 app_list::StartPageService::Get(profile_); | 134 app_list::StartPageService::Get(profile_); |
114 speech_ui_.reset(new app_list::SpeechUIModel( | 135 speech_ui_.reset(new app_list::SpeechUIModel( |
115 service ? service->state() : app_list::SPEECH_RECOGNITION_OFF)); | 136 service ? service->state() : app_list::SPEECH_RECOGNITION_OFF)); |
116 | 137 |
117 #if defined(GOOGLE_CHROME_BUILD) | 138 #if defined(GOOGLE_CHROME_BUILD) |
118 speech_ui_->set_logo( | 139 speech_ui_->set_logo( |
119 *ui::ResourceBundle::GetSharedInstance(). | 140 *ui::ResourceBundle::GetSharedInstance(). |
120 GetImageSkiaNamed(IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH)); | 141 GetImageSkiaNamed(IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH)); |
121 #endif | 142 #endif |
122 | 143 |
123 OnProfileChanged(); // sets model_ | 144 OnProfileChanged(); // sets model_ |
124 if (service) | 145 if (service) |
125 service->AddObserver(this); | 146 service->AddObserver(this); |
126 } | 147 } |
127 | 148 |
128 AppListViewDelegate::~AppListViewDelegate() { | 149 AppListViewDelegate::~AppListViewDelegate() { |
129 app_list::StartPageService* service = | 150 app_list::StartPageService* service = |
130 app_list::StartPageService::Get(profile_); | 151 app_list::StartPageService::Get(profile_); |
131 if (service) | 152 if (service) |
132 service->RemoveObserver(this); | 153 service->RemoveObserver(this); |
133 g_browser_process-> | 154 g_browser_process-> |
134 profile_manager()->GetProfileInfoCache().RemoveObserver(this); | 155 profile_manager()->GetProfileInfoCache().RemoveObserver(this); |
135 | 156 |
| 157 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); |
| 158 if (factory) |
| 159 factory->RemoveObserver(this); |
| 160 |
136 // Ensure search controller is released prior to speech_ui_. | 161 // Ensure search controller is released prior to speech_ui_. |
137 search_controller_.reset(); | 162 search_controller_.reset(); |
138 } | 163 } |
139 | 164 |
140 void AppListViewDelegate::OnHotwordStateChanged(bool started) { | 165 void AppListViewDelegate::OnHotwordStateChanged(bool started) { |
141 if (started) { | 166 if (started) { |
142 if (speech_ui_->state() == app_list::SPEECH_RECOGNITION_READY) { | 167 if (speech_ui_->state() == app_list::SPEECH_RECOGNITION_READY) { |
143 OnSpeechRecognitionStateChanged( | 168 OnSpeechRecognitionStateChanged( |
144 app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING); | 169 app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING); |
145 } | 170 } |
146 } else { | 171 } else { |
147 if (speech_ui_->state() == app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING) | 172 if (speech_ui_->state() == app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING) |
148 OnSpeechRecognitionStateChanged(app_list::SPEECH_RECOGNITION_READY); | 173 OnSpeechRecognitionStateChanged(app_list::SPEECH_RECOGNITION_READY); |
149 } | 174 } |
150 } | 175 } |
151 | 176 |
152 void AppListViewDelegate::OnHotwordRecognized() { | 177 void AppListViewDelegate::OnHotwordRecognized() { |
153 DCHECK_EQ(app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING, | 178 DCHECK_EQ(app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING, |
154 speech_ui_->state()); | 179 speech_ui_->state()); |
155 ToggleSpeechRecognition(); | 180 ToggleSpeechRecognition(); |
156 } | 181 } |
157 | 182 |
| 183 void AppListViewDelegate::SigninManagerCreated(SigninManagerBase* manager) { |
| 184 scoped_observer_.Add(manager); |
| 185 } |
| 186 |
| 187 void AppListViewDelegate::SigninManagerShutdown(SigninManagerBase* manager) { |
| 188 if (scoped_observer_.IsObserving(manager)) |
| 189 scoped_observer_.Remove(manager); |
| 190 } |
| 191 |
| 192 void AppListViewDelegate::GoogleSigninFailed( |
| 193 const GoogleServiceAuthError& error) { |
| 194 OnProfileChanged(); |
| 195 } |
| 196 |
| 197 void AppListViewDelegate::GoogleSigninSucceeded(const std::string& username, |
| 198 const std::string& password) { |
| 199 OnProfileChanged(); |
| 200 } |
| 201 |
| 202 void AppListViewDelegate::GoogleSignedOut(const std::string& username) { |
| 203 OnProfileChanged(); |
| 204 } |
| 205 |
158 void AppListViewDelegate::OnProfileChanged() { | 206 void AppListViewDelegate::OnProfileChanged() { |
159 model_ = app_list::AppListSyncableServiceFactory::GetForProfile( | 207 model_ = app_list::AppListSyncableServiceFactory::GetForProfile( |
160 profile_)->model(); | 208 profile_)->model(); |
161 | 209 |
162 search_controller_.reset(new app_list::SearchController( | 210 search_controller_.reset(new app_list::SearchController( |
163 profile_, model_->search_box(), model_->results(), | 211 profile_, model_->search_box(), model_->results(), |
164 speech_ui_.get(), controller_)); | 212 speech_ui_.get(), controller_)); |
165 | 213 |
166 #if defined(USE_ASH) | 214 #if defined(USE_ASH) |
167 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, model_)); | 215 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, model_)); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 495 |
448 void AppListViewDelegate::AddObserver( | 496 void AppListViewDelegate::AddObserver( |
449 app_list::AppListViewDelegateObserver* observer) { | 497 app_list::AppListViewDelegateObserver* observer) { |
450 observers_.AddObserver(observer); | 498 observers_.AddObserver(observer); |
451 } | 499 } |
452 | 500 |
453 void AppListViewDelegate::RemoveObserver( | 501 void AppListViewDelegate::RemoveObserver( |
454 app_list::AppListViewDelegateObserver* observer) { | 502 app_list::AppListViewDelegateObserver* observer) { |
455 observers_.RemoveObserver(observer); | 503 observers_.RemoveObserver(observer); |
456 } | 504 } |
OLD | NEW |