| 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 #include <string> |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/observer_list.h" |
| 11 #include "chrome/browser/chromeos/arc/extensions/arc_support_message_host.h" | 13 #include "chrome/browser/chromeos/arc/extensions/arc_support_message_host.h" |
| 12 #include "extensions/browser/api/messaging/native_message_host.h" | 14 #include "extensions/browser/api/messaging/native_message_host.h" |
| 13 #include "ui/display/display_observer.h" | 15 #include "ui/display/display_observer.h" |
| 14 | 16 |
| 15 class Profile; | 17 class Profile; |
| 16 | 18 |
| 17 // Native interface to control ARC support chrome App. | 19 // Native interface to control ARC support chrome App. |
| 18 // TODO(hidehiko,lhchavez): Move this into extensions/ directory, and put it | 20 // TODO(hidehiko,lhchavez): Move this into extensions/ directory, and put it |
| 19 // into "arc" namespace. Add unittests at the time. | 21 // into "arc" namespace. Add unittests at the time. |
| 20 class ArcSupportHost : public arc::ArcSupportMessageHost::Observer, | 22 class ArcSupportHost : public arc::ArcSupportMessageHost::Observer, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 SERVER_COMMUNICATION_ERROR, | 41 SERVER_COMMUNICATION_ERROR, |
| 40 ANDROID_MANAGEMENT_REQUIRED_ERROR, | 42 ANDROID_MANAGEMENT_REQUIRED_ERROR, |
| 41 }; | 43 }; |
| 42 | 44 |
| 43 // Observer to notify UI event. | 45 // Observer to notify UI event. |
| 44 class Observer { | 46 class Observer { |
| 45 public: | 47 public: |
| 46 virtual ~Observer() = default; | 48 virtual ~Observer() = default; |
| 47 | 49 |
| 48 // Called when the ARC support window is closed. | 50 // Called when the ARC support window is closed. |
| 49 virtual void OnWindowClosed() = 0; | 51 virtual void OnWindowClosed() {} |
| 50 | 52 |
| 51 // Called when the user press AGREE button on ToS page. | 53 // Called when the user press AGREE button on ToS page. |
| 52 // TODO(hidehiko): Currently, due to implementation reason, | 54 // TODO(hidehiko): Currently, due to implementation reason, |
| 53 // this is also called when RETRY on error page is clicked. Fix this. | 55 // this is also called when RETRY on error page is clicked. Fix this. |
| 54 virtual void OnTermsAgreed(bool is_metrics_enabled, | 56 virtual void OnTermsAgreed(bool is_metrics_enabled, |
| 55 bool is_backup_and_restore_enabled, | 57 bool is_backup_and_restore_enabled, |
| 56 bool is_location_service_enabled) = 0; | 58 bool is_location_service_enabled) {} |
| 57 | 59 |
| 58 // Called when LSO auth token fetch is successfully completed. | 60 // Called when LSO auth token fetch is successfully completed. |
| 59 virtual void OnAuthSucceeded(const std::string& auth_code) = 0; | 61 virtual void OnAuthSucceeded(const std::string& auth_code) {} |
| 60 | 62 |
| 61 // Called when "RETRY" button on the error page is clicked. | 63 // Called when "RETRY" button on the error page is clicked. |
| 62 virtual void OnRetryClicked() = 0; | 64 virtual void OnRetryClicked() {} |
| 63 | 65 |
| 64 // Called when send feedback button on error page is clicked. | 66 // Called when send feedback button on error page is clicked. |
| 65 virtual void OnSendFeedbackClicked() = 0; | 67 virtual void OnSendFeedbackClicked() {} |
| 66 }; | 68 }; |
| 67 | 69 |
| 68 static const char kHostAppId[]; | 70 static const char kHostAppId[]; |
| 69 static const char kStorageId[]; | 71 static const char kStorageId[]; |
| 70 | 72 |
| 71 explicit ArcSupportHost(Profile* profile); | 73 explicit ArcSupportHost(Profile* profile); |
| 72 ~ArcSupportHost() override; | 74 ~ArcSupportHost() override; |
| 73 | 75 |
| 74 // Currently only one observer can be added. | |
| 75 // TODO(hidehiko): Support RemoveObserver. Support multiple observer. | |
| 76 void AddObserver(Observer* observer); | 76 void AddObserver(Observer* observer); |
| 77 void RemoveObserver(Observer* observer); |
| 78 bool HasObserver(Observer* observer); |
| 77 | 79 |
| 78 // Called when the communication to arc_support Chrome App is ready. | 80 // Called when the communication to arc_support Chrome App is ready. |
| 79 void SetMessageHost(arc::ArcSupportMessageHost* message_host); | 81 void SetMessageHost(arc::ArcSupportMessageHost* message_host); |
| 80 | 82 |
| 81 // Called when the communication to arc_support Chrome App is closed. | 83 // Called when the communication to arc_support Chrome App is closed. |
| 82 // The argument message_host is used to check if the given |message_host| | 84 // The argument message_host is used to check if the given |message_host| |
| 83 // is what this instance uses know, to avoid racy case. | 85 // is what this instance uses know, to avoid racy case. |
| 84 // If |message_host| is different from the one this instance knows, | 86 // If |message_host| is different from the one this instance knows, |
| 85 // this is no op. | 87 // this is no op. |
| 86 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host); | 88 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // 'enabled': is_enabled, | 149 // 'enabled': is_enabled, |
| 148 // 'managed': is_managed | 150 // 'managed': is_managed |
| 149 // } | 151 // } |
| 150 void SendPreferenceCheckboxUpdate(const std::string& action_name, | 152 void SendPreferenceCheckboxUpdate(const std::string& action_name, |
| 151 const PreferenceCheckboxData& data); | 153 const PreferenceCheckboxData& data); |
| 152 | 154 |
| 153 void DisconnectMessageHost(); | 155 void DisconnectMessageHost(); |
| 154 | 156 |
| 155 Profile* const profile_; | 157 Profile* const profile_; |
| 156 | 158 |
| 157 // Currently Observer is only ArcAuthService, so it is unique. | 159 base::ObserverList<Observer> observer_list_; |
| 158 // Use ObserverList when more classes start to observe it. | |
| 159 Observer* observer_ = nullptr; | |
| 160 | 160 |
| 161 // True, if ARC support app is requested to start, but the connection is not | 161 // True, if ARC support app is requested to start, but the connection is not |
| 162 // yet established. Reset to false, when the app is started and the | 162 // yet established. Reset to false, when the app is started and the |
| 163 // connection to the app is established. | 163 // connection to the app is established. |
| 164 bool app_start_pending_ = false; | 164 bool app_start_pending_ = false; |
| 165 | 165 |
| 166 // The instance is created and managed by Chrome. | 166 // The instance is created and managed by Chrome. |
| 167 arc::ArcSupportMessageHost* message_host_ = nullptr; | 167 arc::ArcSupportMessageHost* message_host_ = nullptr; |
| 168 | 168 |
| 169 // The lifetime of the message_host_ is out of control from ARC. | 169 // The lifetime of the message_host_ is out of control from ARC. |
| 170 // Fields below are UI parameter cache in case the value is set before | 170 // Fields below are UI parameter cache in case the value is set before |
| 171 // connection to the ARC support Chrome app is established. | 171 // connection to the ARC support Chrome app is established. |
| 172 UIPage ui_page_ = UIPage::NO_PAGE; | 172 UIPage ui_page_ = UIPage::NO_PAGE; |
| 173 | 173 |
| 174 // These have valid values iff ui_page_ == ERROR. | 174 // These have valid values iff ui_page_ == ERROR. |
| 175 Error error_; | 175 Error error_; |
| 176 bool should_show_send_feedback_; | 176 bool should_show_send_feedback_; |
| 177 | 177 |
| 178 bool is_arc_managed_ = false; | 178 bool is_arc_managed_ = false; |
| 179 | 179 |
| 180 PreferenceCheckboxData metrics_checkbox_; | 180 PreferenceCheckboxData metrics_checkbox_; |
| 181 PreferenceCheckboxData backup_and_restore_checkbox_; | 181 PreferenceCheckboxData backup_and_restore_checkbox_; |
| 182 PreferenceCheckboxData location_services_checkbox_; | 182 PreferenceCheckboxData location_services_checkbox_; |
| 183 | 183 |
| 184 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); | 184 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ | 187 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ |
| OLD | NEW |