Chromium Code Reviews| 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_WELCOME_WIN10_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_WELCOME_WIN10_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_WELCOME_WIN10_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_WELCOME_WIN10_HANDLER_H_ |
| 7 | 7 |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 8 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/optional.h" | |
| 13 #include "base/timer/timer.h" | |
| 14 #include "chrome/common/shell_handler_win.mojom.h" | |
| 15 #include "content/public/browser/utility_process_mojo_client.h" | |
| 9 #include "content/public/browser/web_ui_message_handler.h" | 16 #include "content/public/browser/web_ui_message_handler.h" |
| 10 | 17 |
| 11 namespace base { | 18 namespace base { |
| 12 class ListValue; | 19 class ListValue; |
| 13 } | 20 } |
| 14 | 21 |
| 15 // Handles actions on the Windows 10 specific Welcome page. | 22 // Handles actions on the Windows 10 specific Welcome page. |
| 16 class WelcomeWin10Handler : public content::WebUIMessageHandler { | 23 class WelcomeWin10Handler : public content::WebUIMessageHandler { |
| 17 public: | 24 public: |
| 18 WelcomeWin10Handler(); | 25 WelcomeWin10Handler(); |
| 19 ~WelcomeWin10Handler() override; | 26 ~WelcomeWin10Handler() override; |
| 20 | 27 |
| 21 // content::WebUIMessageHandler: | 28 // content::WebUIMessageHandler: |
| 22 void RegisterMessages() override; | 29 void RegisterMessages() override; |
| 23 | 30 |
| 24 private: | 31 private: |
| 32 // Handlers for javascript calls. | |
| 33 void HandleGetPinnedToTaskbarState(const base::ListValue* args); | |
| 25 void HandleSetDefaultBrowser(const base::ListValue* args); | 34 void HandleSetDefaultBrowser(const base::ListValue* args); |
| 26 void HandleContinue(const base::ListValue* args); | 35 void HandleContinue(const base::ListValue* args); |
| 27 | 36 |
| 37 void StartIsPinnedToTaskbarCheck(); | |
| 38 | |
| 39 // Callback for mojom::ShellHandler's call to IsPinnedToTaskbar(). | |
| 40 void OnIsPinnedToTaskbarResult(bool succeeded, bool is_pinned_to_taskbar); | |
| 41 | |
| 42 // Sets the internal result and optionally call | |
| 43 // SendPinnedToTaskbarStateResult() in the case that | |
| 44 // |pinned_state_callback_id_| is not empty. | |
| 45 void OnIsPinnedToTaskbarDetermined(bool is_pinned_to_taskbar); | |
| 46 | |
| 47 // Returns the result to the getPinnedToTaskbarState() javascript call via the | |
| 48 // promise. | |
| 49 void SendPinnedToTaskbarStateResult(); | |
| 50 | |
| 51 std::unique_ptr<content::UtilityProcessMojoClient<mojom::ShellHandler>> | |
| 52 client_; | |
| 53 base::OneShotTimer timer_; | |
| 54 | |
| 55 // Acts as a cache to hold the taskbar pinned state of Chrome. It has no value | |
| 56 // until this state is determined. | |
| 57 base::Optional<bool> pinned_state_result_; | |
|
tmartino
2016/10/28 21:44:15
Any meaningful race conditions between the JS hand
Patrick Monette
2016/10/29 00:59:12
It's all happening on the same thread. I added dch
| |
| 58 | |
| 59 // The callback id used to return the result to the getPinnedToTaskbarState() | |
| 60 // javascript call. This id is empty until we receive the call; thus this | |
| 61 // variable is used to determine if the result should be sent to the caller | |
| 62 // when it is received, or wait for the call to happen. | |
| 63 std::string pinned_state_callback_id_; | |
| 64 | |
| 28 DISALLOW_COPY_AND_ASSIGN(WelcomeWin10Handler); | 65 DISALLOW_COPY_AND_ASSIGN(WelcomeWin10Handler); |
| 29 }; | 66 }; |
| 30 | 67 |
| 31 #endif // CHROME_BROWSER_UI_WEBUI_WELCOME_WIN10_HANDLER_H_ | 68 #endif // CHROME_BROWSER_UI_WEBUI_WELCOME_WIN10_HANDLER_H_ |
| OLD | NEW |