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

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

Issue 2436903003: Extract ArcSupportMessageHost. (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 "base/macros.h" 8 #include "base/macros.h"
9 #include "chrome/browser/chromeos/arc/arc_auth_service.h" 9 #include "chrome/browser/chromeos/arc/arc_auth_service.h"
10 #include "chrome/browser/chromeos/arc/extensions/arc_support_message_host.h"
10 #include "components/prefs/pref_change_registrar.h" 11 #include "components/prefs/pref_change_registrar.h"
11 #include "extensions/browser/api/messaging/native_message_host.h" 12 #include "extensions/browser/api/messaging/native_message_host.h"
12 #include "ui/display/display_observer.h" 13 #include "ui/display/display_observer.h"
13 14
14 // Supports communication with Arc support dialog. 15 // Native interface to control ARC support chrome App.
15 class ArcSupportHost : public extensions::NativeMessageHost, 16 // TODO(hidehiko): Move more implementation for the UI control from
16 public arc::ArcAuthService::Observer, 17 // ArcAuthService to this class.
18 // TODO(hidehiko,lhchavez,khmel): Extract preference observing into a
19 // standalone class so that it can be shared with OOBE flow.
20 // TODO(hidehiko,lhchavez): Move this into extensions/ directory, and put it
21 // into "arc" namespace. Add unittests at the time.
22 class ArcSupportHost : public arc::ArcSupportMessageHost::Observer,
17 public display::DisplayObserver { 23 public display::DisplayObserver {
18 public: 24 public:
19 static const char kHostName[];
20 static const char kHostAppId[]; 25 static const char kHostAppId[];
21 static const char kStorageId[]; 26 static const char kStorageId[];
22 static const char* const kHostOrigin[];
23 27
24 static std::unique_ptr<NativeMessageHost> Create(); 28 ArcSupportHost();
29 ~ArcSupportHost() override;
25 30
26 ~ArcSupportHost() override; 31 // Called when the communication to arc_support Chrome App is ready.
32 void SetMessageHost(arc::ArcSupportMessageHost* message_host);
33
34 // Called when the communication to arc_support Chrome App is closed.
35 // The argument message_host is used to check if the given |message_host|
36 // is what this instance uses know, to avoid racy case.
37 // If |message_host| is different from the one this instance knows,
38 // this is no op.
39 void UnsetMessageHost(arc::ArcSupportMessageHost* message_host);
27 40
28 // Requests to close the extension window. 41 // Requests to close the extension window.
29 void Close(); 42 void Close();
43 void ShowPage(arc::ArcAuthService::UIPage page, const base::string16& status);
30 44
31 // Overrides NativeMessageHost: 45 // arc::ArcSupportMessageHost::Observer override:
32 void Start(Client* client) override; 46 void OnMessage(const base::DictionaryValue& message) override;
33 void OnMessage(const std::string& request_string) override;
34 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const override;
35
36 // Overrides arc::ArcAuthService::Observer:
37 // TODO(hidehiko): Get rid of Observer interface.
38 void OnOptInUIClose() override;
39 void OnOptInUIShowPage(arc::ArcAuthService::UIPage page,
40 const base::string16& status) override;
41 47
42 // display::DisplayObserver: 48 // display::DisplayObserver:
43 void OnDisplayAdded(const display::Display& new_display) override; 49 void OnDisplayAdded(const display::Display& new_display) override;
44 void OnDisplayRemoved(const display::Display& old_display) override; 50 void OnDisplayRemoved(const display::Display& old_display) override;
45 void OnDisplayMetricsChanged(const display::Display& display, 51 void OnDisplayMetricsChanged(const display::Display& display,
46 uint32_t changed_metrics) override; 52 uint32_t changed_metrics) override;
47 53
48 private: 54 private:
49 ArcSupportHost();
50
51 bool Initialize(); 55 bool Initialize();
52 void OnMetricsPreferenceChanged(); 56 void OnMetricsPreferenceChanged();
53 void OnBackupAndRestorePreferenceChanged(); 57 void OnBackupAndRestorePreferenceChanged();
54 void OnLocationServicePreferenceChanged(); 58 void OnLocationServicePreferenceChanged();
55 59
56 // Utilities on preference update. 60 // Utilities on preference update.
57 void SendMetricsMode(); 61 void SendMetricsMode();
58 void SendBackupAndRestoreMode(); 62 void SendBackupAndRestoreMode();
59 void SendLocationServicesMode(); 63 void SendLocationServicesMode();
60 void SendOptionMode(const std::string& action_name, 64 void SendOptionMode(const std::string& action_name,
61 const std::string& pref_name); 65 const std::string& pref_name);
62 66
63 // Sends a preference update to the extension. 67 // Sends a preference update to the extension.
64 // The message will be 68 // The message will be
65 // { 69 // {
66 // 'action': action_name, 70 // 'action': action_name,
67 // 'enabled': is_enabled, 71 // 'enabled': is_enabled,
68 // 'managed': is_managed 72 // 'managed': is_managed
69 // } 73 // }
70 void SendPreferenceUpdate(const std::string& action_name, 74 void SendPreferenceUpdate(const std::string& action_name,
71 bool is_enabled, 75 bool is_enabled,
72 bool is_managed); 76 bool is_managed);
73 77
74 void EnableMetrics(bool is_enabled); 78 void EnableMetrics(bool is_enabled);
75 void EnableBackupRestore(bool is_enabled); 79 void EnableBackupRestore(bool is_enabled);
76 void EnableLocationService(bool is_enabled); 80 void EnableLocationService(bool is_enabled);
77 81
78 // Unowned pointer. 82 void DisconnectMessageHost();
79 Client* client_ = nullptr;
80 83
81 // Keep if Close() is requested from the browser. 84 // The instance is created and managed by Chrome.
82 // TODO(hidehiko): Remove this. This is temporarily introduced for checking 85 arc::ArcSupportMessageHost* message_host_ = nullptr;
83 // if ArcAuthService::CancelAuthCode() needs to be invoked or not.
84 // ArcAuthService should know its own state and the transition so moving to
85 // there should simplify the structure. However, it is blocked by the current
86 // dependency. For the clean up, more refactoring is needed, which can be
87 // bigger changes.
88 bool close_requested_ = false;
89 86
90 // Used to track metrics preference. 87 // Used to track metrics preference.
91 PrefChangeRegistrar pref_local_change_registrar_; 88 PrefChangeRegistrar pref_local_change_registrar_;
92 // Used to track backup&restore and location service preference. 89 // Used to track backup&restore and location service preference.
93 PrefChangeRegistrar pref_change_registrar_; 90 PrefChangeRegistrar pref_change_registrar_;
94 91
95 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost); 92 DISALLOW_COPY_AND_ASSIGN(ArcSupportHost);
96 }; 93 };
97 94
98 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_ 95 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SUPPORT_HOST_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service_unittest.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