OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_syncable_service.h" | 5 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
6 | 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" |
7 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/ui/app_list/app_list_service.h" | 10 #include "chrome/browser/ui/app_list/app_list_service.h" |
9 #include "chrome/browser/ui/app_list/extension_app_model_builder.h" | 11 #include "chrome/browser/ui/app_list/extension_app_model_builder.h" |
10 #include "chrome/browser/ui/host_desktop.h" | 12 #include "chrome/browser/ui/host_desktop.h" |
| 13 #include "content/public/browser/notification_source.h" |
11 #include "ui/app_list/app_list_model.h" | 14 #include "ui/app_list/app_list_model.h" |
12 | 15 |
13 namespace app_list { | 16 namespace app_list { |
14 | 17 |
15 AppListSyncableService::AppListSyncableService(Profile* profile) | 18 AppListSyncableService::AppListSyncableService( |
| 19 Profile* profile, |
| 20 ExtensionService* extension_service) |
16 : profile_(profile), | 21 : profile_(profile), |
17 model_(new AppListModel) { | 22 model_(new AppListModel) { |
| 23 if (extension_service && extension_service->is_ready()) { |
| 24 BuildModel(); |
| 25 return; |
| 26 } |
| 27 |
| 28 // The extensions for this profile have not yet all been loaded. |
| 29 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
| 30 content::Source<Profile>(profile)); |
| 31 } |
| 32 |
| 33 AppListSyncableService::~AppListSyncableService() { |
| 34 } |
| 35 |
| 36 void AppListSyncableService::BuildModel() { |
18 // For now, use the AppListControllerDelegate associated with the native | 37 // For now, use the AppListControllerDelegate associated with the native |
19 // desktop. TODO(stevenjb): Remove ExtensionAppModelBuilder controller | 38 // desktop. TODO(stevenjb): Remove ExtensionAppModelBuilder controller |
20 // dependency and move the dependent methods from AppListControllerDelegate | 39 // dependency and move the dependent methods from AppListControllerDelegate |
21 // to an extension service delegate associated with this class. | 40 // to an extension service delegate associated with this class. |
22 AppListControllerDelegate* controller = NULL; | 41 AppListControllerDelegate* controller = NULL; |
23 AppListService* service = | 42 AppListService* service = |
24 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE); | 43 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE); |
25 if (service) | 44 if (service) |
26 controller = service->GetControllerDelegate(); | 45 controller = service->GetControllerDelegate(); |
27 apps_builder_.reset( | 46 apps_builder_.reset( |
28 new ExtensionAppModelBuilder(profile_, model_.get(), controller)); | 47 new ExtensionAppModelBuilder(profile_, model_.get(), controller)); |
29 DCHECK(profile_); | 48 DCHECK(profile_); |
30 VLOG(1) << "AppListSyncableService Created."; | 49 VLOG(1) << "AppListSyncableService Created."; |
31 } | 50 } |
32 | 51 |
33 AppListSyncableService::~AppListSyncableService() { | 52 void AppListSyncableService::Observe( |
| 53 int type, |
| 54 const content::NotificationSource& source, |
| 55 const content::NotificationDetails& details) { |
| 56 DCHECK_EQ(chrome::NOTIFICATION_EXTENSIONS_READY, type); |
| 57 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
| 58 registrar_.RemoveAll(); |
| 59 BuildModel(); |
34 } | 60 } |
35 | 61 |
36 } // namespace app_list | 62 } // namespace app_list |
OLD | NEW |