| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/android/blimp/chrome_blimp_client_context_delegate.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "base/strings/string_number_conversions.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "blimp/client/public/blimp_client_context.h" | |
| 11 #include "blimp/client/public/blimp_client_context_delegate.h" | |
| 12 #include "blimp/client/public/contents/blimp_contents.h" | |
| 13 #include "blimp/client/public/resources/blimp_strings.h" | |
| 14 #include "blimp/client/support/resources/blimp_strings.h" | |
| 15 #include "chrome/browser/android/blimp/blimp_client_context_factory.h" | |
| 16 #include "chrome/browser/android/blimp/blimp_contents_profile_attachment.h" | |
| 17 #include "chrome/browser/profiles/profile.h" | |
| 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | |
| 19 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 20 #include "components/signin/core/browser/profile_identity_provider.h" | |
| 21 #include "components/signin/core/browser/signin_manager.h" | |
| 22 #include "net/base/net_errors.h" | |
| 23 #include "ui/base/l10n/l10n_util.h" | |
| 24 | |
| 25 ChromeBlimpClientContextDelegate::ChromeBlimpClientContextDelegate( | |
| 26 Profile* profile) | |
| 27 : profile_(profile), | |
| 28 blimp_client_context_( | |
| 29 BlimpClientContextFactory::GetForBrowserContext(profile)) { | |
| 30 blimp_client_context_->SetDelegate(this); | |
| 31 } | |
| 32 | |
| 33 ChromeBlimpClientContextDelegate::~ChromeBlimpClientContextDelegate() { | |
| 34 blimp_client_context_->SetDelegate(nullptr); | |
| 35 } | |
| 36 | |
| 37 void ChromeBlimpClientContextDelegate::AttachBlimpContentsHelpers( | |
| 38 blimp::client::BlimpContents* blimp_contents) { | |
| 39 AttachProfileToBlimpContents(blimp_contents, profile_); | |
| 40 } | |
| 41 | |
| 42 void ChromeBlimpClientContextDelegate::OnAssignmentConnectionAttempted( | |
| 43 blimp::client::AssignmentRequestResult result, | |
| 44 const blimp::client::Assignment& assignment) { | |
| 45 if (result == blimp::client::ASSIGNMENT_REQUEST_RESULT_OK) | |
| 46 return; | |
| 47 base::string16 message = blimp::string::BlimpPrefix( | |
| 48 blimp::string::AssignmentResultErrorToString(result)); | |
| 49 ShowMessage(message, false); | |
| 50 } | |
| 51 | |
| 52 std::unique_ptr<IdentityProvider> | |
| 53 ChromeBlimpClientContextDelegate::CreateIdentityProvider() { | |
| 54 return base::WrapUnique<IdentityProvider>(new ProfileIdentityProvider( | |
| 55 SigninManagerFactory::GetForProfile(profile_), | |
| 56 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), | |
| 57 base::Closure())); | |
| 58 } | |
| 59 | |
| 60 void ChromeBlimpClientContextDelegate::OnAuthenticationError( | |
| 61 const GoogleServiceAuthError& error) { | |
| 62 LOG(ERROR) << "GoogleAuth error : " << error.ToString(); | |
| 63 base::string16 message = blimp::string::BlimpPrefix( | |
| 64 l10n_util::GetStringUTF16(IDS_BLIMP_SIGNIN_GET_TOKEN_FAILED)); | |
| 65 ShowMessage(message, false); | |
| 66 } | |
| 67 | |
| 68 void ChromeBlimpClientContextDelegate::OnConnected() { | |
| 69 base::string16 message = blimp::string::BlimpPrefix( | |
| 70 l10n_util::GetStringUTF16(IDS_BLIMP_NETWORK_CONNECTED)); | |
| 71 ShowMessage(message, true); | |
| 72 } | |
| 73 | |
| 74 void ChromeBlimpClientContextDelegate::OnEngineDisconnected(int result) { | |
| 75 OnDisconnected(blimp::string::EndConnectionMessageToString(result)); | |
| 76 } | |
| 77 | |
| 78 void ChromeBlimpClientContextDelegate::OnNetworkDisconnected(int result) { | |
| 79 OnDisconnected(base::UTF8ToUTF16(net::ErrorToShortString(result))); | |
| 80 } | |
| 81 | |
| 82 void ChromeBlimpClientContextDelegate::ShowMessage( | |
| 83 const base::string16& message, | |
| 84 bool short_message) {} | |
| 85 | |
| 86 void ChromeBlimpClientContextDelegate::OnDisconnected( | |
| 87 const base::string16& reason) { | |
| 88 ShowMessage(blimp::string::BlimpPrefix(l10n_util::GetStringFUTF16( | |
| 89 IDS_BLIMP_NETWORK_DISCONNECTED, reason)), | |
| 90 false); | |
| 91 } | |
| OLD | NEW |