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

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 polish. 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) {
David Trainor- moved to gerrit 2016/10/07 06:58:53 Remove {} for single line if.
xingliu 2016/10/10 17:09:50 Done.
43 return;
44 }
45
46 // TODO(xingliu): All strings shown in the UI should be accessed through grd
47 // files. https://crbug.com/630687
48 std::stringstream ss;
49 ss << "Blimp: Assignment failed, reason: " << result << ".";
50 ShowMessage(base::UTF8ToUTF16(ss.str()), false);
51 }
39 52
40 std::unique_ptr<IdentityProvider> 53 std::unique_ptr<IdentityProvider>
41 ChromeBlimpClientContextDelegate::CreateIdentityProvider() { 54 ChromeBlimpClientContextDelegate::CreateIdentityProvider() {
42 return base::WrapUnique<IdentityProvider>(new ProfileIdentityProvider( 55 return base::WrapUnique<IdentityProvider>(new ProfileIdentityProvider(
43 SigninManagerFactory::GetForProfile(profile_), 56 SigninManagerFactory::GetForProfile(profile_),
44 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), 57 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
45 base::Closure())); 58 base::Closure()));
46 } 59 }
47 60
48 void ChromeBlimpClientContextDelegate::OnAuthenticationError( 61 void ChromeBlimpClientContextDelegate::OnAuthenticationError(
49 BlimpClientContextDelegate::AuthError error) { 62 const GoogleServiceAuthError& error) {
50 switch (error) { 63 LOG(ERROR) << "GoogleAuth error : " << error.ToString();
51 case AuthError::NOT_SIGNED_IN: 64 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 } 65 }
66
67 void ChromeBlimpClientContextDelegate::OnConnected() {
68 ShowMessage(base::UTF8ToUTF16("Blimp: Connected."), true);
69 }
70
71 void ChromeBlimpClientContextDelegate::OnEngineDisconnected(int result) {
72 OnDisconnected(base::UTF8ToUTF16(base::IntToString(result)));
73 }
74
75 void ChromeBlimpClientContextDelegate::OnNetworkDisconnected(int result) {
76 OnDisconnected(base::UTF8ToUTF16(net::ErrorToShortString(result)));
77 }
78
79 void ChromeBlimpClientContextDelegate::ShowMessage(
80 const base::string16& message,
81 bool short_message) {}
82
83 void ChromeBlimpClientContextDelegate::OnDisconnected(
84 const base::string16& reason) {
85 std::stringstream ss;
86 ss << "Blimp: Disconnected(" << reason << ").";
87 ShowMessage(base::UTF8ToUTF16(ss.str()), false);
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698