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" | |
34 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/page_navigator.h" | 34 #include "content/public/browser/page_navigator.h" |
36 #include "content/public/browser/user_metrics.h" | 35 #include "content/public/browser/user_metrics.h" |
37 #include "grit/theme_resources.h" | 36 #include "grit/theme_resources.h" |
38 #include "ui/app_list/app_list_switches.h" | 37 #include "ui/app_list/app_list_switches.h" |
39 #include "ui/app_list/app_list_view_delegate_observer.h" | 38 #include "ui/app_list/app_list_view_delegate_observer.h" |
40 #include "ui/app_list/search_box_model.h" | 39 #include "ui/app_list/search_box_model.h" |
41 #include "ui/app_list/speech_ui_model.h" | 40 #include "ui/app_list/speech_ui_model.h" |
42 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
43 | 42 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 const size_t count = profile_info.GetNumberOfProfiles(); | 83 const size_t count = profile_info.GetNumberOfProfiles(); |
85 for (size_t i = 0; i < count; ++i) { | 84 for (size_t i = 0; i < count; ++i) { |
86 // Don't display managed users. | 85 // Don't display managed users. |
87 if (profile_info.ProfileIsManagedAtIndex(i)) | 86 if (profile_info.ProfileIsManagedAtIndex(i)) |
88 continue; | 87 continue; |
89 | 88 |
90 app_list::AppListViewDelegate::User user; | 89 app_list::AppListViewDelegate::User user; |
91 user.name = profile_info.GetNameOfProfileAtIndex(i); | 90 user.name = profile_info.GetNameOfProfileAtIndex(i); |
92 user.email = profile_info.GetUserNameOfProfileAtIndex(i); | 91 user.email = profile_info.GetUserNameOfProfileAtIndex(i); |
93 user.profile_path = profile_info.GetPathOfProfileAtIndex(i); | 92 user.profile_path = profile_info.GetPathOfProfileAtIndex(i); |
94 user.signin_required = profile_info.ProfileIsSigninRequiredAtIndex(i); | |
95 user.active = active_profile_path == user.profile_path; | 93 user.active = active_profile_path == user.profile_path; |
96 users->push_back(user); | 94 users->push_back(user); |
97 } | 95 } |
98 } | 96 } |
99 | 97 |
100 } // namespace | 98 } // namespace |
101 | 99 |
102 AppListViewDelegate::AppListViewDelegate(Profile* profile, | 100 AppListViewDelegate::AppListViewDelegate(Profile* profile, |
103 AppListControllerDelegate* controller) | 101 AppListControllerDelegate* controller) |
104 : controller_(controller), | 102 : controller_(controller), profile_(profile), model_(NULL) { |
105 profile_(profile), | |
106 model_(NULL), | |
107 scoped_observer_(this) { | |
108 CHECK(controller_); | 103 CHECK(controller_); |
109 SigninManagerFactory::GetInstance()->AddObserver(this); | |
110 | 104 |
111 // Start observing all already-created SigninManagers. | |
112 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 105 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
113 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | |
114 for (std::vector<Profile*>::iterator i = profiles.begin(); | |
115 i != profiles.end(); | |
116 ++i) { | |
117 SigninManagerBase* manager = | |
118 SigninManagerFactory::GetForProfileIfExists(*i); | |
119 if (manager) { | |
120 DCHECK(!scoped_observer_.IsObserving(manager)); | |
121 scoped_observer_.Add(manager); | |
122 } | |
123 } | |
124 | |
125 profile_manager->GetProfileInfoCache().AddObserver(this); | 106 profile_manager->GetProfileInfoCache().AddObserver(this); |
126 | 107 |
127 app_list::StartPageService* service = | 108 app_list::StartPageService* service = |
128 app_list::StartPageService::Get(profile_); | 109 app_list::StartPageService::Get(profile_); |
129 speech_ui_.reset(new app_list::SpeechUIModel( | 110 speech_ui_.reset(new app_list::SpeechUIModel( |
130 service ? service->state() : app_list::SPEECH_RECOGNITION_OFF)); | 111 service ? service->state() : app_list::SPEECH_RECOGNITION_OFF)); |
131 | 112 |
132 #if defined(GOOGLE_CHROME_BUILD) | 113 #if defined(GOOGLE_CHROME_BUILD) |
133 speech_ui_->set_logo( | 114 speech_ui_->set_logo( |
134 *ui::ResourceBundle::GetSharedInstance(). | 115 *ui::ResourceBundle::GetSharedInstance(). |
135 GetImageSkiaNamed(IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH)); | 116 GetImageSkiaNamed(IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH)); |
136 #endif | 117 #endif |
137 | 118 |
138 OnProfileChanged(); // sets model_ | 119 OnProfileChanged(); // sets model_ |
139 if (service) | 120 if (service) |
140 service->AddObserver(this); | 121 service->AddObserver(this); |
141 } | 122 } |
142 | 123 |
143 AppListViewDelegate::~AppListViewDelegate() { | 124 AppListViewDelegate::~AppListViewDelegate() { |
144 app_list::StartPageService* service = | 125 app_list::StartPageService* service = |
145 app_list::StartPageService::Get(profile_); | 126 app_list::StartPageService::Get(profile_); |
146 if (service) | 127 if (service) |
147 service->RemoveObserver(this); | 128 service->RemoveObserver(this); |
148 g_browser_process-> | 129 g_browser_process-> |
149 profile_manager()->GetProfileInfoCache().RemoveObserver(this); | 130 profile_manager()->GetProfileInfoCache().RemoveObserver(this); |
150 | 131 |
151 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); | |
152 if (factory) | |
153 factory->RemoveObserver(this); | |
154 | |
155 // Ensure search controller is released prior to speech_ui_. | 132 // Ensure search controller is released prior to speech_ui_. |
156 search_controller_.reset(); | 133 search_controller_.reset(); |
157 } | 134 } |
158 | 135 |
159 void AppListViewDelegate::OnHotwordStateChanged(bool started) { | 136 void AppListViewDelegate::OnHotwordStateChanged(bool started) { |
160 if (started) { | 137 if (started) { |
161 if (speech_ui_->state() == app_list::SPEECH_RECOGNITION_READY) { | 138 if (speech_ui_->state() == app_list::SPEECH_RECOGNITION_READY) { |
162 OnSpeechRecognitionStateChanged( | 139 OnSpeechRecognitionStateChanged( |
163 app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING); | 140 app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING); |
164 } | 141 } |
165 } else { | 142 } else { |
166 if (speech_ui_->state() == app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING) | 143 if (speech_ui_->state() == app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING) |
167 OnSpeechRecognitionStateChanged(app_list::SPEECH_RECOGNITION_READY); | 144 OnSpeechRecognitionStateChanged(app_list::SPEECH_RECOGNITION_READY); |
168 } | 145 } |
169 } | 146 } |
170 | 147 |
171 void AppListViewDelegate::OnHotwordRecognized() { | 148 void AppListViewDelegate::OnHotwordRecognized() { |
172 DCHECK_EQ(app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING, | 149 DCHECK_EQ(app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING, |
173 speech_ui_->state()); | 150 speech_ui_->state()); |
174 ToggleSpeechRecognition(); | 151 ToggleSpeechRecognition(); |
175 } | 152 } |
176 | 153 |
177 void AppListViewDelegate::SigninManagerCreated(SigninManagerBase* manager) { | |
178 scoped_observer_.Add(manager); | |
179 } | |
180 | |
181 void AppListViewDelegate::SigninManagerShutdown(SigninManagerBase* manager) { | |
182 if (scoped_observer_.IsObserving(manager)) | |
183 scoped_observer_.Remove(manager); | |
184 } | |
185 | |
186 void AppListViewDelegate::GoogleSigninFailed( | |
187 const GoogleServiceAuthError& error) { | |
188 OnProfileChanged(); | |
189 } | |
190 | |
191 void AppListViewDelegate::GoogleSigninSucceeded(const std::string& username, | |
192 const std::string& password) { | |
193 OnProfileChanged(); | |
tapted
2014/06/03 08:41:02
Removing this will mean that the profile switching
| |
194 } | |
195 | |
196 void AppListViewDelegate::GoogleSignedOut(const std::string& username) { | |
197 OnProfileChanged(); | |
198 } | |
199 | |
200 void AppListViewDelegate::OnProfileChanged() { | 154 void AppListViewDelegate::OnProfileChanged() { |
201 model_ = app_list::AppListSyncableServiceFactory::GetForProfile( | 155 model_ = app_list::AppListSyncableServiceFactory::GetForProfile( |
202 profile_)->model(); | 156 profile_)->model(); |
203 | 157 |
204 search_controller_.reset(new app_list::SearchController( | 158 search_controller_.reset(new app_list::SearchController( |
205 profile_, model_->search_box(), model_->results(), | 159 profile_, model_->search_box(), model_->results(), |
206 speech_ui_.get(), controller_)); | 160 speech_ui_.get(), controller_)); |
207 | 161 |
208 signin_delegate_.SetProfile(profile_); | |
209 | |
210 #if defined(USE_ASH) | 162 #if defined(USE_ASH) |
211 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, model_)); | 163 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, model_)); |
212 #endif | 164 #endif |
213 | 165 |
214 // Don't populate the app list users if we are on the ash desktop. | 166 // Don't populate the app list users if we are on the ash desktop. |
215 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 167 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
216 controller_->GetAppListWindow()); | 168 controller_->GetAppListWindow()); |
217 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) | 169 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) |
218 return; | 170 return; |
219 | 171 |
(...skipping 21 matching lines...) Expand all Loading... | |
241 OnProfileChanged(); | 193 OnProfileChanged(); |
242 | 194 |
243 // Clear search query. | 195 // Clear search query. |
244 model_->search_box()->SetText(base::string16()); | 196 model_->search_box()->SetText(base::string16()); |
245 } | 197 } |
246 | 198 |
247 app_list::AppListModel* AppListViewDelegate::GetModel() { | 199 app_list::AppListModel* AppListViewDelegate::GetModel() { |
248 return model_; | 200 return model_; |
249 } | 201 } |
250 | 202 |
251 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { | |
252 return &signin_delegate_; | |
253 } | |
254 | |
255 app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() { | 203 app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() { |
256 return speech_ui_.get(); | 204 return speech_ui_.get(); |
257 } | 205 } |
258 | 206 |
259 void AppListViewDelegate::GetShortcutPathForApp( | 207 void AppListViewDelegate::GetShortcutPathForApp( |
260 const std::string& app_id, | 208 const std::string& app_id, |
261 const base::Callback<void(const base::FilePath&)>& callback) { | 209 const base::Callback<void(const base::FilePath&)>& callback) { |
262 #if defined(OS_WIN) | 210 #if defined(OS_WIN) |
263 ExtensionService* service = profile_->GetExtensionService(); | 211 ExtensionService* service = profile_->GetExtensionService(); |
264 DCHECK(service); | 212 DCHECK(service); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 | 435 |
488 void AppListViewDelegate::AddObserver( | 436 void AppListViewDelegate::AddObserver( |
489 app_list::AppListViewDelegateObserver* observer) { | 437 app_list::AppListViewDelegateObserver* observer) { |
490 observers_.AddObserver(observer); | 438 observers_.AddObserver(observer); |
491 } | 439 } |
492 | 440 |
493 void AppListViewDelegate::RemoveObserver( | 441 void AppListViewDelegate::RemoveObserver( |
494 app_list::AppListViewDelegateObserver* observer) { | 442 app_list::AppListViewDelegateObserver* observer) { |
495 observers_.RemoveObserver(observer); | 443 observers_.RemoveObserver(observer); |
496 } | 444 } |
OLD | NEW |