Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: chrome/browser/android/blimp/chrome_blimp_client_context_delegate.cc

Issue 2391263005: Propagate error messages to UI for blimp. (Closed)
Patch Set: Minor fixes. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
9 #include "base/strings/utf_string_conversions.h"
8 #include "blimp/client/public/blimp_client_context.h" 10 #include "blimp/client/public/blimp_client_context.h"
9 #include "blimp/client/public/blimp_client_context_delegate.h" 11 #include "blimp/client/public/blimp_client_context_delegate.h"
10 #include "blimp/client/public/contents/blimp_contents.h" 12 #include "blimp/client/public/contents/blimp_contents.h"
11 #include "chrome/browser/android/blimp/blimp_client_context_factory.h" 13 #include "chrome/browser/android/blimp/blimp_client_context_factory.h"
12 #include "chrome/browser/android/blimp/blimp_contents_profile_attachment.h" 14 #include "chrome/browser/android/blimp/blimp_contents_profile_attachment.h"
13 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
15 #include "chrome/browser/signin/signin_manager_factory.h" 17 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "components/signin/core/browser/profile_identity_provider.h" 18 #include "components/signin/core/browser/profile_identity_provider.h"
17 #include "components/signin/core/browser/signin_manager.h" 19 #include "components/signin/core/browser/signin_manager.h"
20 #include "net/base/net_errors.h"
18 21
19 ChromeBlimpClientContextDelegate::ChromeBlimpClientContextDelegate( 22 ChromeBlimpClientContextDelegate::ChromeBlimpClientContextDelegate(
20 Profile* profile) 23 Profile* profile)
21 : profile_(profile), 24 : profile_(profile),
22 blimp_client_context_( 25 blimp_client_context_(
23 BlimpClientContextFactory::GetForBrowserContext(profile)) { 26 BlimpClientContextFactory::GetForBrowserContext(profile)) {
24 blimp_client_context_->SetDelegate(this); 27 blimp_client_context_->SetDelegate(this);
25 } 28 }
26 29
27 ChromeBlimpClientContextDelegate::~ChromeBlimpClientContextDelegate() { 30 ChromeBlimpClientContextDelegate::~ChromeBlimpClientContextDelegate() {
28 blimp_client_context_->SetDelegate(nullptr); 31 blimp_client_context_->SetDelegate(nullptr);
29 } 32 }
30 33
31 void ChromeBlimpClientContextDelegate::AttachBlimpContentsHelpers( 34 void ChromeBlimpClientContextDelegate::AttachBlimpContentsHelpers(
32 blimp::client::BlimpContents* blimp_contents) { 35 blimp::client::BlimpContents* blimp_contents) {
33 AttachProfileToBlimpContents(blimp_contents, profile_); 36 AttachProfileToBlimpContents(blimp_contents, profile_);
34 } 37 }
35 38
36 void ChromeBlimpClientContextDelegate::OnAssignmentConnectionAttempted( 39 void ChromeBlimpClientContextDelegate::OnAssignmentConnectionAttempted(
37 blimp::client::AssignmentRequestResult result, 40 blimp::client::AssignmentRequestResult result,
38 const blimp::client::Assignment& assignment) {} 41 const blimp::client::Assignment& assignment) {
42 if (result == blimp::client::ASSIGNMENT_REQUEST_RESULT_OK)
43 return;
44
45 // TODO(xingliu): All strings shown in the UI should be accessed through grd
46 // files. https://crbug.com/630687
47 std::stringstream ss;
48 ss << "Blimp: Assignment failed, reason: " << result << ".";
49 ShowMessage(base::UTF8ToUTF16(ss.str()), false);
50 }
39 51
40 std::unique_ptr<IdentityProvider> 52 std::unique_ptr<IdentityProvider>
41 ChromeBlimpClientContextDelegate::CreateIdentityProvider() { 53 ChromeBlimpClientContextDelegate::CreateIdentityProvider() {
42 return base::WrapUnique<IdentityProvider>(new ProfileIdentityProvider( 54 return base::WrapUnique<IdentityProvider>(new ProfileIdentityProvider(
43 SigninManagerFactory::GetForProfile(profile_), 55 SigninManagerFactory::GetForProfile(profile_),
44 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), 56 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
45 base::Closure())); 57 base::Closure()));
46 } 58 }
47 59
48 void ChromeBlimpClientContextDelegate::OnAuthenticationError( 60 void ChromeBlimpClientContextDelegate::OnAuthenticationError(
49 BlimpClientContextDelegate::AuthError error) { 61 const GoogleServiceAuthError& error) {
50 switch (error) { 62 LOG(ERROR) << "GoogleAuth error : " << error.ToString();
51 case AuthError::NOT_SIGNED_IN: 63 ShowMessage(base::UTF8ToUTF16("Blimp: Failed to get OAuth2 token."), false);
52 // User need to signed in first, on Android it's handled in Java layer
53 // before the connection.
54 VLOG(1) << "User is not signed in before connection to Blimp.";
55 break;
56 case AuthError::OAUTH_TOKEN_FAIL:
57 // TODO(xingliu): Alert the user in UI.
58 // There is an known issue that ongoing request can be cancelled when
59 // Android layer updates the refresh token.
60 break;
61 default:
62 LOG(WARNING) << "Unknown Blimp error.";
63 }
64 } 64 }
65
66 void ChromeBlimpClientContextDelegate::OnConnected() {
67 ShowMessage(base::UTF8ToUTF16("Blimp: Connected."), true);
68 }
69
70 void ChromeBlimpClientContextDelegate::OnEngineDisconnected(int result) {
71 OnDisconnected(base::UTF8ToUTF16(base::IntToString(result)));
72 }
73
74 void ChromeBlimpClientContextDelegate::OnNetworkDisconnected(int result) {
75 OnDisconnected(base::UTF8ToUTF16(net::ErrorToShortString(result)));
76 }
77
78 void ChromeBlimpClientContextDelegate::ShowMessage(
79 const base::string16& message,
80 bool short_message) {}
81
82 void ChromeBlimpClientContextDelegate::OnDisconnected(
83 const base::string16& reason) {
84 std::stringstream ss;
85 ss << "Blimp: Disconnected(" << reason << ").";
86 ShowMessage(base::UTF8ToUTF16(ss.str()), false);
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698