OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/external_extension_provider_impl.h" | 5 #include "chrome/browser/extensions/external_extension_provider_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "base/version.h" | 15 #include "base/version.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/extensions/default_apps_trial.h" | |
18 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
19 #include "chrome/browser/extensions/external_extension_provider_interface.h" | 18 #include "chrome/browser/extensions/external_extension_provider_interface.h" |
20 #include "chrome/browser/extensions/external_policy_extension_loader.h" | 19 #include "chrome/browser/extensions/external_policy_extension_loader.h" |
21 #include "chrome/browser/extensions/external_pref_extension_loader.h" | 20 #include "chrome/browser/extensions/external_pref_extension_loader.h" |
22 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
26 #include "content/browser/browser_thread.h" | 25 #include "content/browser/browser_thread.h" |
27 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
28 | 27 |
| 28 #if !defined(OS_CHROMEOS) |
| 29 #include "chrome/browser/extensions/default_apps.h" |
| 30 #endif |
| 31 |
29 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
30 #include "chrome/browser/extensions/external_registry_extension_loader_win.h" | 33 #include "chrome/browser/extensions/external_registry_extension_loader_win.h" |
31 #endif | 34 #endif |
32 | 35 |
33 // Constants for keeping track of extension preferences in a dictionary. | 36 // Constants for keeping track of extension preferences in a dictionary. |
34 const char ExternalExtensionProviderImpl::kLocation[] = "location"; | |
35 const char ExternalExtensionProviderImpl::kState[] = "state"; | |
36 const char ExternalExtensionProviderImpl::kExternalCrx[] = "external_crx"; | 37 const char ExternalExtensionProviderImpl::kExternalCrx[] = "external_crx"; |
37 const char ExternalExtensionProviderImpl::kExternalVersion[] = | 38 const char ExternalExtensionProviderImpl::kExternalVersion[] = |
38 "external_version"; | 39 "external_version"; |
39 const char ExternalExtensionProviderImpl::kExternalUpdateUrl[] = | 40 const char ExternalExtensionProviderImpl::kExternalUpdateUrl[] = |
40 "external_update_url"; | 41 "external_update_url"; |
41 const char ExternalExtensionProviderImpl::kSupportedLocales[] = | 42 const char ExternalExtensionProviderImpl::kSupportedLocales[] = |
42 "supported_locales"; | 43 "supported_locales"; |
43 | 44 |
44 #if !defined(OS_CHROMEOS) | |
45 class DefaultAppsProvider : public ExternalExtensionProviderImpl { | |
46 public: | |
47 DefaultAppsProvider(VisitorInterface* service, Profile* profile) | |
48 : ExternalExtensionProviderImpl(service, | |
49 new ExternalPrefExtensionLoader(chrome::DIR_DEFAULT_APPS, | |
50 ExternalPrefExtensionLoader::NONE), | |
51 Extension::EXTERNAL_PREF, Extension::INVALID), | |
52 profile_(profile) { | |
53 DCHECK(profile_); | |
54 } | |
55 | |
56 // ExternalExtensionProviderImpl overrides: | |
57 virtual void ServiceShutdown() OVERRIDE; | |
58 virtual void VisitRegisteredExtension() const OVERRIDE; | |
59 | |
60 private: | |
61 Profile* profile_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(DefaultAppsProvider); | |
64 }; | |
65 | |
66 void DefaultAppsProvider::ServiceShutdown() { | |
67 profile_ = NULL; | |
68 ExternalExtensionProviderImpl::ServiceShutdown(); | |
69 } | |
70 | |
71 void DefaultAppsProvider::VisitRegisteredExtension() const { | |
72 // Don't install default apps if the profile already has apps installed. | |
73 if (profile_) { | |
74 ExtensionService* extension_service = profile_->GetExtensionService(); | |
75 if (extension_service && extension_service->HasApps()) { | |
76 service()->OnExternalProviderReady(this); | |
77 return; | |
78 } | |
79 } | |
80 | |
81 ExternalExtensionProviderImpl::VisitRegisteredExtension(); | |
82 } | |
83 #endif | |
84 | |
85 ExternalExtensionProviderImpl::ExternalExtensionProviderImpl( | 45 ExternalExtensionProviderImpl::ExternalExtensionProviderImpl( |
86 VisitorInterface* service, | 46 VisitorInterface* service, |
87 ExternalExtensionLoader* loader, | 47 ExternalExtensionLoader* loader, |
88 Extension::Location crx_location, | 48 Extension::Location crx_location, |
89 Extension::Location download_location) | 49 Extension::Location download_location) |
90 : crx_location_(crx_location), | 50 : crx_location_(crx_location), |
91 download_location_(download_location), | 51 download_location_(download_location), |
92 service_(service), | 52 service_(service), |
93 prefs_(NULL), | 53 prefs_(NULL), |
94 ready_(false), | 54 ready_(false), |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 #endif | 335 #endif |
376 provider_list->push_back( | 336 provider_list->push_back( |
377 linked_ptr<ExternalExtensionProviderInterface>( | 337 linked_ptr<ExternalExtensionProviderInterface>( |
378 new ExternalExtensionProviderImpl( | 338 new ExternalExtensionProviderImpl( |
379 service, | 339 service, |
380 new ExternalPolicyExtensionLoader(profile), | 340 new ExternalPolicyExtensionLoader(profile), |
381 Extension::INVALID, | 341 Extension::INVALID, |
382 Extension::EXTERNAL_POLICY_DOWNLOAD))); | 342 Extension::EXTERNAL_POLICY_DOWNLOAD))); |
383 | 343 |
384 #if !defined(OS_CHROMEOS) | 344 #if !defined(OS_CHROMEOS) |
385 // We decide to install or not install default apps based on the following | 345 if (default_apps::ShouldInstallInProfile(profile)) { |
386 // criteria, from highest priority to lowest priority: | 346 provider_list->push_back( |
387 // | 347 linked_ptr<ExternalExtensionProviderInterface>( |
388 // - if this instance of chrome is participating in the default apps | 348 new ExternalExtensionProviderImpl( |
389 // field trial, then install apps based on the group | 349 service, |
390 // - the command line option. Tests use this option to disable installation | 350 new ExternalPrefExtensionLoader( |
391 // of default apps in some cases | 351 chrome::DIR_DEFAULT_APPS, options), |
392 // - the preferences value in the profile. This value is usually set in | 352 Extension::EXTERNAL_PREF, |
393 // the master_preferences file | 353 Extension::INVALID))); |
394 bool install_apps = | |
395 profile->GetPrefs()->GetString(prefs::kDefaultApps) == "install"; | |
396 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
397 switches::kDisableDefaultApps)) { | |
398 install_apps = false; | |
399 } | |
400 if (base::FieldTrialList::TrialExists(kDefaultAppsTrial_Name)) { | |
401 install_apps = base::FieldTrialList::Find( | |
402 kDefaultAppsTrial_Name)->group_name() != kDefaultAppsTrial_NoAppsGroup; | |
403 } | |
404 | |
405 if (install_apps) { | |
406 // Don't bother installing default apps in locales where its known that | |
407 // they don't work. | |
408 // TODO(rogerta): Do this check dynamically once the webstore can expose | |
409 // an API. | |
410 const std::string& locale = g_browser_process->GetApplicationLocale(); | |
411 static const char* unsupported_locales[] = {"CN", "TR", "IR"}; | |
412 bool supported_locale = true; | |
413 for (size_t i = 0; i < arraysize(unsupported_locales); ++i) { | |
414 if (EndsWith(locale, unsupported_locales[i], false)) { | |
415 supported_locale = false; | |
416 break; | |
417 } | |
418 } | |
419 | |
420 if (supported_locale) { | |
421 provider_list->push_back( | |
422 linked_ptr<ExternalExtensionProviderInterface>( | |
423 new DefaultAppsProvider(service, profile))); | |
424 } | |
425 } | 354 } |
426 #endif | 355 #endif |
427 } | 356 } |
OLD | NEW |