Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: chrome/browser/chromeos/arc/arc_support_host.h

Issue 2475073003: Refactor ArcSupportHost and ArcAuthService part 1. (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
17 namespace arc {
18 class ArcOptInPreferenceHandler;
19 }
20
21 // Native interface to control ARC support chrome App. 15 // Native interface to control ARC support chrome App.
22 // TODO(hidehiko): Move more implementation for the UI control from 16 // TODO(hidehiko): Move more implementation for the UI control from
23 // ArcAuthService to this class and remove 17 // ArcAuthService to this class.
24 // arc::ArcOptInPreferenceHandlerObserver inheritance.
25 // TODO(hidehiko,lhchavez): Move this into extensions/ directory, and put it 18 // TODO(hidehiko,lhchavez): Move this into extensions/ directory, and put it
26 // into "arc" namespace. Add unittests at the time. 19 // into "arc" namespace. Add unittests at the time.
27 class ArcSupportHost : public arc::ArcSupportMessageHost::Observer, 20 class ArcSupportHost : public arc::ArcSupportMessageHost::Observer,
28 public arc::ArcOptInPreferenceHandlerObserver,
29 public display::DisplayObserver { 21 public display::DisplayObserver {
30 public: 22 public:
23 enum class UIPage {
24 NO_PAGE, // Hide everything.
25 TERMS, // Terms content page.
26 LSO_PROGRESS, // LSO loading progress page.
27 LSO, // LSO page to enter user's credentials.
28 START_PROGRESS, // Arc starting progress page.
29 ERROR, // Arc start error page.
30 ERROR_WITH_FEEDBACK, // Arc start error page, plus feedback button.
31 };
32
33 // Observer to notify UI event.
34 class Observer {
35 public:
36 virtual ~Observer() = default;
37
38 // Called when the ARC support window is closed.
39 virtual void OnWindowClosed() = 0;
40
41 // Called when the user press AGREE button on ToS page.
42 // TODO(hidehiko): Currently, due to implementation reason,
43 // this is also called when RETRY on error page is clicked. Fix this.
44 virtual void OnTermsAgreed(bool is_metrics_enabled,
45 bool is_backup_and_restore_enabled,
46 bool is_location_service_enabled) = 0;
47
48 // Called when LSO auth token fetch is successfully completed.
49 virtual void OnAuthSucceeded(const std::string& auth_code) = 0;
50
51 // Called when send feedback button on error page is clicked.
52 virtual void OnSendFeedbackClicked() = 0;
53 };
54
31 static const char kHostAppId[]; 55 static const char kHostAppId[];
32 static const char kStorageId[]; 56 static const char kStorageId[];
33 57
34 ArcSupportHost(); 58 ArcSupportHost();
35 ~ArcSupportHost() override; 59 ~ArcSupportHost() override;
36 60
61 // Currently only one observer can be added.
62 // TODO(hidehiko): Support RemoveObserver. Support multiple observer.
63 void AddObserver(Observer* observer);
64
37 // Called when the communication to arc_support Chrome App is ready. 65 // Called when the communication to arc_support Chrome App is ready.
38 void SetMessageHost(arc::ArcSupportMessageHost* message_host); 66 void SetMessageHost(arc::ArcSupportMessageHost* message_host);
39 67
40 // Called when the communication to arc_support Chrome App is closed. 68 // 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| 69 // The argument message_host is used to check if the given |message_host|
42 // is what this instance uses know, to avoid racy case. 70 // is what this instance uses know, to avoid racy case.
43 // If |message_host| is different from the one this instance knows, 71 // If |message_host| is different from the one this instance knows,
44 // this is no op. 72 // this is no op.
45 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host); 73 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host);
46 74
47 // Requests to close the extension window. 75 // Requests to close the extension window.
48 void Close(); 76 void Close();
49 void ShowPage(arc::ArcAuthService::UIPage page, const base::string16& status); 77 void ShowPage(UIPage page, const base::string16& status);
78
79 void SetMetricsPreferenceCheckbox(bool is_enabled, bool is_managed);
80 void SetBackupAndRestorePreferenceCheckbox(bool is_enabled, bool is_managed);
81 void SetLocationServicesPreferenceCheckbox(bool is_enabled, bool is_managed);
50 82
51 // arc::ArcSupportMessageHost::Observer override: 83 // arc::ArcSupportMessageHost::Observer override:
52 void OnMessage(const base::DictionaryValue& message) override; 84 void OnMessage(const base::DictionaryValue& message) override;
53 85
54 // display::DisplayObserver: 86 // display::DisplayObserver:
55 void OnDisplayAdded(const display::Display& new_display) override; 87 void OnDisplayAdded(const display::Display& new_display) override;
56 void OnDisplayRemoved(const display::Display& old_display) override; 88 void OnDisplayRemoved(const display::Display& old_display) override;
57 void OnDisplayMetricsChanged(const display::Display& display, 89 void OnDisplayMetricsChanged(const display::Display& display,
58 uint32_t changed_metrics) override; 90 uint32_t changed_metrics) override;
59 91
60 // arc::ArcOptInPreferenceHandlerObserver: 92 private:
61 void OnMetricsModeChanged(bool enabled, bool managed) override; 93 struct PreferenceCheckboxData {
62 void OnBackupAndRestoreModeChanged(bool enabled, bool managed) override; 94 PreferenceCheckboxData() : PreferenceCheckboxData(false, false) {}
63 void OnLocationServicesModeChanged(bool enabled, bool managed) override; 95 PreferenceCheckboxData(bool is_enabled, bool is_managed)
96 : is_enabled(is_enabled), is_managed(is_managed) {}
64 97
65 private: 98 bool is_enabled;
99 bool is_managed;
100 };
101
66 bool Initialize(); 102 bool Initialize();
67 103
68 // Sends a preference update to the extension. 104 // Sends a preference update to the extension.
69 // The message will be 105 // The message will be
70 // { 106 // {
71 // 'action': action_name, 107 // 'action': action_name,
72 // 'enabled': is_enabled, 108 // 'enabled': is_enabled,
73 // 'managed': is_managed 109 // 'managed': is_managed
74 // } 110 // }
75 void SendPreferenceUpdate(const std::string& action_name, 111 void SendPreferenceCheckboxUpdate(const std::string& action_name,
76 bool is_enabled, 112 const PreferenceCheckboxData& data);
77 bool is_managed);
78 113
79 void DisconnectMessageHost(); 114 void DisconnectMessageHost();
80 115
116 // Currently Observer is only ArcAuthService, so it is unique.
117 // Use ObserverList when more classes start to observe it.
118 Observer* observer_ = nullptr;
119
120 PreferenceCheckboxData metrics_checkbox_;
121 PreferenceCheckboxData backup_and_restore_checkbox_;
122 PreferenceCheckboxData location_services_checkbox_;
123
81 // The instance is created and managed by Chrome. 124 // The instance is created and managed by Chrome.
82 arc::ArcSupportMessageHost* message_host_ = nullptr; 125 arc::ArcSupportMessageHost* message_host_ = nullptr;
83 126
84 // Handles preferences and metrics mode.
85 std::unique_ptr<arc::ArcOptInPreferenceHandler> preference_handler_;
86
87 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); 127 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost);
88 }; 128 };
89 129
90 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ 130 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.cc ('k') | chrome/browser/chromeos/arc/arc_support_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698