| 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_UI_WEBUI_SETTINGS_PROFILE_INFO_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_PROFILE_INFO_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_SETTINGS_PROFILE_INFO_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SETTINGS_PROFILE_INFO_HANDLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/scoped_observer.h" | 11 #include "base/scoped_observer.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/profiles/profile_attributes_storage.h" | 13 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 14 #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" | 14 #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" |
| 15 #include "components/prefs/pref_change_registrar.h" |
| 15 | 16 |
| 16 #if defined(OS_CHROMEOS) | 17 #if defined(OS_CHROMEOS) |
| 17 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 19 #endif | 20 #endif |
| 20 | 21 |
| 21 class Profile; | 22 class Profile; |
| 22 | 23 |
| 23 namespace settings { | 24 namespace settings { |
| 24 | 25 |
| 25 class ProfileInfoHandler : public SettingsPageUIHandler, | 26 class ProfileInfoHandler : public SettingsPageUIHandler, |
| 26 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
| 27 public content::NotificationObserver, | 28 public content::NotificationObserver, |
| 28 #endif | 29 #endif |
| 29 public ProfileAttributesStorage::Observer { | 30 public ProfileAttributesStorage::Observer { |
| 30 public: | 31 public: |
| 31 static const char kProfileInfoChangedEventName[]; | 32 static const char kProfileInfoChangedEventName[]; |
| 33 static const char kProfileManagesSupervisedUsersChangedEventName[]; |
| 32 | 34 |
| 33 explicit ProfileInfoHandler(Profile* profile); | 35 explicit ProfileInfoHandler(Profile* profile); |
| 34 ~ProfileInfoHandler() override; | 36 ~ProfileInfoHandler() override; |
| 35 | 37 |
| 36 // SettingsPageUIHandler implementation. | 38 // SettingsPageUIHandler implementation. |
| 37 void RegisterMessages() override; | 39 void RegisterMessages() override; |
| 38 void OnJavascriptAllowed() override; | 40 void OnJavascriptAllowed() override; |
| 39 void OnJavascriptDisallowed() override; | 41 void OnJavascriptDisallowed() override; |
| 40 | 42 |
| 41 #if defined(OS_CHROMEOS) | 43 #if defined(OS_CHROMEOS) |
| 42 // content::NotificationObserver implementation. | 44 // content::NotificationObserver implementation. |
| 43 void Observe(int type, | 45 void Observe(int type, |
| 44 const content::NotificationSource& source, | 46 const content::NotificationSource& source, |
| 45 const content::NotificationDetails& details) override; | 47 const content::NotificationDetails& details) override; |
| 46 #endif | 48 #endif |
| 47 | 49 |
| 48 // ProfileAttributesStorage::Observer implementation. | 50 // ProfileAttributesStorage::Observer implementation. |
| 49 void OnProfileNameChanged(const base::FilePath& profile_path, | 51 void OnProfileNameChanged(const base::FilePath& profile_path, |
| 50 const base::string16& old_profile_name) override; | 52 const base::string16& old_profile_name) override; |
| 51 void OnProfileAvatarChanged(const base::FilePath& profile_path) override; | 53 void OnProfileAvatarChanged(const base::FilePath& profile_path) override; |
| 52 | 54 |
| 53 private: | 55 private: |
| 54 FRIEND_TEST_ALL_PREFIXES(ProfileInfoHandlerTest, GetProfileInfo); | 56 FRIEND_TEST_ALL_PREFIXES(ProfileInfoHandlerTest, GetProfileInfo); |
| 55 FRIEND_TEST_ALL_PREFIXES(ProfileInfoHandlerTest, PushProfileInfo); | 57 FRIEND_TEST_ALL_PREFIXES(ProfileInfoHandlerTest, PushProfileInfo); |
| 58 FRIEND_TEST_ALL_PREFIXES(ProfileInfoHandlerTest, |
| 59 GetProfileManagesSupervisedUsers); |
| 60 FRIEND_TEST_ALL_PREFIXES(ProfileInfoHandlerTest, |
| 61 PushProfileManagesSupervisedUsers); |
| 56 | 62 |
| 57 // Callbacks from the page. | 63 // Callbacks from the page. |
| 58 void HandleGetProfileInfo(const base::ListValue* args); | 64 void HandleGetProfileInfo(const base::ListValue* args); |
| 65 void HandleGetProfileManagesSupervisedUsers(const base::ListValue* args); |
| 59 | 66 |
| 60 void PushProfileInfo(); | 67 void PushProfileInfo(); |
| 61 | 68 |
| 69 // Pushes whether the current profile manages supervised users to JavaScript. |
| 70 void PushProfileManagesSupervisedUsersStatus(); |
| 71 |
| 72 // Returns true if this profile manages supervised users. |
| 73 bool IsProfileManagingSupervisedUsers() const; |
| 74 |
| 62 std::unique_ptr<base::DictionaryValue> GetAccountNameAndIcon() const; | 75 std::unique_ptr<base::DictionaryValue> GetAccountNameAndIcon() const; |
| 63 | 76 |
| 64 // Weak pointer. | 77 // Weak pointer. |
| 65 Profile* profile_; | 78 Profile* profile_; |
| 66 | 79 |
| 67 ScopedObserver<ProfileAttributesStorage, ProfileInfoHandler> | 80 ScopedObserver<ProfileAttributesStorage, ProfileInfoHandler> |
| 68 profile_observer_; | 81 profile_observer_; |
| 69 | 82 |
| 83 // Used to listen for changes in the list of managed supervised users. |
| 84 PrefChangeRegistrar profile_pref_registrar_; |
| 85 |
| 70 #if defined(OS_CHROMEOS) | 86 #if defined(OS_CHROMEOS) |
| 71 // Used to listen to ChromeOS user image changes. | 87 // Used to listen to ChromeOS user image changes. |
| 72 content::NotificationRegistrar registrar_; | 88 content::NotificationRegistrar registrar_; |
| 73 #endif | 89 #endif |
| 74 | 90 |
| 75 DISALLOW_COPY_AND_ASSIGN(ProfileInfoHandler); | 91 DISALLOW_COPY_AND_ASSIGN(ProfileInfoHandler); |
| 76 }; | 92 }; |
| 77 | 93 |
| 78 } // namespace settings | 94 } // namespace settings |
| 79 | 95 |
| 80 #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_PROFILE_INFO_HANDLER_H_ | 96 #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_PROFILE_INFO_HANDLER_H_ |
| OLD | NEW |