Index: chrome/browser/ui/webui/chromeos/login/wait_for_container_ready_screen_handler.cc |
diff --git a/chrome/browser/ui/webui/chromeos/login/wait_for_container_ready_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/wait_for_container_ready_screen_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d426fa5f29bfa8cf33707c968263ecb52ddc64ed |
--- /dev/null |
+++ b/chrome/browser/ui/webui/chromeos/login/wait_for_container_ready_screen_handler.cc |
@@ -0,0 +1,105 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/webui/chromeos/login/wait_for_container_ready_screen_handler.h" |
+ |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/chromeos/arc/arc_session_manager.h" |
+#include "chrome/browser/chromeos/login/oobe_screen.h" |
+#include "chrome/browser/chromeos/login/screens/wait_for_container_ready_screen.h" |
+#include "chrome/grit/generated_resources.h" |
+#include "components/login/localized_values_builder.h" |
+ |
+namespace { |
+ |
+const char kJsScreenPath[] = "login.WaitForContainerReadyScreen"; |
xiyuan
2017/06/19 16:36:02
nit: const -> constexpr
yueli
2017/06/19 18:49:18
Done.
|
+constexpr base::TimeDelta kWaitingTimeout = base::TimeDelta::FromMinutes(1); |
+ |
+} // namespace |
+ |
+namespace chromeos { |
+ |
+WaitForContainerReadyScreenHandler::WaitForContainerReadyScreenHandler() |
+ : BaseScreenHandler(kScreenId), weak_ptr_factory_(this) { |
+ set_call_js_prefix(kJsScreenPath); |
+ arc::ArcSessionManager::Get()->AddObserver(this); |
xiyuan
2017/06/19 16:36:02
nit: is_container_ready_ = arc::ArcSessionManager:
yueli
2017/06/19 18:49:18
Done.
|
+} |
+ |
+WaitForContainerReadyScreenHandler::~WaitForContainerReadyScreenHandler() { |
+ if (screen_) { |
+ screen_->OnViewDestroyed(this); |
+ } |
+ timer_.Stop(); |
+ arc::ArcSessionManager::Get()->RemoveObserver(this); |
+} |
+ |
+void WaitForContainerReadyScreenHandler::DeclareLocalizedValues( |
+ ::login::LocalizedValuesBuilder* builder) { |
+ builder->Add("locale", g_browser_process->GetApplicationLocale()); |
xc
2017/06/17 00:35:22
where is locale used?
yueli
2017/06/19 18:49:18
Done.
|
+ builder->Add("waitForContainerReadyTitle", |
+ IDS_WAIT_FOR_CONTAINER_READY_TITLE); |
+ builder->Add("waitForContainerReadyIntroMessage", |
+ IDS_WAIT_FOR_CONTAINER_READY_INTRO_MESSAGE); |
+} |
+ |
+void WaitForContainerReadyScreenHandler::Bind( |
+ WaitForContainerReadyScreen* screen) { |
+ BaseScreenHandler::SetBaseScreen(screen); |
+ screen_ = screen; |
+ if (page_is_ready()) |
+ Initialize(); |
+} |
+ |
+void WaitForContainerReadyScreenHandler::Unbind() { |
+ screen_ = nullptr; |
+ BaseScreenHandler::SetBaseScreen(nullptr); |
+ timer_.Stop(); |
+} |
+ |
+void WaitForContainerReadyScreenHandler::Show() { |
+ if (!page_is_ready() || !screen_) { |
+ show_on_init_ = true; |
+ return; |
+ } |
+ |
+ if (is_container_ready_) { |
+ screen_->OnContainerReady(); |
xc
2017/06/17 00:35:21
Why not return here and skip the timer and show sc
yueli
2017/06/19 18:49:18
Done.
|
+ } |
+ |
+ timer_.Start(FROM_HERE, kWaitingTimeout, |
+ base::Bind(&WaitForContainerReadyScreenHandler::OnTimeout, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ |
+ ShowScreen(kScreenId); |
+} |
+ |
+void WaitForContainerReadyScreenHandler::Hide() {} |
xc
2017/06/17 00:35:22
why we don't handle hide?
|
+ |
+void WaitForContainerReadyScreenHandler::OnArcInitialStart() { |
+ is_container_ready_ = true; |
+ if (!screen_) |
+ return; |
+ |
+ // TODO(updowndota): Remove the temporary delay after the potential racing |
+ // issue is eliminated. |
+ timer_.Stop(); |
+ timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), |
+ base::Bind(&WaitForContainerReadyScreenHandler::OnTimeout, |
xiyuan
2017/06/19 16:36:02
nit: Suggest to have a NotifyContainerReady method
yueli
2017/06/19 18:49:18
Done.
|
+ weak_ptr_factory_.GetWeakPtr())); |
+} |
+ |
+void WaitForContainerReadyScreenHandler::Initialize() { |
+ if (!screen_ || !show_on_init_) |
+ return; |
+ |
+ Show(); |
+ show_on_init_ = false; |
+} |
+ |
+void WaitForContainerReadyScreenHandler::OnTimeout() { |
+ if (screen_) |
xc
2017/06/17 00:35:21
add a todo for adding a histogram.
yueli
2017/06/19 18:49:18
Done.
|
+ screen_->OnContainerReady(); |
+} |
+ |
+} // namespace chromeos |