| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/background_application_list_model.h" | 5 #include "chrome/browser/background_application_list_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "app/l10n_util_collator.h" | 10 #include "app/l10n_util_collator.h" |
| 11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/app/chrome_command_ids.h" |
| 13 #include "chrome/browser/background_mode_manager.h" | 14 #include "chrome/browser/background_mode_manager.h" |
| 14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/extensions/extension_prefs.h" | 16 #include "chrome/browser/extensions/extension_prefs.h" |
| 16 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "chrome/browser/extensions/image_loading_tracker.h" | 18 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/extension_resource.h" | 22 #include "chrome/common/extensions/extension_resource.h" |
| 22 #include "chrome/common/notification_details.h" | 23 #include "chrome/common/notification_details.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 Source<Profile>(profile)); | 151 Source<Profile>(profile)); |
| 151 registrar_.Add(this, | 152 registrar_.Add(this, |
| 152 NotificationType::EXTENSION_UNLOADED, | 153 NotificationType::EXTENSION_UNLOADED, |
| 153 Source<Profile>(profile)); | 154 Source<Profile>(profile)); |
| 154 registrar_.Add(this, | 155 registrar_.Add(this, |
| 155 NotificationType::EXTENSION_UNLOADED_DISABLED, | 156 NotificationType::EXTENSION_UNLOADED_DISABLED, |
| 156 Source<Profile>(profile)); | 157 Source<Profile>(profile)); |
| 157 registrar_.Add(this, | 158 registrar_.Add(this, |
| 158 NotificationType::EXTENSIONS_READY, | 159 NotificationType::EXTENSIONS_READY, |
| 159 Source<Profile>(profile)); | 160 Source<Profile>(profile)); |
| 161 ExtensionService* service = profile->GetExtensionService(); |
| 162 if (service && service->is_ready()) |
| 163 Update(); |
| 160 } | 164 } |
| 161 | 165 |
| 162 void BackgroundApplicationListModel::AddObserver(Observer* observer) { | 166 void BackgroundApplicationListModel::AddObserver(Observer* observer) { |
| 163 observers_.AddObserver(observer); | 167 observers_.AddObserver(observer); |
| 164 } | 168 } |
| 165 | 169 |
| 166 void BackgroundApplicationListModel::AssociateApplicationData( | 170 void BackgroundApplicationListModel::AssociateApplicationData( |
| 167 const Extension* extension) { | 171 const Extension* extension) { |
| 168 DCHECK(IsBackgroundApp(*extension)); | 172 DCHECK(IsBackgroundApp(*extension)); |
| 169 Application* application = FindApplication(extension); | 173 Application* application = FindApplication(extension); |
| 170 if (!application) { | 174 if (!application) { |
| 175 // App position is used as a dynamic command and so must be less than any |
| 176 // predefined command id. |
| 177 if (applications_.size() >= IDC_MinimumLabelValue) { |
| 178 LOG(ERROR) << "Background application limit of " << IDC_MinimumLabelValue |
| 179 << " exceeded. Ignoring."; |
| 180 return; |
| 181 } |
| 171 application = new Application(this, extension); | 182 application = new Application(this, extension); |
| 172 applications_[extension->id()] = application; | 183 applications_[extension->id()] = application; |
| 173 application->RequestIcon(Extension::EXTENSION_ICON_BITTY); | 184 application->RequestIcon(Extension::EXTENSION_ICON_BITTY); |
| 174 } | 185 } |
| 175 } | 186 } |
| 176 | 187 |
| 177 void BackgroundApplicationListModel::DissociateApplicationData( | 188 void BackgroundApplicationListModel::DissociateApplicationData( |
| 178 const Extension* extension) { | 189 const Extension* extension) { |
| 179 ApplicationMap::iterator found = applications_.find(extension->id()); | 190 ApplicationMap::iterator found = applications_.find(extension->id()); |
| 180 if (found != applications_.end()) { | 191 if (found != applications_.end()) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 (*old_cursor)->name() == (*new_cursor)->name() && | 312 (*old_cursor)->name() == (*new_cursor)->name() && |
| 302 (*old_cursor)->id() == (*new_cursor)->id()) { | 313 (*old_cursor)->id() == (*new_cursor)->id()) { |
| 303 ++old_cursor; | 314 ++old_cursor; |
| 304 ++new_cursor; | 315 ++new_cursor; |
| 305 } | 316 } |
| 306 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { | 317 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { |
| 307 extensions_ = extensions; | 318 extensions_ = extensions; |
| 308 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged()); | 319 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged()); |
| 309 } | 320 } |
| 310 } | 321 } |
| OLD | NEW |