Chromium Code Reviews| 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 "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | |
| 10 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/feedback/feedback_util.h" | 12 #include "chrome/browser/feedback/feedback_util.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 14 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| 14 #include "chrome/browser/ui/app_list/apps_model_builder.h" | 15 #include "chrome/browser/ui/app_list/apps_model_builder.h" |
| 15 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" | 16 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" |
| 16 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h" | 17 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h" |
| 17 #include "chrome/browser/ui/app_list/search/search_controller.h" | 18 #include "chrome/browser/ui/app_list/search/search_controller.h" |
| 18 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
| 19 #include "chrome/browser/ui/chrome_pages.h" | 20 #include "chrome/browser/ui/chrome_pages.h" |
| 20 #include "chrome/browser/ui/host_desktop.h" | 21 #include "chrome/browser/ui/host_desktop.h" |
| 21 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 22 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| 22 #include "chrome/browser/web_applications/web_app.h" | 23 #include "chrome/browser/web_applications/web_app.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/notification_details.h" | |
| 28 #include "content/public/browser/notification_service.h" | |
| 29 #include "content/public/browser/notification_source.h" | |
| 26 #include "content/public/browser/page_navigator.h" | 30 #include "content/public/browser/page_navigator.h" |
| 27 #include "content/public/browser/user_metrics.h" | 31 #include "content/public/browser/user_metrics.h" |
| 28 | 32 |
| 29 #if defined(USE_ASH) | 33 #if defined(USE_ASH) |
| 30 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" | 34 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" |
| 31 #endif | 35 #endif |
| 32 | 36 |
| 33 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
| 34 #include "chrome/browser/web_applications/web_app_win.h" | 38 #include "chrome/browser/web_applications/web_app_win.h" |
| 35 #endif | 39 #endif |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 47 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info), | 51 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info), |
| 48 callback); | 52 callback); |
| 49 } | 53 } |
| 50 #endif | 54 #endif |
| 51 | 55 |
| 52 } // namespace | 56 } // namespace |
| 53 | 57 |
| 54 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, | 58 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, |
| 55 Profile* profile) | 59 Profile* profile) |
| 56 : controller_(controller), | 60 : controller_(controller), |
| 57 profile_(profile) {} | 61 profile_(profile), |
| 62 model_(NULL) { | |
| 63 DCHECK(profile_); | |
| 64 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | |
| 65 content::NotificationService::AllSources()); | |
| 66 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | |
| 67 content::Source<Profile>(profile_)); | |
| 68 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, | |
| 69 content::Source<Profile>(profile_)); | |
| 70 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | |
| 71 content::Source<Profile>(profile_)); | |
| 72 } | |
| 58 | 73 |
| 59 AppListViewDelegate::~AppListViewDelegate() {} | 74 AppListViewDelegate::~AppListViewDelegate() { |
| 75 if (signin_delegate_.get()) | |
| 76 signin_delegate_->RemoveObserver(this); | |
| 77 } | |
| 78 | |
| 79 void AppListViewDelegate::OnProfileChanged() { | |
| 80 model_->SetSignedIn(!signin_delegate_->NeedSignin()); | |
| 81 ProfileInfoCache& cache = | |
| 82 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 83 // Populate the current user details. | |
| 84 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | |
| 85 // The profile won't exist in the cache if the current app list profile is | |
| 86 // being deleted. | |
| 87 if (profile_index == std::string::npos) | |
|
xiyuan
2013/08/08 01:52:06
Do you need to reset the current user info when th
calamity
2013/08/08 06:29:40
Nope. When the app list is next shown, the last us
| |
| 88 return; | |
| 89 | |
| 90 model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index), | |
| 91 cache.GetUserNameOfProfileAtIndex(profile_index)); | |
| 92 } | |
| 60 | 93 |
| 61 void AppListViewDelegate::SetModel(app_list::AppListModel* model) { | 94 void AppListViewDelegate::SetModel(app_list::AppListModel* model) { |
| 95 if (signin_delegate_.get()) | |
| 96 signin_delegate_->RemoveObserver(this); | |
| 62 if (model) { | 97 if (model) { |
| 98 model_ = model; | |
| 63 apps_builder_.reset(new AppsModelBuilder(profile_, | 99 apps_builder_.reset(new AppsModelBuilder(profile_, |
| 64 model->apps(), | 100 model->apps(), |
| 65 controller_.get())); | 101 controller_.get())); |
| 66 apps_builder_->Build(); | 102 apps_builder_->Build(); |
| 67 | 103 |
| 68 search_controller_.reset(new app_list::SearchController( | 104 search_controller_.reset(new app_list::SearchController( |
| 69 profile_, model->search_box(), model->results(), controller_.get())); | 105 profile_, model->search_box(), model->results(), controller_.get())); |
| 70 | 106 |
| 71 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); | 107 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); |
| 108 signin_delegate_->AddObserver(this); | |
| 72 | 109 |
| 73 #if defined(USE_ASH) | 110 #if defined(USE_ASH) |
| 74 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, | 111 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, |
| 75 model)); | 112 model)); |
| 76 #endif | 113 #endif |
| 114 OnProfileChanged(); | |
| 77 } else { | 115 } else { |
| 116 model_ = NULL; | |
| 78 apps_builder_.reset(); | 117 apps_builder_.reset(); |
| 79 search_controller_.reset(); | 118 search_controller_.reset(); |
| 80 #if defined(USE_ASH) | 119 #if defined(USE_ASH) |
| 81 app_sync_ui_state_watcher_.reset(); | 120 app_sync_ui_state_watcher_.reset(); |
| 82 #endif | 121 #endif |
| 83 } | 122 } |
| 84 } | 123 } |
| 85 | 124 |
| 86 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { | 125 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { |
| 87 return signin_delegate_.get(); | 126 return signin_delegate_.get(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 } | 192 } |
| 154 | 193 |
| 155 void AppListViewDelegate::ViewActivationChanged(bool active) { | 194 void AppListViewDelegate::ViewActivationChanged(bool active) { |
| 156 controller_->ViewActivationChanged(active); | 195 controller_->ViewActivationChanged(active); |
| 157 } | 196 } |
| 158 | 197 |
| 159 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { | 198 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { |
| 160 return controller_->GetWindowIcon(); | 199 return controller_->GetWindowIcon(); |
| 161 } | 200 } |
| 162 | 201 |
| 163 string16 AppListViewDelegate::GetCurrentUserName() { | |
| 164 ProfileInfoCache& cache = | |
| 165 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 166 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | |
| 167 if (profile_index != std::string::npos) | |
| 168 return cache.GetNameOfProfileAtIndex(profile_index); | |
| 169 | |
| 170 return string16(); | |
| 171 } | |
| 172 | |
| 173 string16 AppListViewDelegate::GetCurrentUserEmail() { | |
| 174 ProfileInfoCache& cache = | |
| 175 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 176 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | |
| 177 if (profile_index != std::string::npos) | |
| 178 return cache.GetUserNameOfProfileAtIndex(profile_index); | |
| 179 | |
| 180 return string16(); | |
| 181 } | |
| 182 | |
| 183 void AppListViewDelegate::OpenSettings() { | 202 void AppListViewDelegate::OpenSettings() { |
| 184 ExtensionService* service = profile_->GetExtensionService(); | 203 ExtensionService* service = profile_->GetExtensionService(); |
| 185 DCHECK(service); | 204 DCHECK(service); |
| 186 const extensions::Extension* extension = service->GetInstalledExtension( | 205 const extensions::Extension* extension = service->GetInstalledExtension( |
| 187 extension_misc::kSettingsAppId); | 206 extension_misc::kSettingsAppId); |
| 188 DCHECK(extension); | 207 DCHECK(extension); |
| 189 controller_->ActivateApp(profile_, extension, 0); | 208 controller_->ActivateApp(profile_, extension, 0); |
| 190 } | 209 } |
| 191 | 210 |
| 192 void AppListViewDelegate::OpenHelp() { | 211 void AppListViewDelegate::OpenHelp() { |
| 193 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 212 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 194 controller_->GetAppListWindow()); | 213 controller_->GetAppListWindow()); |
| 195 Browser* browser = chrome::FindOrCreateTabbedBrowser( | 214 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
| 196 profile_, desktop); | 215 profile_, desktop); |
| 197 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), | 216 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), |
| 198 content::Referrer(), | 217 content::Referrer(), |
| 199 NEW_FOREGROUND_TAB, | 218 NEW_FOREGROUND_TAB, |
| 200 content::PAGE_TRANSITION_LINK, | 219 content::PAGE_TRANSITION_LINK, |
| 201 false)); | 220 false)); |
| 202 } | 221 } |
| 203 | 222 |
| 204 void AppListViewDelegate::OpenFeedback() { | 223 void AppListViewDelegate::OpenFeedback() { |
| 205 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( | 224 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
| 206 controller_->GetAppListWindow()); | 225 controller_->GetAppListWindow()); |
| 207 Browser* browser = chrome::FindOrCreateTabbedBrowser( | 226 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
| 208 profile_, desktop); | 227 profile_, desktop); |
| 209 chrome::ShowFeedbackPage(browser, std::string(), | 228 chrome::ShowFeedbackPage(browser, std::string(), |
| 210 chrome::kAppLauncherCategoryTag); | 229 chrome::kAppLauncherCategoryTag); |
| 211 } | 230 } |
| 231 | |
| 232 void AppListViewDelegate::OnSigninSuccess() { | |
|
xiyuan
2013/08/08 01:52:06
What's the difference between OnSigninSuccess and
calamity
2013/08/08 06:29:40
Removed the notifications.
| |
| 233 OnProfileChanged(); | |
| 234 } | |
| 235 | |
| 236 void AppListViewDelegate::Observe( | |
| 237 int type, | |
| 238 const content::NotificationSource& source, | |
| 239 const content::NotificationDetails& details) { | |
| 240 OnProfileChanged(); | |
| 241 } | |
| OLD | NEW |