| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 HotwordServiceFactory::GetInstance()->UpdateMicrophoneState(); | 254 HotwordServiceFactory::GetInstance()->UpdateMicrophoneState(); |
| 255 } | 255 } |
| 256 } | 256 } |
| 257 | 257 |
| 258 void HotwordService::OnExtensionUninstalled( | 258 void HotwordService::OnExtensionUninstalled( |
| 259 content::BrowserContext* browser_context, | 259 content::BrowserContext* browser_context, |
| 260 const extensions::Extension* extension, | 260 const extensions::Extension* extension, |
| 261 extensions::UninstallReason reason) { | 261 extensions::UninstallReason reason) { |
| 262 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 262 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 263 | 263 |
| 264 if (extension->id() != extension_misc::kHotwordExtensionId || | 264 if ((extension->id() != extension_misc::kHotwordExtensionId && |
| 265 profile_ != Profile::FromBrowserContext(browser_context) || | 265 extension->id() != extension_misc::kHotwordSharedModuleId) || |
| 266 profile_ != Profile::FromBrowserContext(browser_context) || |
| 266 !GetExtensionService(profile_)) | 267 !GetExtensionService(profile_)) |
| 267 return; | 268 return; |
| 268 | 269 |
| 269 // If the extension wasn't uninstalled due to language change, don't try to | 270 // If the extension wasn't uninstalled due to language change, don't try to |
| 270 // reinstall it. | 271 // reinstall it. |
| 271 if (!reinstall_pending_) | 272 if (!reinstall_pending_) |
| 272 return; | 273 return; |
| 273 | 274 |
| 274 InstallHotwordExtensionFromWebstore(); | 275 InstallHotwordExtensionFromWebstore(); |
| 275 SetPreviousLanguagePref(); | 276 SetPreviousLanguagePref(); |
| 276 } | 277 } |
| 277 | 278 |
| 279 std::string HotwordService::ReinstalledExtensionId() { |
| 280 if (IsExperimentalHotwordingEnabled()) |
| 281 return extension_misc::kHotwordSharedModuleId; |
| 282 |
| 283 return extension_misc::kHotwordExtensionId; |
| 284 } |
| 285 |
| 278 void HotwordService::InstallHotwordExtensionFromWebstore() { | 286 void HotwordService::InstallHotwordExtensionFromWebstore() { |
| 279 installer_ = new extensions::WebstoreStartupInstaller( | 287 installer_ = new extensions::WebstoreStartupInstaller( |
| 280 extension_misc::kHotwordExtensionId, | 288 ReinstalledExtensionId(), |
| 281 profile_, | 289 profile_, |
| 282 false, | 290 false, |
| 283 extensions::WebstoreStandaloneInstaller::Callback()); | 291 extensions::WebstoreStandaloneInstaller::Callback()); |
| 284 installer_->BeginInstall(); | 292 installer_->BeginInstall(); |
| 285 } | 293 } |
| 286 | 294 |
| 287 void HotwordService::OnExtensionInstalled( | 295 void HotwordService::OnExtensionInstalled( |
| 288 content::BrowserContext* browser_context, | 296 content::BrowserContext* browser_context, |
| 289 const extensions::Extension* extension, | 297 const extensions::Extension* extension, |
| 290 bool is_update) { | 298 bool is_update) { |
| 291 | 299 |
| 292 if (extension->id() != extension_misc::kHotwordExtensionId || | 300 if ((extension->id() != extension_misc::kHotwordExtensionId && |
| 293 profile_ != Profile::FromBrowserContext(browser_context)) | 301 extension->id() != extension_misc::kHotwordSharedModuleId) || |
| 302 profile_ != Profile::FromBrowserContext(browser_context)) |
| 294 return; | 303 return; |
| 295 | 304 |
| 296 // If the previous locale pref has never been set, set it now since | 305 // If the previous locale pref has never been set, set it now since |
| 297 // the extension has been installed. | 306 // the extension has been installed. |
| 298 if (!profile_->GetPrefs()->HasPrefPath(prefs::kHotwordPreviousLanguage)) | 307 if (!profile_->GetPrefs()->HasPrefPath(prefs::kHotwordPreviousLanguage)) |
| 299 SetPreviousLanguagePref(); | 308 SetPreviousLanguagePref(); |
| 300 | 309 |
| 301 // If MaybeReinstallHotwordExtension already triggered an uninstall, we | 310 // If MaybeReinstallHotwordExtension already triggered an uninstall, we |
| 302 // don't want to loop and trigger another uninstall-install cycle. | 311 // don't want to loop and trigger another uninstall-install cycle. |
| 303 // However, if we arrived here via an uninstall-triggered-install (and in | 312 // However, if we arrived here via an uninstall-triggered-install (and in |
| (...skipping 19 matching lines...) Expand all Loading... |
| 323 } | 332 } |
| 324 | 333 |
| 325 bool HotwordService::MaybeReinstallHotwordExtension() { | 334 bool HotwordService::MaybeReinstallHotwordExtension() { |
| 326 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 335 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 327 | 336 |
| 328 ExtensionService* extension_service = GetExtensionService(profile_); | 337 ExtensionService* extension_service = GetExtensionService(profile_); |
| 329 if (!extension_service) | 338 if (!extension_service) |
| 330 return false; | 339 return false; |
| 331 | 340 |
| 332 const extensions::Extension* extension = extension_service->GetExtensionById( | 341 const extensions::Extension* extension = extension_service->GetExtensionById( |
| 333 extension_misc::kHotwordExtensionId, true); | 342 ReinstalledExtensionId(), true); |
| 334 if (!extension) | 343 if (!extension) |
| 335 return false; | 344 return false; |
| 336 | 345 |
| 337 // If the extension is currently pending, return and we'll check again | 346 // If the extension is currently pending, return and we'll check again |
| 338 // after the install is finished. | 347 // after the install is finished. |
| 339 extensions::PendingExtensionManager* pending_manager = | 348 extensions::PendingExtensionManager* pending_manager = |
| 340 extension_service->pending_extension_manager(); | 349 extension_service->pending_extension_manager(); |
| 341 if (pending_manager->IsIdPending(extension->id())) | 350 if (pending_manager->IsIdPending(extension->id())) |
| 342 return false; | 351 return false; |
| 343 | 352 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 354 // Ensure the call to OnExtensionUninstalled was triggered by a language | 363 // Ensure the call to OnExtensionUninstalled was triggered by a language |
| 355 // change so it's okay to reinstall. | 364 // change so it's okay to reinstall. |
| 356 reinstall_pending_ = true; | 365 reinstall_pending_ = true; |
| 357 | 366 |
| 358 return UninstallHotwordExtension(extension_service); | 367 return UninstallHotwordExtension(extension_service); |
| 359 } | 368 } |
| 360 | 369 |
| 361 bool HotwordService::UninstallHotwordExtension( | 370 bool HotwordService::UninstallHotwordExtension( |
| 362 ExtensionService* extension_service) { | 371 ExtensionService* extension_service) { |
| 363 base::string16 error; | 372 base::string16 error; |
| 373 std::string extension_id = ReinstalledExtensionId(); |
| 364 if (!extension_service->UninstallExtension( | 374 if (!extension_service->UninstallExtension( |
| 365 extension_misc::kHotwordExtensionId, | 375 extension_id, |
| 366 extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT, | 376 extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT, |
| 367 base::Bind(&base::DoNothing), | 377 base::Bind(&base::DoNothing), |
| 368 &error)) { | 378 &error)) { |
| 369 LOG(WARNING) << "Cannot uninstall extension with id " | 379 LOG(WARNING) << "Cannot uninstall extension with id " |
| 370 << extension_misc::kHotwordExtensionId | 380 << extension_id |
| 371 << ": " << error; | 381 << ": " << error; |
| 372 reinstall_pending_ = false; | 382 reinstall_pending_ = false; |
| 373 return false; | 383 return false; |
| 374 } | 384 } |
| 375 return true; | 385 return true; |
| 376 } | 386 } |
| 377 | 387 |
| 378 bool HotwordService::IsServiceAvailable() { | 388 bool HotwordService::IsServiceAvailable() { |
| 379 error_message_ = 0; | 389 error_message_ = 0; |
| 380 | 390 |
| 381 // Determine if the extension is available. | 391 // Determine if the extension is available. |
| 382 extensions::ExtensionSystem* system = | 392 extensions::ExtensionSystem* system = |
| 383 extensions::ExtensionSystem::Get(profile_); | 393 extensions::ExtensionSystem::Get(profile_); |
| 384 ExtensionService* service = system->extension_service(); | 394 ExtensionService* service = system->extension_service(); |
| 385 // Include disabled extensions (true parameter) since it may not be enabled | 395 // Include disabled extensions (true parameter) since it may not be enabled |
| 386 // if the user opted out. | 396 // if the user opted out. |
| 387 std::string extensionId; | |
| 388 if (IsExperimentalHotwordingEnabled()) { | |
| 389 // TODO(amistry): Handle reloading on language change as the old extension | |
| 390 // does. | |
| 391 extensionId = extension_misc::kHotwordSharedModuleId; | |
| 392 } else { | |
| 393 extensionId = extension_misc::kHotwordExtensionId; | |
| 394 } | |
| 395 const extensions::Extension* extension = | 397 const extensions::Extension* extension = |
| 396 service->GetExtensionById(extensionId, true); | 398 service->GetExtensionById(ReinstalledExtensionId(), true); |
| 397 if (!extension) | 399 if (!extension) |
| 398 error_message_ = IDS_HOTWORD_GENERIC_ERROR_MESSAGE; | 400 error_message_ = IDS_HOTWORD_GENERIC_ERROR_MESSAGE; |
| 399 | 401 |
| 400 RecordExtensionAvailabilityMetrics(service, extension); | 402 RecordExtensionAvailabilityMetrics(service, extension); |
| 401 RecordLoggingMetrics(profile_); | 403 RecordLoggingMetrics(profile_); |
| 402 | 404 |
| 403 // Determine if NaCl is available. | 405 // Determine if NaCl is available. |
| 404 bool nacl_enabled = false; | 406 bool nacl_enabled = false; |
| 405 base::FilePath path; | 407 base::FilePath path; |
| 406 if (PathService::Get(chrome::FILE_NACL_PLUGIN, &path)) { | 408 if (PathService::Get(chrome::FILE_NACL_PLUGIN, &path)) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 return false; | 533 return false; |
| 532 | 534 |
| 533 std::string previous_locale = | 535 std::string previous_locale = |
| 534 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); | 536 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); |
| 535 std::string locale = GetCurrentLocale(profile_); | 537 std::string locale = GetCurrentLocale(profile_); |
| 536 | 538 |
| 537 // If it's a new locale, then the old extension should be uninstalled. | 539 // If it's a new locale, then the old extension should be uninstalled. |
| 538 return locale != previous_locale && | 540 return locale != previous_locale && |
| 539 HotwordService::DoesHotwordSupportLanguage(profile_); | 541 HotwordService::DoesHotwordSupportLanguage(profile_); |
| 540 } | 542 } |
| OLD | NEW |