Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/common/system/chromeos/devicetype_utils.h" | 10 #include "ash/common/system/chromeos/devicetype_utils.h" |
| 11 #include "base/bind.h" | |
| 11 #include "base/i18n/timezone.h" | 12 #include "base/i18n/timezone.h" |
| 12 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 18 #include "chrome/browser/extensions/extension_util.h" | 19 #include "chrome/browser/extensions/extension_util.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 21 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 constexpr char kIsBackupRestoreEnabled[] = "isBackupRestoreEnabled"; | 80 constexpr char kIsBackupRestoreEnabled[] = "isBackupRestoreEnabled"; |
| 80 constexpr char kIsLocationServiceEnabled[] = "isLocationServiceEnabled"; | 81 constexpr char kIsLocationServiceEnabled[] = "isLocationServiceEnabled"; |
| 81 | 82 |
| 82 // "onRetryClicked" is fired when a user clicks "RETRY" button on the error | 83 // "onRetryClicked" is fired when a user clicks "RETRY" button on the error |
| 83 // page. | 84 // page. |
| 84 constexpr char kEventOnRetryClicked[] = "onRetryClicked"; | 85 constexpr char kEventOnRetryClicked[] = "onRetryClicked"; |
| 85 | 86 |
| 86 // "onSendFeedbackClicked" is fired when a user clicks "Send Feedback" button. | 87 // "onSendFeedbackClicked" is fired when a user clicks "Send Feedback" button. |
| 87 constexpr char kEventOnSendFeedbackClicked[] = "onSendFeedbackClicked"; | 88 constexpr char kEventOnSendFeedbackClicked[] = "onSendFeedbackClicked"; |
| 88 | 89 |
| 90 void RequestOpenApp(Profile* profile) { | |
| 91 const extensions::Extension* extension = | |
| 92 extensions::ExtensionRegistry::Get(profile)->GetInstalledExtension( | |
| 93 ArcSupportHost::kHostAppId); | |
| 94 DCHECK(extension); | |
| 95 DCHECK( | |
| 96 extensions::util::IsAppLaunchable(ArcSupportHost::kHostAppId, profile)); | |
| 97 OpenApplication(CreateAppLaunchParamsUserContainer( | |
| 98 profile, extension, WindowOpenDisposition::NEW_WINDOW, | |
| 99 extensions::SOURCE_CHROME_INTERNAL)); | |
| 100 } | |
| 101 | |
| 89 std::ostream& operator<<(std::ostream& os, ArcSupportHost::UIPage ui_page) { | 102 std::ostream& operator<<(std::ostream& os, ArcSupportHost::UIPage ui_page) { |
| 90 switch (ui_page) { | 103 switch (ui_page) { |
| 91 case ArcSupportHost::UIPage::NO_PAGE: | 104 case ArcSupportHost::UIPage::NO_PAGE: |
| 92 return os << "NO_PAGE"; | 105 return os << "NO_PAGE"; |
| 93 case ArcSupportHost::UIPage::TERMS: | 106 case ArcSupportHost::UIPage::TERMS: |
| 94 return os << "TERMS"; | 107 return os << "TERMS"; |
| 95 case ArcSupportHost::UIPage::LSO: | 108 case ArcSupportHost::UIPage::LSO: |
| 96 return os << "LSO"; | 109 return os << "LSO"; |
| 97 case ArcSupportHost::UIPage::ARC_LOADING: | 110 case ArcSupportHost::UIPage::ARC_LOADING: |
| 98 return os << "ARC_LOADING"; | 111 return os << "ARC_LOADING"; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 } | 146 } |
| 134 | 147 |
| 135 } // namespace | 148 } // namespace |
| 136 | 149 |
| 137 // static | 150 // static |
| 138 const char ArcSupportHost::kHostAppId[] = "cnbgggchhmkkdmeppjobngjoejnihlei"; | 151 const char ArcSupportHost::kHostAppId[] = "cnbgggchhmkkdmeppjobngjoejnihlei"; |
| 139 | 152 |
| 140 // static | 153 // static |
| 141 const char ArcSupportHost::kStorageId[] = "arc_support"; | 154 const char ArcSupportHost::kStorageId[] = "arc_support"; |
| 142 | 155 |
| 143 ArcSupportHost::ArcSupportHost(Profile* profile) : profile_(profile) {} | 156 ArcSupportHost::ArcSupportHost(Profile* profile) |
| 157 : profile_(profile), | |
| 158 request_open_app_callback_(base::Bind(&RequestOpenApp)) { | |
| 159 DCHECK(profile_); | |
| 160 } | |
| 144 | 161 |
| 145 ArcSupportHost::~ArcSupportHost() { | 162 ArcSupportHost::~ArcSupportHost() { |
| 146 if (message_host_) | 163 if (message_host_) |
| 147 DisconnectMessageHost(); | 164 DisconnectMessageHost(); |
| 148 } | 165 } |
| 149 | 166 |
| 150 void ArcSupportHost::AddObserver(Observer* observer) { | 167 void ArcSupportHost::AddObserver(Observer* observer) { |
| 151 observer_list_.AddObserver(observer); | 168 observer_list_.AddObserver(observer); |
| 152 } | 169 } |
| 153 | 170 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 | 327 |
| 311 void ArcSupportHost::SetMessageHost(arc::ArcSupportMessageHost* message_host) { | 328 void ArcSupportHost::SetMessageHost(arc::ArcSupportMessageHost* message_host) { |
| 312 if (message_host_ == message_host) | 329 if (message_host_ == message_host) |
| 313 return; | 330 return; |
| 314 | 331 |
| 315 app_start_pending_ = false; | 332 app_start_pending_ = false; |
| 316 if (message_host_) | 333 if (message_host_) |
| 317 DisconnectMessageHost(); | 334 DisconnectMessageHost(); |
| 318 message_host_ = message_host; | 335 message_host_ = message_host; |
| 319 message_host_->SetObserver(this); | 336 message_host_->SetObserver(this); |
| 320 display::Screen::GetScreen()->AddObserver(this); | 337 display::Screen* screen = display::Screen::GetScreen(); |
|
hidehiko
2016/11/28 12:42:54
Relaxed for testing. Ditto for below.
| |
| 338 if (screen) | |
| 339 screen->AddObserver(this); | |
| 321 | 340 |
| 322 if (!Initialize()) { | 341 if (!Initialize()) { |
| 323 Close(); | 342 Close(); |
| 324 return; | 343 return; |
| 325 } | 344 } |
| 326 | 345 |
| 327 // Hereafter, install the requested ui state into the ARC support Chrome app. | 346 // Hereafter, install the requested ui state into the ARC support Chrome app. |
| 328 | 347 |
| 329 // Set preference checkbox state. | 348 // Set preference checkbox state. |
| 330 SendPreferenceCheckboxUpdate(kActionSetMetricsMode, metrics_checkbox_); | 349 SendPreferenceCheckboxUpdate(kActionSetMetricsMode, metrics_checkbox_); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 345 | 364 |
| 346 void ArcSupportHost::UnsetMessageHost( | 365 void ArcSupportHost::UnsetMessageHost( |
| 347 arc::ArcSupportMessageHost* message_host) { | 366 arc::ArcSupportMessageHost* message_host) { |
| 348 if (message_host_ != message_host) | 367 if (message_host_ != message_host) |
| 349 return; | 368 return; |
| 350 DisconnectMessageHost(); | 369 DisconnectMessageHost(); |
| 351 } | 370 } |
| 352 | 371 |
| 353 void ArcSupportHost::DisconnectMessageHost() { | 372 void ArcSupportHost::DisconnectMessageHost() { |
| 354 DCHECK(message_host_); | 373 DCHECK(message_host_); |
| 355 display::Screen::GetScreen()->RemoveObserver(this); | 374 display::Screen* screen = display::Screen::GetScreen(); |
| 375 if (screen) | |
| 376 screen->RemoveObserver(this); | |
| 356 message_host_->SetObserver(nullptr); | 377 message_host_->SetObserver(nullptr); |
| 357 message_host_ = nullptr; | 378 message_host_ = nullptr; |
| 358 } | 379 } |
| 359 | 380 |
| 360 void ArcSupportHost::RequestAppStart() { | 381 void ArcSupportHost::RequestAppStart() { |
| 361 DCHECK(!message_host_); | 382 DCHECK(!message_host_); |
| 362 DCHECK(!app_start_pending_); | 383 DCHECK(!app_start_pending_); |
| 363 | 384 |
| 364 app_start_pending_ = true; | 385 app_start_pending_ = true; |
| 365 const extensions::Extension* extension = | 386 request_open_app_callback_.Run(profile_); |
| 366 extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension( | 387 } |
| 367 kHostAppId); | 388 |
| 368 DCHECK(extension); | 389 void ArcSupportHost::SetRequestOpenAppCallbackForTest( |
| 369 DCHECK(extensions::util::IsAppLaunchable(kHostAppId, profile_)); | 390 const RequestOpenAppCallback& callback) { |
| 370 OpenApplication(CreateAppLaunchParamsUserContainer( | 391 DCHECK(!message_host_); |
| 371 profile_, extension, WindowOpenDisposition::NEW_WINDOW, | 392 DCHECK(!app_start_pending_); |
| 372 extensions::SOURCE_CHROME_INTERNAL)); | 393 DCHECK(!callback.is_null()); |
| 394 request_open_app_callback_ = callback; | |
| 373 } | 395 } |
| 374 | 396 |
| 375 bool ArcSupportHost::Initialize() { | 397 bool ArcSupportHost::Initialize() { |
| 376 DCHECK(message_host_); | 398 DCHECK(message_host_); |
| 377 | 399 |
| 378 auto loadtime_data = base::MakeUnique<base::DictionaryValue>(); | 400 auto loadtime_data = base::MakeUnique<base::DictionaryValue>(); |
| 379 base::string16 device_name = ash::GetChromeOSDeviceName(); | 401 base::string16 device_name = ash::GetChromeOSDeviceName(); |
| 380 loadtime_data->SetString( | 402 loadtime_data->SetString( |
| 381 "greetingHeader", | 403 "greetingHeader", |
| 382 l10n_util::GetStringFUTF16(IDS_ARC_OPT_IN_DIALOG_HEADER, device_name)); | 404 l10n_util::GetStringFUTF16(IDS_ARC_OPT_IN_DIALOG_HEADER, device_name)); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 | 478 |
| 457 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 479 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 458 webui::SetLoadTimeDataDefaults(app_locale, loadtime_data.get()); | 480 webui::SetLoadTimeDataDefaults(app_locale, loadtime_data.get()); |
| 459 | 481 |
| 460 base::DictionaryValue message; | 482 base::DictionaryValue message; |
| 461 message.SetString(kAction, kActionInitialize); | 483 message.SetString(kAction, kActionInitialize); |
| 462 message.Set(kData, std::move(loadtime_data)); | 484 message.Set(kData, std::move(loadtime_data)); |
| 463 | 485 |
| 464 const std::string device_id = user_manager::known_user::GetDeviceId( | 486 const std::string device_id = user_manager::known_user::GetDeviceId( |
| 465 multi_user_util::GetAccountIdFromProfile(profile_)); | 487 multi_user_util::GetAccountIdFromProfile(profile_)); |
| 466 DCHECK(!device_id.empty()); | |
|
hidehiko
2016/11/28 12:42:54
Relaxed for testing.
| |
| 467 message.SetString(kDeviceId, device_id); | 488 message.SetString(kDeviceId, device_id); |
| 468 | 489 |
| 469 message_host_->SendMessage(message); | 490 message_host_->SendMessage(message); |
| 470 return true; | 491 return true; |
| 471 } | 492 } |
| 472 | 493 |
| 473 void ArcSupportHost::OnDisplayAdded(const display::Display& new_display) {} | 494 void ArcSupportHost::OnDisplayAdded(const display::Display& new_display) {} |
| 474 | 495 |
| 475 void ArcSupportHost::OnDisplayRemoved(const display::Display& old_display) {} | 496 void ArcSupportHost::OnDisplayRemoved(const display::Display& old_display) {} |
| 476 | 497 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 for (auto& observer : observer_list_) | 543 for (auto& observer : observer_list_) |
| 523 observer.OnRetryClicked(); | 544 observer.OnRetryClicked(); |
| 524 } else if (event == kEventOnSendFeedbackClicked) { | 545 } else if (event == kEventOnSendFeedbackClicked) { |
| 525 for (auto& observer : observer_list_) | 546 for (auto& observer : observer_list_) |
| 526 observer.OnSendFeedbackClicked(); | 547 observer.OnSendFeedbackClicked(); |
| 527 } else { | 548 } else { |
| 528 LOG(ERROR) << "Unknown message: " << event; | 549 LOG(ERROR) << "Unknown message: " << event; |
| 529 NOTREACHED(); | 550 NOTREACHED(); |
| 530 } | 551 } |
| 531 } | 552 } |
| OLD | NEW |