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/apps_model_builder.h" | 5 #include "chrome/browser/ui/app_list/apps_model_builder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "chrome/browser/extensions/extension_prefs.h" | 11 #include "chrome/browser/extensions/extension_prefs.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
| 14 #include "chrome/browser/extensions/install_tracker.h" |
| 15 #include "chrome/browser/extensions/install_tracker_factory.h" |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/app_list/extension_app_item.h" | 17 #include "chrome/browser/ui/app_list/extension_app_item.h" |
16 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
18 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
19 #include "ui/gfx/image/image_skia.h" | 21 #include "ui/gfx/image/image_skia.h" |
20 | 22 |
21 using extensions::Extension; | 23 using extensions::Extension; |
22 | 24 |
23 namespace { | 25 namespace { |
(...skipping 12 matching lines...) Expand all Loading... |
36 | 38 |
37 } // namespace | 39 } // namespace |
38 | 40 |
39 AppsModelBuilder::AppsModelBuilder(Profile* profile, | 41 AppsModelBuilder::AppsModelBuilder(Profile* profile, |
40 app_list::AppListModel::Apps* model, | 42 app_list::AppListModel::Apps* model, |
41 AppListControllerDelegate* controller) | 43 AppListControllerDelegate* controller) |
42 : profile_(profile), | 44 : profile_(profile), |
43 controller_(controller), | 45 controller_(controller), |
44 model_(model), | 46 model_(model), |
45 ignore_changes_(false) { | 47 ignore_changes_(false) { |
| 48 extensions::InstallTracker* tracker = |
| 49 extensions::InstallTrackerFactory::GetForProfile(profile_); |
| 50 tracker->AddObserver(this); |
46 extensions::ExtensionPrefs* extension_prefs = | 51 extensions::ExtensionPrefs* extension_prefs = |
47 extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 52 extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
48 extension_prefs(); | 53 extension_prefs(); |
49 | 54 |
50 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 55 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
51 content::Source<Profile>(profile_)); | 56 content::Source<Profile>(profile_)); |
52 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 57 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
53 content::Source<Profile>(profile_)); | 58 content::Source<Profile>(profile_)); |
54 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, | 59 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, |
55 content::Source<ExtensionSorting>(extension_prefs->extension_sorting())); | 60 content::Source<ExtensionSorting>(extension_prefs->extension_sorting())); |
56 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST, | 61 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST, |
57 content::Source<Profile>(profile_)); | 62 content::Source<Profile>(profile_)); |
58 | 63 |
59 pref_change_registrar_.Init(extension_prefs->pref_service()); | 64 pref_change_registrar_.Init(extension_prefs->pref_service()); |
60 pref_change_registrar_.Add(extensions::ExtensionPrefs::kExtensionsPref, | 65 pref_change_registrar_.Add(extensions::ExtensionPrefs::kExtensionsPref, |
61 base::Bind(&AppsModelBuilder::ResortApps, | 66 base::Bind(&AppsModelBuilder::ResortApps, |
62 base::Unretained(this))); | 67 base::Unretained(this))); |
63 | 68 |
64 model_->AddObserver(this); | 69 model_->AddObserver(this); |
65 } | 70 } |
66 | 71 |
67 AppsModelBuilder::~AppsModelBuilder() { | 72 AppsModelBuilder::~AppsModelBuilder() { |
| 73 extensions::InstallTracker* tracker = |
| 74 extensions::InstallTrackerFactory::GetForProfile(profile_); |
| 75 tracker->RemoveObserver(this); |
68 model_->RemoveObserver(this); | 76 model_->RemoveObserver(this); |
69 } | 77 } |
70 | 78 |
71 void AppsModelBuilder::Build() { | 79 void AppsModelBuilder::Build() { |
72 DCHECK(model_ && model_->item_count() == 0); | 80 DCHECK(model_ && model_->item_count() == 0); |
73 | 81 |
74 PopulateApps(); | 82 PopulateApps(); |
75 HighlightApp(); | 83 HighlightApp(); |
76 } | 84 } |
77 | 85 |
78 void AppsModelBuilder::OnBeginExtensionInstall( | 86 void AppsModelBuilder::OnBeginExtensionInstall( |
79 const std::string& extension_id, | 87 const std::string& extension_id, |
80 const std::string& extension_name, | 88 const std::string& extension_name, |
81 const gfx::ImageSkia& installing_icon) { | 89 const gfx::ImageSkia& installing_icon, |
| 90 bool is_app) { |
| 91 if (!is_app) |
| 92 return; |
82 InsertApp(new ExtensionAppItem(profile_, | 93 InsertApp(new ExtensionAppItem(profile_, |
83 extension_id, | 94 extension_id, |
84 controller_, | 95 controller_, |
85 extension_name, | 96 extension_name, |
86 installing_icon)); | 97 installing_icon)); |
87 highlight_app_id_ = extension_id; | 98 highlight_app_id_ = extension_id; |
88 HighlightApp(); | 99 HighlightApp(); |
89 } | 100 } |
90 | 101 |
91 void AppsModelBuilder::OnDownloadProgress(const std::string& extension_id, | 102 void AppsModelBuilder::OnDownloadProgress(const std::string& extension_id, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 285 |
275 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; | 286 ExtensionAppItem* prev = target_index > 0 ? GetAppAt(target_index - 1) : NULL; |
276 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? | 287 ExtensionAppItem* next = target_index + 1 < model_->item_count() ? |
277 GetAppAt(target_index + 1) : NULL; | 288 GetAppAt(target_index + 1) : NULL; |
278 GetAppAt(target_index)->Move(prev, next); | 289 GetAppAt(target_index)->Move(prev, next); |
279 } | 290 } |
280 | 291 |
281 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { | 292 void AppsModelBuilder::ListItemsChanged(size_t start, size_t count) { |
282 NOTREACHED(); | 293 NOTREACHED(); |
283 } | 294 } |
OLD | NEW |