1 // Copyright (c) 2011 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_APP_LAUNCHER_LOGIN_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_APP_LAUNCHER_LOGIN_HANDLER_H_ 7 8 #include <memory> 9 10 #include "base/macros.h" 11 #include "build/build_config.h" 12 #include "content/public/browser/web_ui_message_handler.h" 13 14 class Profile; 15 class ProfileInfoWatcher; 16 17 // The login handler currently simply displays the current logged in 18 // username at the top of the NTP (and update itself when that changes). 19 // In the future it may expand to allow users to login from the NTP. 20 class AppLauncherLoginHandler : public content::WebUIMessageHandler { 21 public: 22 AppLauncherLoginHandler(); 23 ~AppLauncherLoginHandler() override; 24 25 // WebUIMessageHandler implementation: 26 void RegisterMessages() override; 27 28 // Returns true if the login handler should be shown in a new tab page 29 // for the given |profile|. |profile| must not be NULL. 30 static bool ShouldShow(Profile* profile); 31 32 private: 33 // User actions while on the NTP when clicking on or viewing the sync promo. 34 enum NTPSignInPromoBuckets { 35 NTP_SIGN_IN_PROMO_VIEWED, 36 NTP_SIGN_IN_PROMO_CLICKED, 37 NTP_SIGN_IN_PROMO_BUCKET_BOUNDARY, 38 }; 39 40 // Called from JS when the NTP is loaded. |args| is the list of arguments 41 // passed from JS and should be an empty list. 42 void HandleInitializeSyncLogin(const base::ListValue* args); 43 44 #if !defined(OS_CHROMEOS) 45 // Called from JS when the user clicks the login container. It shows the 46 // appropriate UI based on the current sync state. |args| is the list of 47 // arguments passed from JS and should be an empty list. 48 void HandleShowSyncLoginUI(const base::ListValue* args); 49 #endif 50 51 // Records actions in SyncPromo.NTPPromo histogram. 52 void RecordInHistogram(NTPSignInPromoBuckets type); 53 54 // Internal helper method 55 void UpdateLogin(); 56 57 // Watches this web UI's profile for info changes (e.g. authenticated username 58 // changes). 59 std::unique_ptr<ProfileInfoWatcher> profile_info_watcher_; 60 61 DISALLOW_COPY_AND_ASSIGN(AppLauncherLoginHandler); 62 }; 63 64 #endif // CHROME_BROWSER_UI_WEBUI_APP_LAUNCHER_LOGIN_HANDLER_H_ 65