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/extensions/extensions_service.h" | 5 #include "chrome/browser/extensions/extensions_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 173 } |
174 | 174 |
175 } // namespace | 175 } // namespace |
176 | 176 |
177 // Implements IO for the ExtensionsService. | 177 // Implements IO for the ExtensionsService. |
178 | 178 |
179 class ExtensionsServiceBackend | 179 class ExtensionsServiceBackend |
180 : public base::RefCountedThreadSafe<ExtensionsServiceBackend>, | 180 : public base::RefCountedThreadSafe<ExtensionsServiceBackend>, |
181 public ExternalExtensionProvider::Visitor { | 181 public ExternalExtensionProvider::Visitor { |
182 public: | 182 public: |
183 // |rdh| can be NULL in the case of test environment. | 183 // |install_directory| is a path where to look for extensions to load. |
184 // |extension_prefs| contains a dictionary value that points to the extension | 184 // |load_external_extensions| indicates whether or not backend should load |
185 // preferences. | 185 // external extensions listed in JSON file and Windows registry. |
186 explicit ExtensionsServiceBackend(const FilePath& install_directory); | 186 ExtensionsServiceBackend(const FilePath& install_directory, |
| 187 bool load_external_extensions); |
187 | 188 |
188 // Loads a single extension from |path| where |path| is the top directory of | 189 // Loads a single extension from |path| where |path| is the top directory of |
189 // a specific extension where its manifest file lives. | 190 // a specific extension where its manifest file lives. |
190 // Errors are reported through ExtensionErrorReporter. On success, | 191 // Errors are reported through ExtensionErrorReporter. On success, |
191 // OnExtensionLoaded() is called. | 192 // OnExtensionLoaded() is called. |
192 // TODO(erikkay): It might be useful to be able to load a packed extension | 193 // TODO(erikkay): It might be useful to be able to load a packed extension |
193 // (presumably into memory) without installing it. | 194 // (presumably into memory) without installing it. |
194 void LoadSingleExtension(const FilePath &path, | 195 void LoadSingleExtension(const FilePath &path, |
195 scoped_refptr<ExtensionsService> frontend); | 196 scoped_refptr<ExtensionsService> frontend); |
196 | 197 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 279 |
279 // Set to true by OnExternalExtensionUpdateUrlFound() when an external | 280 // Set to true by OnExternalExtensionUpdateUrlFound() when an external |
280 // extension URL is found. Used in CheckForExternalUpdates() to see | 281 // extension URL is found. Used in CheckForExternalUpdates() to see |
281 // if an update check is needed to install pending extensions. | 282 // if an update check is needed to install pending extensions. |
282 bool external_extension_added_; | 283 bool external_extension_added_; |
283 | 284 |
284 DISALLOW_COPY_AND_ASSIGN(ExtensionsServiceBackend); | 285 DISALLOW_COPY_AND_ASSIGN(ExtensionsServiceBackend); |
285 }; | 286 }; |
286 | 287 |
287 ExtensionsServiceBackend::ExtensionsServiceBackend( | 288 ExtensionsServiceBackend::ExtensionsServiceBackend( |
288 const FilePath& install_directory) | 289 const FilePath& install_directory, |
| 290 bool load_external_extensions) |
289 : frontend_(NULL), | 291 : frontend_(NULL), |
290 install_directory_(install_directory), | 292 install_directory_(install_directory), |
291 alert_on_error_(false), | 293 alert_on_error_(false), |
292 external_extension_added_(false) { | 294 external_extension_added_(false) { |
| 295 if (!load_external_extensions) |
| 296 return; |
| 297 |
293 // TODO(aa): This ends up doing blocking IO on the UI thread because it reads | 298 // TODO(aa): This ends up doing blocking IO on the UI thread because it reads |
294 // pref data in the ctor and that is called on the UI thread. Would be better | 299 // pref data in the ctor and that is called on the UI thread. Would be better |
295 // to re-read data each time we list external extensions, anyway. | 300 // to re-read data each time we list external extensions, anyway. |
296 external_extension_providers_[Extension::EXTERNAL_PREF] = | 301 external_extension_providers_[Extension::EXTERNAL_PREF] = |
297 linked_ptr<ExternalExtensionProvider>( | 302 linked_ptr<ExternalExtensionProvider>( |
298 new ExternalPrefExtensionProvider()); | 303 new ExternalPrefExtensionProvider()); |
299 #if defined(OS_WIN) | 304 #if defined(OS_WIN) |
300 external_extension_providers_[Extension::EXTERNAL_REGISTRY] = | 305 external_extension_providers_[Extension::EXTERNAL_REGISTRY] = |
301 linked_ptr<ExternalExtensionProvider>( | 306 linked_ptr<ExternalExtensionProvider>( |
302 new ExternalRegistryExtensionProvider()); | 307 new ExternalRegistryExtensionProvider()); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 if (autoupdate_enabled) { | 554 if (autoupdate_enabled) { |
550 int update_frequency = kDefaultUpdateFrequencySeconds; | 555 int update_frequency = kDefaultUpdateFrequencySeconds; |
551 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { | 556 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { |
552 base::StringToInt(command_line->GetSwitchValueASCII( | 557 base::StringToInt(command_line->GetSwitchValueASCII( |
553 switches::kExtensionsUpdateFrequency), | 558 switches::kExtensionsUpdateFrequency), |
554 &update_frequency); | 559 &update_frequency); |
555 } | 560 } |
556 updater_ = new ExtensionUpdater(this, prefs, update_frequency); | 561 updater_ = new ExtensionUpdater(this, prefs, update_frequency); |
557 } | 562 } |
558 | 563 |
559 backend_ = new ExtensionsServiceBackend(install_directory_); | 564 backend_ = new ExtensionsServiceBackend(install_directory_, |
| 565 extensions_enabled_); |
560 | 566 |
561 // Use monochrome icons for Omnibox icons. | 567 // Use monochrome icons for Omnibox icons. |
562 omnibox_popup_icon_manager_.set_monochrome(true); | 568 omnibox_popup_icon_manager_.set_monochrome(true); |
563 omnibox_icon_manager_.set_monochrome(true); | 569 omnibox_icon_manager_.set_monochrome(true); |
564 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, | 570 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, |
565 0, kOmniboxIconPaddingRight)); | 571 0, kOmniboxIconPaddingRight)); |
566 } | 572 } |
567 | 573 |
568 ExtensionsService::~ExtensionsService() { | 574 ExtensionsService::~ExtensionsService() { |
569 UnloadAllExtensions(); | 575 UnloadAllExtensions(); |
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1787 return false; | 1793 return false; |
1788 | 1794 |
1789 for (ExtensionList::const_iterator it = extensions_.begin(); | 1795 for (ExtensionList::const_iterator it = extensions_.begin(); |
1790 it != extensions_.end(); ++it) { | 1796 it != extensions_.end(); ++it) { |
1791 if ((*it)->is_app()) | 1797 if ((*it)->is_app()) |
1792 return true; | 1798 return true; |
1793 } | 1799 } |
1794 | 1800 |
1795 return false; | 1801 return false; |
1796 } | 1802 } |
OLD | NEW |