| 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/search/hotword_service.h" | 5 #include "chrome/browser/search/hotword_service.h" |
| 6 | 6 |
| 7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/pending_extension_manager.h" | 15 #include "chrome/browser/extensions/pending_extension_manager.h" |
| 16 #include "chrome/browser/extensions/updater/extension_updater.h" | 16 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 17 #include "chrome/browser/extensions/webstore_startup_installer.h" | 17 #include "chrome/browser/extensions/webstore_startup_installer.h" |
| 18 #include "chrome/browser/plugins/plugin_prefs.h" | 18 #include "chrome/browser/plugins/plugin_prefs.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/search/hotword_service_factory.h" | 20 #include "chrome/browser/search/hotword_service_factory.h" |
| 21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/plugin_service.h" | 26 #include "content/public/browser/plugin_service.h" |
| 27 #include "content/public/common/webplugininfo.h" | 27 #include "content/public/common/webplugininfo.h" |
| 28 #include "extensions/browser/extension_system.h" | 28 #include "extensions/browser/extension_system.h" |
| 29 #include "extensions/browser/uninstall_reason.h" |
| 29 #include "extensions/common/extension.h" | 30 #include "extensions/common/extension.h" |
| 30 #include "extensions/common/one_shot_event.h" | 31 #include "extensions/common/one_shot_event.h" |
| 31 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 33 | 34 |
| 34 // The whole file relies on the extension systems but this file is built on | 35 // The whole file relies on the extension systems but this file is built on |
| 35 // some non-extension supported platforms and including an API header will cause | 36 // some non-extension supported platforms and including an API header will cause |
| 36 // a compile error since it depends on header files generated by .idl. | 37 // a compile error since it depends on header files generated by .idl. |
| 37 // TODO(mukai): clean up file dependencies and remove this clause. | 38 // TODO(mukai): clean up file dependencies and remove this clause. |
| 38 #if defined(ENABLE_EXTENSIONS) | 39 #if defined(ENABLE_EXTENSIONS) |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 // be up by the time it's needed, but this is the best we can do without | 249 // be up by the time it's needed, but this is the best we can do without |
| 249 // starting it at start up which slows down start up too much. | 250 // starting it at start up which slows down start up too much. |
| 250 // The content/media for microphone uses the same observer design and | 251 // The content/media for microphone uses the same observer design and |
| 251 // makes use of the same audio device monitor. | 252 // makes use of the same audio device monitor. |
| 252 HotwordServiceFactory::GetInstance()->UpdateMicrophoneState(); | 253 HotwordServiceFactory::GetInstance()->UpdateMicrophoneState(); |
| 253 } | 254 } |
| 254 } | 255 } |
| 255 | 256 |
| 256 void HotwordService::OnExtensionUninstalled( | 257 void HotwordService::OnExtensionUninstalled( |
| 257 content::BrowserContext* browser_context, | 258 content::BrowserContext* browser_context, |
| 258 const extensions::Extension* extension) { | 259 const extensions::Extension* extension, |
| 260 extensions::UninstallReason reason) { |
| 259 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 261 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 260 | 262 |
| 261 if (extension->id() != extension_misc::kHotwordExtensionId || | 263 if (extension->id() != extension_misc::kHotwordExtensionId || |
| 262 profile_ != Profile::FromBrowserContext(browser_context) || | 264 profile_ != Profile::FromBrowserContext(browser_context) || |
| 263 !GetExtensionService(profile_)) | 265 !GetExtensionService(profile_)) |
| 264 return; | 266 return; |
| 265 | 267 |
| 266 // If the extension wasn't uninstalled due to language change, don't try to | 268 // If the extension wasn't uninstalled due to language change, don't try to |
| 267 // reinstall it. | 269 // reinstall it. |
| 268 if (!reinstall_pending_) | 270 if (!reinstall_pending_) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 reinstall_pending_ = true; | 357 reinstall_pending_ = true; |
| 356 | 358 |
| 357 return UninstallHotwordExtension(extension_service); | 359 return UninstallHotwordExtension(extension_service); |
| 358 } | 360 } |
| 359 | 361 |
| 360 bool HotwordService::UninstallHotwordExtension( | 362 bool HotwordService::UninstallHotwordExtension( |
| 361 ExtensionService* extension_service) { | 363 ExtensionService* extension_service) { |
| 362 base::string16 error; | 364 base::string16 error; |
| 363 if (!extension_service->UninstallExtension( | 365 if (!extension_service->UninstallExtension( |
| 364 extension_misc::kHotwordExtensionId, | 366 extension_misc::kHotwordExtensionId, |
| 365 ExtensionService::UNINSTALL_REASON_INTERNAL_MANAGEMENT, | 367 extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT, |
| 366 &error)) { | 368 &error)) { |
| 367 LOG(WARNING) << "Cannot uninstall extension with id " | 369 LOG(WARNING) << "Cannot uninstall extension with id " |
| 368 << extension_misc::kHotwordExtensionId | 370 << extension_misc::kHotwordExtensionId |
| 369 << ": " << error; | 371 << ": " << error; |
| 370 reinstall_pending_ = false; | 372 reinstall_pending_ = false; |
| 371 return false; | 373 return false; |
| 372 } | 374 } |
| 373 return true; | 375 return true; |
| 374 } | 376 } |
| 375 | 377 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 return false; | 502 return false; |
| 501 | 503 |
| 502 std::string previous_locale = | 504 std::string previous_locale = |
| 503 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); | 505 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); |
| 504 std::string locale = GetCurrentLocale(profile_); | 506 std::string locale = GetCurrentLocale(profile_); |
| 505 | 507 |
| 506 // If it's a new locale, then the old extension should be uninstalled. | 508 // If it's a new locale, then the old extension should be uninstalled. |
| 507 return locale != previous_locale && | 509 return locale != previous_locale && |
| 508 HotwordService::DoesHotwordSupportLanguage(profile_); | 510 HotwordService::DoesHotwordSupportLanguage(profile_); |
| 509 } | 511 } |
| OLD | NEW |