| 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 "apps/custom_launcher_page_contents.h" | 9 #include "apps/custom_launcher_page_contents.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 150 } |
| 151 urls->push_back(extension->GetResourceURL(launcher_page_page)); | 151 urls->push_back(extension->GetResourceURL(launcher_page_page)); |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 } // namespace | 155 } // namespace |
| 156 | 156 |
| 157 AppListViewDelegate::AppListViewDelegate(Profile* profile, | 157 AppListViewDelegate::AppListViewDelegate(Profile* profile, |
| 158 AppListControllerDelegate* controller) | 158 AppListControllerDelegate* controller) |
| 159 : controller_(controller), | 159 : controller_(controller), |
| 160 profile_(profile), | 160 profile_(NULL), |
| 161 model_(NULL), | 161 model_(NULL), |
| 162 scoped_observer_(this) { | 162 scoped_observer_(this) { |
| 163 CHECK(controller_); | 163 CHECK(controller_); |
| 164 // The SigninManagerFactor and the SigninManagers are observed to keep the | 164 // The SigninManagerFactor and the SigninManagers are observed to keep the |
| 165 // profile switcher menu up to date, with the correct list of profiles and the | 165 // profile switcher menu up to date, with the correct list of profiles and the |
| 166 // correct email address (or none for signed out users) for each. | 166 // correct email address (or none for signed out users) for each. |
| 167 SigninManagerFactory::GetInstance()->AddObserver(this); | 167 SigninManagerFactory::GetInstance()->AddObserver(this); |
| 168 | 168 |
| 169 // Start observing all already-created SigninManagers. | 169 // Start observing all already-created SigninManagers. |
| 170 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 170 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 171 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | 171 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
| 172 for (std::vector<Profile*>::iterator i = profiles.begin(); | 172 for (std::vector<Profile*>::iterator i = profiles.begin(); |
| 173 i != profiles.end(); | 173 i != profiles.end(); |
| 174 ++i) { | 174 ++i) { |
| 175 SigninManagerBase* manager = | 175 SigninManagerBase* manager = |
| 176 SigninManagerFactory::GetForProfileIfExists(*i); | 176 SigninManagerFactory::GetForProfileIfExists(*i); |
| 177 if (manager) { | 177 if (manager) { |
| 178 DCHECK(!scoped_observer_.IsObserving(manager)); | 178 DCHECK(!scoped_observer_.IsObserving(manager)); |
| 179 scoped_observer_.Add(manager); | 179 scoped_observer_.Add(manager); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 profile_manager->GetProfileInfoCache().AddObserver(this); | 183 profile_manager->GetProfileInfoCache().AddObserver(this); |
| 184 SetProfile(profile); |
| 185 } |
| 184 | 186 |
| 185 app_list::StartPageService* service = | 187 AppListViewDelegate::~AppListViewDelegate() { |
| 188 SetProfile(NULL); |
| 189 g_browser_process->profile_manager()->GetProfileInfoCache().RemoveObserver( |
| 190 this); |
| 191 |
| 192 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); |
| 193 if (factory) |
| 194 factory->RemoveObserver(this); |
| 195 } |
| 196 |
| 197 void AppListViewDelegate::SetProfile(Profile* new_profile) { |
| 198 if (profile_) { |
| 199 // Note: |search_controller_| has a reference to |speech_ui_| so must be |
| 200 // destroyed first. |
| 201 search_controller_.reset(); |
| 202 speech_ui_.reset(); |
| 203 custom_page_contents_.clear(); |
| 204 app_list::StartPageService* start_page_service = |
| 205 app_list::StartPageService::Get(profile_); |
| 206 if (start_page_service) |
| 207 start_page_service->RemoveObserver(this); |
| 208 #if defined(USE_ASH) |
| 209 app_sync_ui_state_watcher_.reset(); |
| 210 #endif |
| 211 model_ = NULL; |
| 212 } |
| 213 |
| 214 profile_ = new_profile; |
| 215 if (!profile_) |
| 216 return; |
| 217 |
| 218 model_ = |
| 219 app_list::AppListSyncableServiceFactory::GetForProfile(profile_)->model(); |
| 220 |
| 221 #if defined(USE_ASH) |
| 222 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, model_)); |
| 223 #endif |
| 224 |
| 225 SetUpSearchUI(); |
| 226 SetUpProfileSwitcher(); |
| 227 SetUpCustomLauncherPages(); |
| 228 |
| 229 // Clear search query. |
| 230 model_->search_box()->SetText(base::string16()); |
| 231 } |
| 232 |
| 233 void AppListViewDelegate::SetUpSearchUI() { |
| 234 app_list::StartPageService* start_page_service = |
| 186 app_list::StartPageService::Get(profile_); | 235 app_list::StartPageService::Get(profile_); |
| 236 if (start_page_service) |
| 237 start_page_service->AddObserver(this); |
| 238 |
| 187 speech_ui_.reset(new app_list::SpeechUIModel( | 239 speech_ui_.reset(new app_list::SpeechUIModel( |
| 188 service ? service->state() : app_list::SPEECH_RECOGNITION_OFF)); | 240 start_page_service ? start_page_service->state() |
| 241 : app_list::SPEECH_RECOGNITION_OFF)); |
| 189 | 242 |
| 190 #if defined(GOOGLE_CHROME_BUILD) | 243 #if defined(GOOGLE_CHROME_BUILD) |
| 191 speech_ui_->set_logo( | 244 speech_ui_->set_logo( |
| 192 *ui::ResourceBundle::GetSharedInstance(). | 245 *ui::ResourceBundle::GetSharedInstance(). |
| 193 GetImageSkiaNamed(IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH)); | 246 GetImageSkiaNamed(IDR_APP_LIST_GOOGLE_LOGO_VOICE_SEARCH)); |
| 194 #endif | 247 #endif |
| 195 | 248 |
| 196 OnProfileChanged(); // sets model_ | 249 search_controller_.reset(new app_list::SearchController(profile_, |
| 197 if (service) | 250 model_->search_box(), |
| 198 service->AddObserver(this); | 251 model_->results(), |
| 252 speech_ui_.get(), |
| 253 controller_)); |
| 254 } |
| 199 | 255 |
| 200 // Set up the custom launcher pages. | 256 void AppListViewDelegate::SetUpProfileSwitcher() { |
| 257 // Don't populate the app list users if we are on the ash desktop. |
| 258 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 259 controller_->GetAppListWindow()); |
| 260 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) |
| 261 return; |
| 262 |
| 263 // Populate the app list users. |
| 264 PopulateUsers(g_browser_process->profile_manager()->GetProfileInfoCache(), |
| 265 profile_->GetPath(), |
| 266 &users_); |
| 267 |
| 268 FOR_EACH_OBSERVER( |
| 269 app_list::AppListViewDelegateObserver, observers_, OnProfilesChanged()); |
| 270 } |
| 271 |
| 272 void AppListViewDelegate::SetUpCustomLauncherPages() { |
| 201 std::vector<GURL> custom_launcher_page_urls; | 273 std::vector<GURL> custom_launcher_page_urls; |
| 202 GetCustomLauncherPageUrls(profile, &custom_launcher_page_urls); | 274 GetCustomLauncherPageUrls(profile_, &custom_launcher_page_urls); |
| 203 for (std::vector<GURL>::const_iterator it = custom_launcher_page_urls.begin(); | 275 for (std::vector<GURL>::const_iterator it = custom_launcher_page_urls.begin(); |
| 204 it != custom_launcher_page_urls.end(); | 276 it != custom_launcher_page_urls.end(); |
| 205 ++it) { | 277 ++it) { |
| 206 std::string extension_id = it->host(); | 278 std::string extension_id = it->host(); |
| 207 apps::CustomLauncherPageContents* page_contents = | 279 apps::CustomLauncherPageContents* page_contents = |
| 208 new apps::CustomLauncherPageContents( | 280 new apps::CustomLauncherPageContents( |
| 209 scoped_ptr<extensions::AppDelegate>(new ChromeAppDelegate), | 281 scoped_ptr<extensions::AppDelegate>(new ChromeAppDelegate), |
| 210 extension_id); | 282 extension_id); |
| 211 page_contents->Initialize(profile, *it); | 283 page_contents->Initialize(profile_, *it); |
| 212 custom_page_contents_.push_back(page_contents); | 284 custom_page_contents_.push_back(page_contents); |
| 213 } | 285 } |
| 214 } | 286 } |
| 215 | 287 |
| 216 AppListViewDelegate::~AppListViewDelegate() { | |
| 217 app_list::StartPageService* service = | |
| 218 app_list::StartPageService::Get(profile_); | |
| 219 if (service) | |
| 220 service->RemoveObserver(this); | |
| 221 g_browser_process-> | |
| 222 profile_manager()->GetProfileInfoCache().RemoveObserver(this); | |
| 223 | |
| 224 SigninManagerFactory* factory = SigninManagerFactory::GetInstance(); | |
| 225 if (factory) | |
| 226 factory->RemoveObserver(this); | |
| 227 | |
| 228 // Ensure search controller is released prior to speech_ui_. | |
| 229 search_controller_.reset(); | |
| 230 } | |
| 231 | |
| 232 void AppListViewDelegate::OnHotwordStateChanged(bool started) { | 288 void AppListViewDelegate::OnHotwordStateChanged(bool started) { |
| 233 if (started) { | 289 if (started) { |
| 234 if (speech_ui_->state() == app_list::SPEECH_RECOGNITION_READY) { | 290 if (speech_ui_->state() == app_list::SPEECH_RECOGNITION_READY) { |
| 235 OnSpeechRecognitionStateChanged( | 291 OnSpeechRecognitionStateChanged( |
| 236 app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING); | 292 app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING); |
| 237 } | 293 } |
| 238 } else { | 294 } else { |
| 239 if (speech_ui_->state() == app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING) | 295 if (speech_ui_->state() == app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING) |
| 240 OnSpeechRecognitionStateChanged(app_list::SPEECH_RECOGNITION_READY); | 296 OnSpeechRecognitionStateChanged(app_list::SPEECH_RECOGNITION_READY); |
| 241 } | 297 } |
| 242 } | 298 } |
| 243 | 299 |
| 244 void AppListViewDelegate::OnHotwordRecognized() { | 300 void AppListViewDelegate::OnHotwordRecognized() { |
| 245 DCHECK_EQ(app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING, | 301 DCHECK_EQ(app_list::SPEECH_RECOGNITION_HOTWORD_LISTENING, |
| 246 speech_ui_->state()); | 302 speech_ui_->state()); |
| 247 ToggleSpeechRecognition(); | 303 ToggleSpeechRecognition(); |
| 248 } | 304 } |
| 249 | 305 |
| 250 void AppListViewDelegate::SigninManagerCreated(SigninManagerBase* manager) { | 306 void AppListViewDelegate::SigninManagerCreated(SigninManagerBase* manager) { |
| 251 scoped_observer_.Add(manager); | 307 scoped_observer_.Add(manager); |
| 252 } | 308 } |
| 253 | 309 |
| 254 void AppListViewDelegate::SigninManagerShutdown(SigninManagerBase* manager) { | 310 void AppListViewDelegate::SigninManagerShutdown(SigninManagerBase* manager) { |
| 255 if (scoped_observer_.IsObserving(manager)) | 311 if (scoped_observer_.IsObserving(manager)) |
| 256 scoped_observer_.Remove(manager); | 312 scoped_observer_.Remove(manager); |
| 257 } | 313 } |
| 258 | 314 |
| 259 void AppListViewDelegate::GoogleSigninFailed( | 315 void AppListViewDelegate::GoogleSigninFailed( |
| 260 const GoogleServiceAuthError& error) { | 316 const GoogleServiceAuthError& error) { |
| 261 OnProfileChanged(); | 317 SetUpProfileSwitcher(); |
| 262 } | 318 } |
| 263 | 319 |
| 264 void AppListViewDelegate::GoogleSigninSucceeded(const std::string& username, | 320 void AppListViewDelegate::GoogleSigninSucceeded(const std::string& username, |
| 265 const std::string& password) { | 321 const std::string& password) { |
| 266 OnProfileChanged(); | 322 SetUpProfileSwitcher(); |
| 267 } | 323 } |
| 268 | 324 |
| 269 void AppListViewDelegate::GoogleSignedOut(const std::string& username) { | 325 void AppListViewDelegate::GoogleSignedOut(const std::string& username) { |
| 270 OnProfileChanged(); | 326 SetUpProfileSwitcher(); |
| 271 } | 327 } |
| 272 | 328 |
| 273 void AppListViewDelegate::OnProfileChanged() { | 329 void AppListViewDelegate::OnProfileAdded(const base::FilePath& profile_path) { |
| 274 model_ = app_list::AppListSyncableServiceFactory::GetForProfile( | 330 SetUpProfileSwitcher(); |
| 275 profile_)->model(); | 331 } |
| 276 | 332 |
| 277 search_controller_.reset(new app_list::SearchController( | 333 void AppListViewDelegate::OnProfileWasRemoved( |
| 278 profile_, model_->search_box(), model_->results(), | 334 const base::FilePath& profile_path, |
| 279 speech_ui_.get(), controller_)); | 335 const base::string16& profile_name) { |
| 336 SetUpProfileSwitcher(); |
| 337 } |
| 280 | 338 |
| 281 #if defined(USE_ASH) | 339 void AppListViewDelegate::OnProfileNameChanged( |
| 282 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, model_)); | 340 const base::FilePath& profile_path, |
| 283 #endif | 341 const base::string16& old_profile_name) { |
| 284 | 342 SetUpProfileSwitcher(); |
| 285 // Don't populate the app list users if we are on the ash desktop. | |
| 286 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | |
| 287 controller_->GetAppListWindow()); | |
| 288 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) | |
| 289 return; | |
| 290 | |
| 291 // Populate the app list users. | |
| 292 PopulateUsers(g_browser_process->profile_manager()->GetProfileInfoCache(), | |
| 293 profile_->GetPath(), &users_); | |
| 294 | |
| 295 FOR_EACH_OBSERVER(app_list::AppListViewDelegateObserver, | |
| 296 observers_, | |
| 297 OnProfilesChanged()); | |
| 298 } | 343 } |
| 299 | 344 |
| 300 bool AppListViewDelegate::ForceNativeDesktop() const { | 345 bool AppListViewDelegate::ForceNativeDesktop() const { |
| 301 return controller_->ForceNativeDesktop(); | 346 return controller_->ForceNativeDesktop(); |
| 302 } | 347 } |
| 303 | 348 |
| 304 void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) { | 349 void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) { |
| 305 DCHECK(model_); | 350 DCHECK(model_); |
| 306 | |
| 307 // The profile must be loaded before this is called. | 351 // The profile must be loaded before this is called. |
| 308 profile_ = | 352 SetProfile( |
| 309 g_browser_process->profile_manager()->GetProfileByPath(profile_path); | 353 g_browser_process->profile_manager()->GetProfileByPath(profile_path)); |
| 310 DCHECK(profile_); | |
| 311 | |
| 312 OnProfileChanged(); | |
| 313 | |
| 314 // Clear search query. | |
| 315 model_->search_box()->SetText(base::string16()); | |
| 316 } | 354 } |
| 317 | 355 |
| 318 app_list::AppListModel* AppListViewDelegate::GetModel() { | 356 app_list::AppListModel* AppListViewDelegate::GetModel() { |
| 319 return model_; | 357 return model_; |
| 320 } | 358 } |
| 321 | 359 |
| 322 app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() { | 360 app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() { |
| 323 return speech_ui_.get(); | 361 return speech_ui_.get(); |
| 324 } | 362 } |
| 325 | 363 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 HotwordService::IsExperimentalHotwordingEnabled() && | 530 HotwordService::IsExperimentalHotwordingEnabled() && |
| 493 service && service->HotwordEnabled()) { | 531 service && service->HotwordEnabled()) { |
| 494 HotwordService* hotword_service = | 532 HotwordService* hotword_service = |
| 495 HotwordServiceFactory::GetForProfile(profile_); | 533 HotwordServiceFactory::GetForProfile(profile_); |
| 496 if (hotword_service) { | 534 if (hotword_service) { |
| 497 hotword_service->RequestHotwordSession(this); | 535 hotword_service->RequestHotwordSession(this); |
| 498 } | 536 } |
| 499 } | 537 } |
| 500 } | 538 } |
| 501 | 539 |
| 502 void AppListViewDelegate::OnProfileAdded(const base::FilePath& profile_path) { | |
| 503 OnProfileChanged(); | |
| 504 } | |
| 505 | |
| 506 void AppListViewDelegate::OnProfileWasRemoved( | |
| 507 const base::FilePath& profile_path, const base::string16& profile_name) { | |
| 508 OnProfileChanged(); | |
| 509 } | |
| 510 | |
| 511 void AppListViewDelegate::OnProfileNameChanged( | |
| 512 const base::FilePath& profile_path, | |
| 513 const base::string16& old_profile_name) { | |
| 514 OnProfileChanged(); | |
| 515 } | |
| 516 | |
| 517 #if defined(TOOLKIT_VIEWS) | 540 #if defined(TOOLKIT_VIEWS) |
| 518 views::View* AppListViewDelegate::CreateStartPageWebView( | 541 views::View* AppListViewDelegate::CreateStartPageWebView( |
| 519 const gfx::Size& size) { | 542 const gfx::Size& size) { |
| 520 app_list::StartPageService* service = | 543 app_list::StartPageService* service = |
| 521 app_list::StartPageService::Get(profile_); | 544 app_list::StartPageService::Get(profile_); |
| 522 if (!service) | 545 if (!service) |
| 523 return NULL; | 546 return NULL; |
| 524 | 547 |
| 525 content::WebContents* web_contents = service->GetStartPageContents(); | 548 content::WebContents* web_contents = service->GetStartPageContents(); |
| 526 if (!web_contents) | 549 if (!web_contents) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 | 620 |
| 598 void AppListViewDelegate::AddObserver( | 621 void AppListViewDelegate::AddObserver( |
| 599 app_list::AppListViewDelegateObserver* observer) { | 622 app_list::AppListViewDelegateObserver* observer) { |
| 600 observers_.AddObserver(observer); | 623 observers_.AddObserver(observer); |
| 601 } | 624 } |
| 602 | 625 |
| 603 void AppListViewDelegate::RemoveObserver( | 626 void AppListViewDelegate::RemoveObserver( |
| 604 app_list::AppListViewDelegateObserver* observer) { | 627 app_list::AppListViewDelegateObserver* observer) { |
| 605 observers_.RemoveObserver(observer); | 628 observers_.RemoveObserver(observer); |
| 606 } | 629 } |
| OLD | NEW |