| 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 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ | 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | |
| 12 #include "chrome/browser/chromeos/arc/extensions/arc_support_message_host.h" | 11 #include "chrome/browser/chromeos/arc/extensions/arc_support_message_host.h" |
| 13 #include "chrome/browser/chromeos/arc/optin/arc_optin_preference_handler_observe
r.h" | |
| 14 #include "extensions/browser/api/messaging/native_message_host.h" | 12 #include "extensions/browser/api/messaging/native_message_host.h" |
| 15 #include "ui/display/display_observer.h" | 13 #include "ui/display/display_observer.h" |
| 16 | 14 |
| 15 class Profile; |
| 16 |
| 17 namespace arc { | 17 namespace arc { |
| 18 class ArcOptInPreferenceHandler; | 18 class ArcOptInPreferenceHandler; |
| 19 } | 19 } |
| 20 | 20 |
| 21 // Native interface to control ARC support chrome App. | 21 // Native interface to control ARC support chrome App. |
| 22 // TODO(hidehiko): Move more implementation for the UI control from | 22 // TODO(hidehiko): Move more implementation for the UI control from |
| 23 // ArcAuthService to this class and remove | 23 // ArcAuthService to this class and remove |
| 24 // arc::ArcOptInPreferenceHandlerObserver inheritance. | 24 // arc::ArcOptInPreferenceHandlerObserver inheritance. |
| 25 // TODO(hidehiko,lhchavez): Move this into extensions/ directory, and put it | 25 // TODO(hidehiko,lhchavez): Move this into extensions/ directory, and put it |
| 26 // into "arc" namespace. Add unittests at the time. | 26 // into "arc" namespace. Add unittests at the time. |
| 27 class ArcSupportHost : public arc::ArcSupportMessageHost::Observer, | 27 class ArcSupportHost : public arc::ArcSupportMessageHost::Observer, |
| 28 public arc::ArcOptInPreferenceHandlerObserver, | |
| 29 public display::DisplayObserver { | 28 public display::DisplayObserver { |
| 30 public: | 29 public: |
| 30 enum class UIPage { |
| 31 NO_PAGE, // Hide evertying. |
| 32 TERMS, // Terms of Service page. |
| 33 LSO, // LSO page. |
| 34 LOADING, // ARC loading page. |
| 35 ERROR, // Error message page. |
| 36 }; |
| 37 |
| 38 enum class ErrorType { |
| 39 SIGN_IN_NETWORK_ERROR, |
| 40 SIGN_IN_SERVICE_UNAVAILABLE_ERROR, |
| 41 SIGN_IN_BAD_AUTHENTICATION_ERROR, |
| 42 SIGN_IN_GMS_NOT_AVAILABLE_ERROR, |
| 43 SIGN_IN_CLOUD_PROVISION_FLOW_FAIL_ERROR, |
| 44 SIGN_IN_UNKNOWN_ERROR, |
| 45 SERVER_COMMUNICATION_ERROR, |
| 46 ANDROID_MANAGEMENT_REQUIRED_ERROR, |
| 47 }; |
| 48 |
| 49 // TODO |
| 50 class Observer { |
| 51 public: |
| 52 virtual ~Observer() = default; |
| 53 |
| 54 virtual void OnWindowClosed() = 0; |
| 55 virtual void OnTermsAgreed(bool is_metrics_enabled, |
| 56 bool is_backup_and_restore_enabled, |
| 57 bool is_location_service_enabled) = 0; |
| 58 virtual void OnAuthSucceeded(const std::string& auth_code) = 0; |
| 59 virtual void OnSendFeedbackClicked() = 0; |
| 60 }; |
| 61 |
| 31 static const char kHostAppId[]; | 62 static const char kHostAppId[]; |
| 32 static const char kStorageId[]; | 63 static const char kStorageId[]; |
| 33 | 64 |
| 34 ArcSupportHost(); | 65 explicit ArcSupportHost(Profile* profile); |
| 35 ~ArcSupportHost() override; | 66 ~ArcSupportHost() override; |
| 36 | 67 |
| 68 void set_observer(Observer* observer) { observer_ = observer; } |
| 69 |
| 37 // Called when the communication to arc_support Chrome App is ready. | 70 // Called when the communication to arc_support Chrome App is ready. |
| 38 void SetMessageHost(arc::ArcSupportMessageHost* message_host); | 71 void SetMessageHost(arc::ArcSupportMessageHost* message_host); |
| 39 | 72 |
| 40 // Called when the communication to arc_support Chrome App is closed. | 73 // Called when the communication to arc_support Chrome App is closed. |
| 41 // The argument message_host is used to check if the given |message_host| | 74 // The argument message_host is used to check if the given |message_host| |
| 42 // is what this instance uses know, to avoid racy case. | 75 // is what this instance uses know, to avoid racy case. |
| 43 // If |message_host| is different from the one this instance knows, | 76 // If |message_host| is different from the one this instance knows, |
| 44 // this is no op. | 77 // this is no op. |
| 45 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host); | 78 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host); |
| 46 | 79 |
| 47 // Requests to close the extension window. | 80 // Requests to close the extension window. |
| 48 void Close(); | 81 void Close(); |
| 49 void ShowPage(arc::ArcAuthService::UIPage page, const base::string16& status); | 82 |
| 83 // Requests to show the Terms Of Service page. |
| 84 void ShowTermsOfServicePage(); |
| 85 |
| 86 // Requests to show LSO sign in page. |
| 87 void ShowLsoPage(); |
| 88 |
| 89 // Requests to show ARC loading page. |
| 90 void ShowLoadingPage(); |
| 91 |
| 92 // Requests to show an error page. |
| 93 void ShowErrorPage(ErrorType error_type, bool show_feedback_button); |
| 94 |
| 95 // Set preference related checkboxes. |
| 96 void SetMetricsCheckbox(bool is_enabled, bool is_managed); |
| 97 void SetBackupAndRestoreCheckbox(bool is_enabled, bool is_managed); |
| 98 void SetLocationServiceCheckbox(bool is_enabled, bool is_managed); |
| 99 |
| 100 // Temporarily expose currently requested UIPage. |
| 101 // Note this may represent different page from the actually shown one, |
| 102 // because the ARC support app may change its page by itself, and this is |
| 103 // out-of-sync in the case. |
| 104 // TODO(hidehiko): Remove this. |
| 105 UIPage ui_page() const { return ui_page_; } |
| 106 |
| 107 // Returns whether send_feedback_button should be shown. Can be called only |
| 108 // when ui_page() returns UIPage::ERROR. |
| 109 // TODO(hidehiko): Remove this. |
| 110 bool error_page_has_send_feedback_button() const { |
| 111 return show_feedback_button_; |
| 112 } |
| 50 | 113 |
| 51 // arc::ArcSupportMessageHost::Observer override: | 114 // arc::ArcSupportMessageHost::Observer override: |
| 52 void OnMessage(const base::DictionaryValue& message) override; | 115 void OnMessage(const base::DictionaryValue& message) override; |
| 53 | 116 |
| 54 // display::DisplayObserver: | 117 // display::DisplayObserver: |
| 55 void OnDisplayAdded(const display::Display& new_display) override; | 118 void OnDisplayAdded(const display::Display& new_display) override; |
| 56 void OnDisplayRemoved(const display::Display& old_display) override; | 119 void OnDisplayRemoved(const display::Display& old_display) override; |
| 57 void OnDisplayMetricsChanged(const display::Display& display, | 120 void OnDisplayMetricsChanged(const display::Display& display, |
| 58 uint32_t changed_metrics) override; | 121 uint32_t changed_metrics) override; |
| 122 private: |
| 123 // TODO |
| 124 struct PreferenceCheckboxData { |
| 125 PreferenceCheckboxData() : PreferenceCheckboxData(false, false) {} |
| 126 PreferenceCheckboxData(bool is_enabled, bool is_managed) |
| 127 : is_enabled(is_enabled), is_managed(is_managed) {} |
| 59 | 128 |
| 60 // arc::ArcOptInPreferenceHandlerObserver: | 129 bool is_enabled = false; |
| 61 void OnMetricsModeChanged(bool enabled, bool managed) override; | 130 bool is_managed = false; |
| 62 void OnBackupAndRestoreModeChanged(bool enabled, bool managed) override; | 131 }; |
| 63 void OnLocationServicesModeChanged(bool enabled, bool managed) override; | |
| 64 | 132 |
| 65 private: | 133 // TODO. |
| 134 void RequestWindowOpen(); |
| 135 |
| 66 bool Initialize(); | 136 bool Initialize(); |
| 67 | 137 |
| 138 void ShowPageInternal(UIPage ui_page); |
| 139 |
| 68 // Sends a preference update to the extension. | 140 // Sends a preference update to the extension. |
| 69 // The message will be | 141 // The message will be |
| 70 // { | 142 // { |
| 71 // 'action': action_name, | 143 // 'action': action_name, |
| 72 // 'enabled': is_enabled, | 144 // 'enabled': is_enabled, |
| 73 // 'managed': is_managed | 145 // 'managed': is_managed |
| 74 // } | 146 // } |
| 75 void SendPreferenceUpdate(const std::string& action_name, | 147 void SendPreferenceCheckboxUpdate(const std::string& action_name, |
| 76 bool is_enabled, | 148 const PreferenceCheckboxData& data); |
| 77 bool is_managed); | |
| 78 | 149 |
| 79 void DisconnectMessageHost(); | 150 void DisconnectMessageHost(); |
| 80 | 151 |
| 152 Profile* profile_; |
| 153 |
| 154 // At the moment, we only have one observer, but will be multiple. |
| 155 // TODO(hidehiko): Use ObserverList then. |
| 156 Observer* observer_ = nullptr; |
| 157 |
| 158 // TODO |
| 159 bool window_open_requested_ = false; |
| 160 |
| 81 // The instance is created and managed by Chrome. | 161 // The instance is created and managed by Chrome. |
| 82 arc::ArcSupportMessageHost* message_host_ = nullptr; | 162 arc::ArcSupportMessageHost* message_host_ = nullptr; |
| 83 | 163 |
| 84 // Handles preferences and metrics mode. | 164 // The lifetime of the message_host_ is out of control from ARC, |
| 85 std::unique_ptr<arc::ArcOptInPreferenceHandler> preference_handler_; | 165 // unfortunately. Cache the latest requested page info here, and send them |
| 166 // in Initialize() to encapsulate synchronization. |
| 167 UIPage ui_page_ = UIPage::NO_PAGE; |
| 168 ErrorType error_type_; |
| 169 bool show_feedback_button_; |
| 170 |
| 171 // Similar to page info above, cache the preference checkbox data. |
| 172 PreferenceCheckboxData metrics_checkbox_; |
| 173 PreferenceCheckboxData backup_and_restore_checkbox_; |
| 174 PreferenceCheckboxData location_service_checkbox_; |
| 86 | 175 |
| 87 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); | 176 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); |
| 88 }; | 177 }; |
| 89 | 178 |
| 90 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ | 179 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ |
| OLD | NEW |