Index: chrome/browser/chromeos/lock_screen_apps/state_controller.cc |
diff --git a/chrome/browser/chromeos/lock_screen_apps/state_controller.cc b/chrome/browser/chromeos/lock_screen_apps/state_controller.cc |
index 4e08767e45bb13bef68c1a6d0074ba9995fbba8b..58c4f06ff59c494327d7ca95ec43efe5ba4140b5 100644 |
--- a/chrome/browser/chromeos/lock_screen_apps/state_controller.cc |
+++ b/chrome/browser/chromeos/lock_screen_apps/state_controller.cc |
@@ -16,6 +16,9 @@ |
#include "chromeos/chromeos_switches.h" |
#include "components/session_manager/core/session_manager.h" |
#include "content/public/common/service_manager_connection.h" |
+#include "extensions/browser/app_window/app_window.h" |
+#include "extensions/browser/app_window/native_app_window.h" |
+#include "extensions/common/extension.h" |
#include "services/service_manager/public/cpp/connector.h" |
using ash::mojom::TrayActionState; |
@@ -40,7 +43,8 @@ StateController* StateController::Get() { |
return g_instance; |
} |
-StateController::StateController() : binding_(this), session_observer_(this) { |
+StateController::StateController() |
+ : binding_(this), app_window_observer_(this), session_observer_(this) { |
DCHECK(!g_instance); |
DCHECK(IsEnabled()); |
@@ -119,7 +123,7 @@ void StateController::RequestNewLockScreenNote() { |
void StateController::OnSessionStateChanged() { |
if (!session_manager::SessionManager::Get()->IsScreenLocked()) { |
app_manager_->Stop(); |
- UpdateLockScreenNoteState(TrayActionState::kNotAvailable); |
+ ResetNoteTakingWindowAndMoveToNextState(true); |
benwells
2017/06/13 10:30:46
Nit: true /* close_window */
tbarzic
2017/06/13 19:17:59
Done.
|
return; |
} |
@@ -132,9 +136,47 @@ void StateController::OnSessionStateChanged() { |
OnNoteTakingAvailabilityChanged(); |
} |
+void StateController::OnAppWindowRemoved(extensions::AppWindow* app_window) { |
+ if (note_app_window_ != app_window) |
+ return; |
+ ResetNoteTakingWindowAndMoveToNextState(false); |
benwells
2017/06/13 10:30:46
Nit: false /* close_window */
tbarzic
2017/06/13 19:17:59
Done.
|
+} |
+ |
+bool StateController::CanCreateAppWindowForAction( |
benwells
2017/06/13 10:30:46
This function name is kind of confusing. It is che
tbarzic
2017/06/13 19:17:59
So, the main purpose of this method is for ChromeA
|
+ content::BrowserContext* context, |
+ const extensions::Extension* extension, |
+ extensions::api::app_runtime::ActionType action) const { |
+ if (action != extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE) |
+ return false; |
+ |
+ if (GetLockScreenNoteState() != TrayActionState::kLaunching) |
+ return false; |
+ |
+ if (!chromeos::ProfileHelper::GetSigninProfile()->IsSameProfile( |
+ Profile::FromBrowserContext(context))) { |
+ return false; |
+ } |
+ |
+ return extension && app_manager_->GetNoteTakingAppId() == extension->id(); |
+} |
+ |
+bool StateController::RegisterAppWindowForAction( |
+ extensions::AppWindow* window, |
+ extensions::api::app_runtime::ActionType action) { |
benwells
2017/06/13 10:30:46
Is ACTION_TYPE_NEW_NOTE the only type of action th
tbarzic
2017/06/13 19:17:59
Currently, yes (as NEW_NOTE is the only action tha
|
+ if (!CanCreateAppWindowForAction(window->browser_context(), |
+ window->GetExtension(), action)) { |
+ return false; |
+ } |
+ |
+ note_app_window_ = window; |
+ app_window_observer_.Add(extensions::AppWindowRegistry::Get( |
+ chromeos::ProfileHelper::GetSigninProfile())); |
+ UpdateLockScreenNoteState(TrayActionState::kActive); |
+ return true; |
+} |
+ |
void StateController::MoveToBackground() { |
- TrayActionState state = GetLockScreenNoteState(); |
- if (state != TrayActionState::kActive && state != TrayActionState::kLaunching) |
+ if (GetLockScreenNoteState() != TrayActionState::kActive) |
return; |
UpdateLockScreenNoteState(TrayActionState::kBackground); |
} |
@@ -145,14 +187,11 @@ void StateController::MoveToForeground() { |
UpdateLockScreenNoteState(TrayActionState::kActive); |
} |
-void StateController::SetLockScreenNoteStateForTesting( |
- ash::mojom::TrayActionState state) { |
- lock_screen_note_state_ = state; |
-} |
- |
void StateController::OnNoteTakingAvailabilityChanged() { |
- if (!app_manager_->IsNoteTakingAppAvailable()) { |
- UpdateLockScreenNoteState(TrayActionState::kNotAvailable); |
+ if (!app_manager_->IsNoteTakingAppAvailable() || |
+ (note_app_window_ && note_app_window_->GetExtension()->id() != |
+ app_manager_->GetNoteTakingAppId())) { |
+ ResetNoteTakingWindowAndMoveToNextState(true); |
return; |
} |
@@ -160,6 +199,21 @@ void StateController::OnNoteTakingAvailabilityChanged() { |
UpdateLockScreenNoteState(TrayActionState::kAvailable); |
} |
+void StateController::ResetNoteTakingWindowAndMoveToNextState( |
+ bool close_window) { |
+ app_window_observer_.RemoveAll(); |
+ |
+ if (note_app_window_) { |
+ if (close_window && note_app_window_->GetBaseWindow()) |
+ note_app_window_->GetBaseWindow()->Close(); |
+ note_app_window_ = nullptr; |
+ } |
+ |
+ UpdateLockScreenNoteState(app_manager_->IsNoteTakingAppAvailable() |
+ ? TrayActionState::kAvailable |
+ : TrayActionState::kNotAvailable); |
+} |
+ |
bool StateController::UpdateLockScreenNoteState(TrayActionState state) { |
const TrayActionState old_state = GetLockScreenNoteState(); |
if (old_state == state) |