| 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/chromeos/arc/arc_support_host.h" | 5 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 6 | 6 |
| 7 #include "ash/system/chromeos/devicetype_utils.h" | 7 #include "ash/system/chromeos/devicetype_utils.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 // static | 31 // static |
| 32 const char ArcSupportHost::kHostName[] = "com.google.arc_support"; | 32 const char ArcSupportHost::kHostName[] = "com.google.arc_support"; |
| 33 | 33 |
| 34 // static | 34 // static |
| 35 const char* const ArcSupportHost::kHostOrigin[] = { | 35 const char* const ArcSupportHost::kHostOrigin[] = { |
| 36 "chrome-extension://cnbgggchhmkkdmeppjobngjoejnihlei/"}; | 36 "chrome-extension://cnbgggchhmkkdmeppjobngjoejnihlei/"}; |
| 37 | 37 |
| 38 // static | 38 // static |
| 39 scoped_ptr<extensions::NativeMessageHost> ArcSupportHost::Create() { | 39 std::unique_ptr<extensions::NativeMessageHost> ArcSupportHost::Create() { |
| 40 return scoped_ptr<NativeMessageHost>(new ArcSupportHost()); | 40 return std::unique_ptr<NativeMessageHost>(new ArcSupportHost()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 ArcSupportHost::ArcSupportHost() { | 43 ArcSupportHost::ArcSupportHost() { |
| 44 arc::ArcAuthService::Get()->AddObserver(this); | 44 arc::ArcAuthService::Get()->AddObserver(this); |
| 45 } | 45 } |
| 46 | 46 |
| 47 ArcSupportHost::~ArcSupportHost() { | 47 ArcSupportHost::~ArcSupportHost() { |
| 48 arc::ArcAuthService::Get()->RemoveObserver(this); | 48 arc::ArcAuthService::Get()->RemoveObserver(this); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void ArcSupportHost::Start(Client* client) { | 51 void ArcSupportHost::Start(Client* client) { |
| 52 DCHECK(!client_); | 52 DCHECK(!client_); |
| 53 client_ = client; | 53 client_ = client; |
| 54 | 54 |
| 55 SendLocalization(); | 55 SendLocalization(); |
| 56 | 56 |
| 57 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | 57 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); |
| 58 OnOptInUIShowPage(arc_auth_service->ui_page(), | 58 OnOptInUIShowPage(arc_auth_service->ui_page(), |
| 59 arc_auth_service->ui_page_status()); | 59 arc_auth_service->ui_page_status()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void ArcSupportHost::SendLocalization() { | 62 void ArcSupportHost::SendLocalization() { |
| 63 DCHECK(client_); | 63 DCHECK(client_); |
| 64 scoped_ptr<base::DictionaryValue> localized_strings( | 64 std::unique_ptr<base::DictionaryValue> localized_strings( |
| 65 new base::DictionaryValue()); | 65 new base::DictionaryValue()); |
| 66 base::string16 device_name = ash::GetChromeOSDeviceName(); | 66 base::string16 device_name = ash::GetChromeOSDeviceName(); |
| 67 localized_strings->SetString( | 67 localized_strings->SetString( |
| 68 "greetingHeader", | 68 "greetingHeader", |
| 69 l10n_util::GetStringFUTF16(IDS_ARC_OPT_IN_DIALOG_HEADER, device_name)); | 69 l10n_util::GetStringFUTF16(IDS_ARC_OPT_IN_DIALOG_HEADER, device_name)); |
| 70 localized_strings->SetString( | 70 localized_strings->SetString( |
| 71 "greetingDescription", | 71 "greetingDescription", |
| 72 l10n_util::GetStringFUTF16(IDS_ARC_OPT_IN_DIALOG_DESCRIPTION, | 72 l10n_util::GetStringFUTF16(IDS_ARC_OPT_IN_DIALOG_DESCRIPTION, |
| 73 device_name)); | 73 device_name)); |
| 74 localized_strings->SetString( | 74 localized_strings->SetString( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 base::DictionaryValue response; | 120 base::DictionaryValue response; |
| 121 response.SetString(kAction, kActionShowPage); | 121 response.SetString(kAction, kActionShowPage); |
| 122 response.SetInteger(kPage, static_cast<int>(page)); | 122 response.SetInteger(kPage, static_cast<int>(page)); |
| 123 response.SetString(kStatus, status); | 123 response.SetString(kStatus, status); |
| 124 std::string response_string; | 124 std::string response_string; |
| 125 base::JSONWriter::Write(response, &response_string); | 125 base::JSONWriter::Write(response, &response_string); |
| 126 client_->PostMessageFromNativeHost(response_string); | 126 client_->PostMessageFromNativeHost(response_string); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void ArcSupportHost::OnMessage(const std::string& request_string) { | 129 void ArcSupportHost::OnMessage(const std::string& request_string) { |
| 130 scoped_ptr<base::Value> request_value = | 130 std::unique_ptr<base::Value> request_value = |
| 131 base::JSONReader::Read(request_string); | 131 base::JSONReader::Read(request_string); |
| 132 base::DictionaryValue* request; | 132 base::DictionaryValue* request; |
| 133 if (!request_value || !request_value->GetAsDictionary(&request)) { | 133 if (!request_value || !request_value->GetAsDictionary(&request)) { |
| 134 NOTREACHED(); | 134 NOTREACHED(); |
| 135 return; | 135 return; |
| 136 } | 136 } |
| 137 | 137 |
| 138 std::string action; | 138 std::string action; |
| 139 if (!request->GetString(kAction, &action)) { | 139 if (!request->GetString(kAction, &action)) { |
| 140 NOTREACHED(); | 140 NOTREACHED(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 154 arc::ArcAuthService::Get()->CancelAuthCode(); | 154 arc::ArcAuthService::Get()->CancelAuthCode(); |
| 155 } else { | 155 } else { |
| 156 NOTREACHED(); | 156 NOTREACHED(); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() | 160 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() |
| 161 const { | 161 const { |
| 162 return base::ThreadTaskRunnerHandle::Get(); | 162 return base::ThreadTaskRunnerHandle::Get(); |
| 163 } | 163 } |
| OLD | NEW |