| 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/extension_webstore_private_api.h" | 5 #include "chrome/browser/extensions/extension_webstore_private_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/extensions/crx_installer.h" | 14 #include "chrome/browser/extensions/crx_installer.h" |
| 15 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 15 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 16 #include "chrome/browser/extensions/extension_install_dialog.h" | 16 #include "chrome/browser/extensions/extension_install_dialog.h" |
| 17 #include "chrome/browser/extensions/extension_prefs.h" | 17 #include "chrome/browser/extensions/extension_prefs.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/net/gaia/token_service.h" | 19 #include "chrome/browser/net/gaia/token_service.h" |
| 20 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/browser/sync/profile_sync_service.h" | 21 #include "chrome/browser/sync/profile_sync_service.h" |
| 22 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/chrome_utility_messages.h" | 24 #include "chrome/common/chrome_utility_messages.h" |
| 24 #include "chrome/common/extensions/extension_constants.h" | 25 #include "chrome/common/extensions/extension_constants.h" |
| 25 #include "chrome/common/extensions/extension_error_utils.h" | 26 #include "chrome/common/extensions/extension_error_utils.h" |
| 26 #include "chrome/common/extensions/extension_l10n_util.h" | 27 #include "chrome/common/extensions/extension_l10n_util.h" |
| 27 #include "chrome/common/net/gaia/gaia_constants.h" | 28 #include "chrome/common/net/gaia/gaia_constants.h" |
| 28 #include "content/browser/tab_contents/tab_contents.h" | 29 #include "content/browser/tab_contents/tab_contents.h" |
| 29 #include "content/common/notification_details.h" | 30 #include "content/common/notification_details.h" |
| 30 #include "content/common/notification_source.h" | 31 #include "content/common/notification_source.h" |
| 31 #include "content/common/notification_type.h" | |
| 32 #include "grit/chromium_strings.h" | 32 #include "grit/chromium_strings.h" |
| 33 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 34 #include "net/base/escape.h" | 34 #include "net/base/escape.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 const char kIconDataKey[] = "iconData"; | 39 const char kIconDataKey[] = "iconData"; |
| 40 const char kIdKey[] = "id"; | 40 const char kIdKey[] = "id"; |
| 41 const char kLocalizedNameKey[] = "localizedName"; | 41 const char kLocalizedNameKey[] = "localizedName"; |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 if (!tab) | 584 if (!tab) |
| 585 return false; | 585 return false; |
| 586 | 586 |
| 587 // We return the result asynchronously, so we addref to keep ourself alive. | 587 // We return the result asynchronously, so we addref to keep ourself alive. |
| 588 // Matched with a Release in OnLoginSuccess() and OnLoginFailure(). | 588 // Matched with a Release in OnLoginSuccess() and OnLoginFailure(). |
| 589 AddRef(); | 589 AddRef(); |
| 590 | 590 |
| 591 // Start listening for notifications about the token. | 591 // Start listening for notifications about the token. |
| 592 TokenService* token_service = profile->GetTokenService(); | 592 TokenService* token_service = profile->GetTokenService(); |
| 593 registrar_.Add(this, | 593 registrar_.Add(this, |
| 594 NotificationType::TOKEN_AVAILABLE, | 594 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
| 595 Source<TokenService>(token_service)); | 595 Source<TokenService>(token_service)); |
| 596 registrar_.Add(this, | 596 registrar_.Add(this, |
| 597 NotificationType::TOKEN_REQUEST_FAILED, | 597 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, |
| 598 Source<TokenService>(token_service)); | 598 Source<TokenService>(token_service)); |
| 599 | 599 |
| 600 GetBrowserSignin(profile)->RequestSignin(tab, | 600 GetBrowserSignin(profile)->RequestSignin(tab, |
| 601 ASCIIToUTF16(preferred_email), | 601 ASCIIToUTF16(preferred_email), |
| 602 GetLoginMessage(), | 602 GetLoginMessage(), |
| 603 this); | 603 this); |
| 604 | 604 |
| 605 // The response will be sent asynchronously in OnLoginSuccess/OnLoginFailure. | 605 // The response will be sent asynchronously in OnLoginSuccess/OnLoginFailure. |
| 606 return true; | 606 return true; |
| 607 } | 607 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 waiting_for_token_ = true; | 639 waiting_for_token_ = true; |
| 640 } | 640 } |
| 641 | 641 |
| 642 void PromptBrowserLoginFunction::OnLoginFailure( | 642 void PromptBrowserLoginFunction::OnLoginFailure( |
| 643 const GoogleServiceAuthError& error) { | 643 const GoogleServiceAuthError& error) { |
| 644 SendResponse(false); | 644 SendResponse(false); |
| 645 // Matches the AddRef in RunImpl(). | 645 // Matches the AddRef in RunImpl(). |
| 646 Release(); | 646 Release(); |
| 647 } | 647 } |
| 648 | 648 |
| 649 void PromptBrowserLoginFunction::Observe(NotificationType type, | 649 void PromptBrowserLoginFunction::Observe(int type, |
| 650 const NotificationSource& source, | 650 const NotificationSource& source, |
| 651 const NotificationDetails& details) { | 651 const NotificationDetails& details) { |
| 652 // Make sure this notification is for the service we are interested in. | 652 // Make sure this notification is for the service we are interested in. |
| 653 std::string service; | 653 std::string service; |
| 654 if (type == NotificationType::TOKEN_AVAILABLE) { | 654 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { |
| 655 TokenService::TokenAvailableDetails* available = | 655 TokenService::TokenAvailableDetails* available = |
| 656 Details<TokenService::TokenAvailableDetails>(details).ptr(); | 656 Details<TokenService::TokenAvailableDetails>(details).ptr(); |
| 657 service = available->service(); | 657 service = available->service(); |
| 658 } else if (type == NotificationType::TOKEN_REQUEST_FAILED) { | 658 } else if (type == chrome::NOTIFICATION_TOKEN_REQUEST_FAILED) { |
| 659 TokenService::TokenRequestFailedDetails* failed = | 659 TokenService::TokenRequestFailedDetails* failed = |
| 660 Details<TokenService::TokenRequestFailedDetails>(details).ptr(); | 660 Details<TokenService::TokenRequestFailedDetails>(details).ptr(); |
| 661 service = failed->service(); | 661 service = failed->service(); |
| 662 } else { | 662 } else { |
| 663 NOTREACHED(); | 663 NOTREACHED(); |
| 664 } | 664 } |
| 665 | 665 |
| 666 if (service != GaiaConstants::kGaiaService) { | 666 if (service != GaiaConstants::kGaiaService) { |
| 667 return; | 667 return; |
| 668 } | 668 } |
| 669 | 669 |
| 670 DCHECK(waiting_for_token_); | 670 DCHECK(waiting_for_token_); |
| 671 | 671 |
| 672 result_.reset(CreateLoginResult(profile_->GetOriginalProfile())); | 672 result_.reset(CreateLoginResult(profile_->GetOriginalProfile())); |
| 673 SendResponse(true); | 673 SendResponse(true); |
| 674 | 674 |
| 675 // Matches the AddRef in RunImpl(). | 675 // Matches the AddRef in RunImpl(). |
| 676 Release(); | 676 Release(); |
| 677 } | 677 } |
| OLD | NEW |