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/support/resources/blimp_strings.h" |
13 #include "chrome/browser/android/blimp/blimp_client_context_factory.h" | 14 #include "chrome/browser/android/blimp/blimp_client_context_factory.h" |
14 #include "chrome/browser/android/blimp/blimp_contents_profile_attachment.h" | 15 #include "chrome/browser/android/blimp/blimp_contents_profile_attachment.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
17 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
18 #include "components/signin/core/browser/profile_identity_provider.h" | 19 #include "components/signin/core/browser/profile_identity_provider.h" |
19 #include "components/signin/core/browser/signin_manager.h" | 20 #include "components/signin/core/browser/signin_manager.h" |
20 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 22 #include "ui/base/l10n/l10n_util.h" |
21 | 23 |
22 ChromeBlimpClientContextDelegate::ChromeBlimpClientContextDelegate( | 24 ChromeBlimpClientContextDelegate::ChromeBlimpClientContextDelegate( |
23 Profile* profile) | 25 Profile* profile) |
24 : profile_(profile), | 26 : profile_(profile), |
25 blimp_client_context_( | 27 blimp_client_context_( |
26 BlimpClientContextFactory::GetForBrowserContext(profile)) { | 28 BlimpClientContextFactory::GetForBrowserContext(profile)) { |
27 blimp_client_context_->SetDelegate(this); | 29 blimp_client_context_->SetDelegate(this); |
28 } | 30 } |
29 | 31 |
30 ChromeBlimpClientContextDelegate::~ChromeBlimpClientContextDelegate() { | 32 ChromeBlimpClientContextDelegate::~ChromeBlimpClientContextDelegate() { |
31 blimp_client_context_->SetDelegate(nullptr); | 33 blimp_client_context_->SetDelegate(nullptr); |
32 } | 34 } |
33 | 35 |
34 void ChromeBlimpClientContextDelegate::AttachBlimpContentsHelpers( | 36 void ChromeBlimpClientContextDelegate::AttachBlimpContentsHelpers( |
35 blimp::client::BlimpContents* blimp_contents) { | 37 blimp::client::BlimpContents* blimp_contents) { |
36 AttachProfileToBlimpContents(blimp_contents, profile_); | 38 AttachProfileToBlimpContents(blimp_contents, profile_); |
37 } | 39 } |
38 | 40 |
39 void ChromeBlimpClientContextDelegate::OnAssignmentConnectionAttempted( | 41 void ChromeBlimpClientContextDelegate::OnAssignmentConnectionAttempted( |
40 blimp::client::AssignmentRequestResult result, | 42 blimp::client::AssignmentRequestResult result, |
41 const blimp::client::Assignment& assignment) { | 43 const blimp::client::Assignment& assignment) { |
42 if (result == blimp::client::ASSIGNMENT_REQUEST_RESULT_OK) | 44 if (result == blimp::client::ASSIGNMENT_REQUEST_RESULT_OK) |
43 return; | 45 return; |
44 | 46 |
45 // TODO(xingliu): All strings shown in the UI should be accessed through grd | 47 // TODO(xingliu): All strings shown in the UI should be accessed through grd |
46 // files. https://crbug.com/630687 | 48 // files. https://crbug.com/630687 |
47 std::stringstream ss; | 49 std::stringstream ss; |
48 ss << "Blimp: Assignment failed, reason: " << result << "."; | 50 ss << "Assignment failed, reason: " << result << "."; |
49 ShowMessage(base::UTF8ToUTF16(ss.str()), false); | 51 base::string16 message = |
| 52 blimp::string::BlimpPrefix(base::UTF8ToUTF16(ss.str())); |
| 53 ShowMessage(message, false); |
50 } | 54 } |
51 | 55 |
52 std::unique_ptr<IdentityProvider> | 56 std::unique_ptr<IdentityProvider> |
53 ChromeBlimpClientContextDelegate::CreateIdentityProvider() { | 57 ChromeBlimpClientContextDelegate::CreateIdentityProvider() { |
54 return base::WrapUnique<IdentityProvider>(new ProfileIdentityProvider( | 58 return base::WrapUnique<IdentityProvider>(new ProfileIdentityProvider( |
55 SigninManagerFactory::GetForProfile(profile_), | 59 SigninManagerFactory::GetForProfile(profile_), |
56 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), | 60 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), |
57 base::Closure())); | 61 base::Closure())); |
58 } | 62 } |
59 | 63 |
60 void ChromeBlimpClientContextDelegate::OnAuthenticationError( | 64 void ChromeBlimpClientContextDelegate::OnAuthenticationError( |
61 const GoogleServiceAuthError& error) { | 65 const GoogleServiceAuthError& error) { |
62 LOG(ERROR) << "GoogleAuth error : " << error.ToString(); | 66 LOG(ERROR) << "GoogleAuth error : " << error.ToString(); |
63 ShowMessage(base::UTF8ToUTF16("Blimp: Failed to get OAuth2 token."), false); | 67 base::string16 message = blimp::string::BlimpPrefix( |
| 68 l10n_util::GetStringUTF16(IDS_BLIMP_SIGNIN_GET_TOKEN_FAILED)); |
| 69 ShowMessage(message, false); |
64 } | 70 } |
65 | 71 |
66 void ChromeBlimpClientContextDelegate::OnConnected() { | 72 void ChromeBlimpClientContextDelegate::OnConnected() { |
67 ShowMessage(base::UTF8ToUTF16("Blimp: Connected."), true); | 73 base::string16 message = blimp::string::BlimpPrefix( |
| 74 l10n_util::GetStringUTF16(IDS_BLIMP_NETWORK_CONNECTED)); |
| 75 ShowMessage(message, true); |
68 } | 76 } |
69 | 77 |
70 void ChromeBlimpClientContextDelegate::OnEngineDisconnected(int result) { | 78 void ChromeBlimpClientContextDelegate::OnEngineDisconnected(int result) { |
71 OnDisconnected(base::UTF8ToUTF16(base::IntToString(result))); | 79 OnDisconnected(base::UTF8ToUTF16(base::IntToString(result))); |
72 } | 80 } |
73 | 81 |
74 void ChromeBlimpClientContextDelegate::OnNetworkDisconnected(int result) { | 82 void ChromeBlimpClientContextDelegate::OnNetworkDisconnected(int result) { |
75 OnDisconnected(base::UTF8ToUTF16(net::ErrorToShortString(result))); | 83 OnDisconnected(base::UTF8ToUTF16(net::ErrorToShortString(result))); |
76 } | 84 } |
77 | 85 |
78 void ChromeBlimpClientContextDelegate::ShowMessage( | 86 void ChromeBlimpClientContextDelegate::ShowMessage( |
79 const base::string16& message, | 87 const base::string16& message, |
80 bool short_message) {} | 88 bool short_message) {} |
81 | 89 |
82 void ChromeBlimpClientContextDelegate::OnDisconnected( | 90 void ChromeBlimpClientContextDelegate::OnDisconnected( |
83 const base::string16& reason) { | 91 const base::string16& reason) { |
84 std::stringstream ss; | 92 ShowMessage(blimp::string::BlimpPrefix(l10n_util::GetStringFUTF16( |
85 ss << "Blimp: Disconnected(" << reason << ")."; | 93 IDS_BLIMP_NETWORK_DISCONNECTED, reason)), |
86 ShowMessage(base::UTF8ToUTF16(ss.str()), false); | 94 false); |
87 } | 95 } |
OLD | NEW |