1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_PROFILE_PICKER_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_SIGNIN_PROFILE_PICKER_HANDLER_H_ 7 8 #include "base/memory/weak_ptr.h" 9 #include "base/time/time.h" 10 #include "base/values.h" 11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile_attributes_storage.h" 13 #include "chrome/browser/profiles/profile_statistics_common.h" 14 #include "content/public/browser/web_contents_observer.h" 15 #include "content/public/browser/web_ui_message_handler.h" 16 17 // The handler for Javascript messages related to the profile picker main view. 18 class ProfilePickerHandler : public content::WebUIMessageHandler, 19 public content::WebContentsObserver, 20 public ProfileAttributesStorage::Observer { 21 public: 22 ProfilePickerHandler(); 23 ~ProfilePickerHandler() override; 24 25 // Enables the startup performance metrics. Should only be called when the 26 // profile picker is shown on startup. 27 void EnableStartupMetrics(); 28 29 // content::WebUIMessageHandler: 30 void RegisterMessages() override; 31 void OnJavascriptAllowed() override; 32 void OnJavascriptDisallowed() override; 33 34 private: 35 void HandleMainViewInitialize(const base::ListValue* args); 36 void HandleLaunchSelectedProfile(bool open_settings, 37 const base::ListValue* args); 38 void HandleLaunchGuestProfile(const base::ListValue* args); 39 void HandleAskOnStartupChanged(const base::ListValue* args); 40 void HandleRemoveProfile(const base::ListValue* args); 41 void HandleGetProfileStatistics(const base::ListValue* args); 42 43 // TODO(crbug.com/1115056): Move to new handler for profile creation. 44 void HandleLoadSignInProfileCreationFlow(const base::ListValue* args); 45 void HandleGetNewProfileSuggestedThemeInfo(const base::ListValue* args); 46 void HandleGetProfileThemeInfo(const base::ListValue* args); 47 void HandleCreateProfile(const base::ListValue* args); 48 49 void OnLoadSigninFailed(); 50 void GatherProfileStatistics(Profile* profile); 51 void OnProfileStatisticsReceived(base::FilePath profile_path, 52 profiles::ProfileCategoryStats result); 53 void OnSwitchToProfileComplete(bool new_profile, 54 bool open_settings, 55 Profile* profile, 56 Profile::CreateStatus profile_create_status); 57 void OnProfileCreated(base::Optional<SkColor> profile_color, 58 bool create_shortcut, 59 Profile* profile, 60 Profile::CreateStatus status); 61 void OnProfileCreationSuccess(base::Optional<SkColor> profile_color, 62 bool create_shortcut, 63 Profile* profile); 64 void PushProfilesList(); 65 base::Value GetProfilesList(); 66 67 // ProfileAttributesStorage::Observer: 68 void OnProfileAdded(const base::FilePath& profile_path) override; 69 void OnProfileWasRemoved(const base::FilePath& profile_path, 70 const base::string16& profile_name) override; 71 void OnProfileAvatarChanged(const base::FilePath& profile_path) override; 72 void OnProfileHighResAvatarLoaded( 73 const base::FilePath& profile_path) override; 74 void OnProfileNameChanged(const base::FilePath& profile_path, 75 const base::string16& old_profile_name) override; 76 77 // content::WebContentsObserver: 78 void DidFirstVisuallyNonEmptyPaint() override; 79 void OnVisibilityChanged(content::Visibility visibility) override; 80 81 // Creation time of the handler, to measure performance on startup. Only set 82 // when the picker is shown on startup. 83 base::TimeTicks creation_time_on_startup_; 84 bool main_view_initialized_ = false; 85 86 base::WeakPtrFactory<ProfilePickerHandler> weak_factory_{this}; 87 88 DISALLOW_COPY_AND_ASSIGN(ProfilePickerHandler); 89 }; 90 91 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_PROFILE_PICKER_HANDLER_H_ 92