| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/android/blimp/chrome_blimp_client_context_delegate.h" | 5 #include "chrome/browser/android/blimp/chrome_blimp_client_context_delegate.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "blimp/client/public/blimp_client_context.h" | 10 #include "blimp/client/public/blimp_client_context.h" |
| 11 #include "blimp/client/public/blimp_client_context_delegate.h" | 11 #include "blimp/client/public/blimp_client_context_delegate.h" |
| 12 #include "blimp/client/public/contents/blimp_contents.h" | 12 #include "blimp/client/public/contents/blimp_contents.h" |
| 13 #include "blimp/client/public/resources/blimp_strings.h" |
| 13 #include "blimp/client/support/resources/blimp_strings.h" | 14 #include "blimp/client/support/resources/blimp_strings.h" |
| 14 #include "chrome/browser/android/blimp/blimp_client_context_factory.h" | 15 #include "chrome/browser/android/blimp/blimp_client_context_factory.h" |
| 15 #include "chrome/browser/android/blimp/blimp_contents_profile_attachment.h" | 16 #include "chrome/browser/android/blimp/blimp_contents_profile_attachment.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 18 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "components/signin/core/browser/profile_identity_provider.h" | 20 #include "components/signin/core/browser/profile_identity_provider.h" |
| 20 #include "components/signin/core/browser/signin_manager.h" | 21 #include "components/signin/core/browser/signin_manager.h" |
| 21 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 36 void ChromeBlimpClientContextDelegate::AttachBlimpContentsHelpers( | 37 void ChromeBlimpClientContextDelegate::AttachBlimpContentsHelpers( |
| 37 blimp::client::BlimpContents* blimp_contents) { | 38 blimp::client::BlimpContents* blimp_contents) { |
| 38 AttachProfileToBlimpContents(blimp_contents, profile_); | 39 AttachProfileToBlimpContents(blimp_contents, profile_); |
| 39 } | 40 } |
| 40 | 41 |
| 41 void ChromeBlimpClientContextDelegate::OnAssignmentConnectionAttempted( | 42 void ChromeBlimpClientContextDelegate::OnAssignmentConnectionAttempted( |
| 42 blimp::client::AssignmentRequestResult result, | 43 blimp::client::AssignmentRequestResult result, |
| 43 const blimp::client::Assignment& assignment) { | 44 const blimp::client::Assignment& assignment) { |
| 44 if (result == blimp::client::ASSIGNMENT_REQUEST_RESULT_OK) | 45 if (result == blimp::client::ASSIGNMENT_REQUEST_RESULT_OK) |
| 45 return; | 46 return; |
| 46 | 47 base::string16 message = blimp::string::BlimpPrefix( |
| 47 // TODO(xingliu): All strings shown in the UI should be accessed through grd | 48 blimp::string::AssignmentResultErrorToString(result)); |
| 48 // files. https://crbug.com/630687 | |
| 49 std::stringstream ss; | |
| 50 ss << "Assignment failed, reason: " << result << "."; | |
| 51 base::string16 message = | |
| 52 blimp::string::BlimpPrefix(base::UTF8ToUTF16(ss.str())); | |
| 53 ShowMessage(message, false); | 49 ShowMessage(message, false); |
| 54 } | 50 } |
| 55 | 51 |
| 56 std::unique_ptr<IdentityProvider> | 52 std::unique_ptr<IdentityProvider> |
| 57 ChromeBlimpClientContextDelegate::CreateIdentityProvider() { | 53 ChromeBlimpClientContextDelegate::CreateIdentityProvider() { |
| 58 return base::WrapUnique<IdentityProvider>(new ProfileIdentityProvider( | 54 return base::WrapUnique<IdentityProvider>(new ProfileIdentityProvider( |
| 59 SigninManagerFactory::GetForProfile(profile_), | 55 SigninManagerFactory::GetForProfile(profile_), |
| 60 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), | 56 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), |
| 61 base::Closure())); | 57 base::Closure())); |
| 62 } | 58 } |
| 63 | 59 |
| 64 void ChromeBlimpClientContextDelegate::OnAuthenticationError( | 60 void ChromeBlimpClientContextDelegate::OnAuthenticationError( |
| 65 const GoogleServiceAuthError& error) { | 61 const GoogleServiceAuthError& error) { |
| 66 LOG(ERROR) << "GoogleAuth error : " << error.ToString(); | 62 LOG(ERROR) << "GoogleAuth error : " << error.ToString(); |
| 67 base::string16 message = blimp::string::BlimpPrefix( | 63 base::string16 message = blimp::string::BlimpPrefix( |
| 68 l10n_util::GetStringUTF16(IDS_BLIMP_SIGNIN_GET_TOKEN_FAILED)); | 64 l10n_util::GetStringUTF16(IDS_BLIMP_SIGNIN_GET_TOKEN_FAILED)); |
| 69 ShowMessage(message, false); | 65 ShowMessage(message, false); |
| 70 } | 66 } |
| 71 | 67 |
| 72 void ChromeBlimpClientContextDelegate::OnConnected() { | 68 void ChromeBlimpClientContextDelegate::OnConnected() { |
| 73 base::string16 message = blimp::string::BlimpPrefix( | 69 base::string16 message = blimp::string::BlimpPrefix( |
| 74 l10n_util::GetStringUTF16(IDS_BLIMP_NETWORK_CONNECTED)); | 70 l10n_util::GetStringUTF16(IDS_BLIMP_NETWORK_CONNECTED)); |
| 75 ShowMessage(message, true); | 71 ShowMessage(message, true); |
| 76 } | 72 } |
| 77 | 73 |
| 78 void ChromeBlimpClientContextDelegate::OnEngineDisconnected(int result) { | 74 void ChromeBlimpClientContextDelegate::OnEngineDisconnected(int result) { |
| 79 OnDisconnected(base::UTF8ToUTF16(base::IntToString(result))); | 75 OnDisconnected(blimp::string::EndConnectionMessageToString(result)); |
| 80 } | 76 } |
| 81 | 77 |
| 82 void ChromeBlimpClientContextDelegate::OnNetworkDisconnected(int result) { | 78 void ChromeBlimpClientContextDelegate::OnNetworkDisconnected(int result) { |
| 83 OnDisconnected(base::UTF8ToUTF16(net::ErrorToShortString(result))); | 79 OnDisconnected(base::UTF8ToUTF16(net::ErrorToShortString(result))); |
| 84 } | 80 } |
| 85 | 81 |
| 86 void ChromeBlimpClientContextDelegate::ShowMessage( | 82 void ChromeBlimpClientContextDelegate::ShowMessage( |
| 87 const base::string16& message, | 83 const base::string16& message, |
| 88 bool short_message) {} | 84 bool short_message) {} |
| 89 | 85 |
| 90 void ChromeBlimpClientContextDelegate::OnDisconnected( | 86 void ChromeBlimpClientContextDelegate::OnDisconnected( |
| 91 const base::string16& reason) { | 87 const base::string16& reason) { |
| 92 ShowMessage(blimp::string::BlimpPrefix(l10n_util::GetStringFUTF16( | 88 ShowMessage(blimp::string::BlimpPrefix(l10n_util::GetStringFUTF16( |
| 93 IDS_BLIMP_NETWORK_DISCONNECTED, reason)), | 89 IDS_BLIMP_NETWORK_DISCONNECTED, reason)), |
| 94 false); | 90 false); |
| 95 } | 91 } |
| OLD | NEW |