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

Unified Diff: chrome/browser/ui/webui/welcome_win10_handler.cc

Issue 2633743002: Add GetIsPinnedToTaskbarState() (Closed)
Patch Set: Created 3 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/welcome_win10_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/welcome_win10_handler.cc
diff --git a/chrome/browser/ui/webui/welcome_win10_handler.cc b/chrome/browser/ui/webui/welcome_win10_handler.cc
index 95124b556aba29591fcb0457bfa4471573422847..ad7b50390553149964ead4cdd816860e0664b2a2 100644
--- a/chrome/browser/ui/webui/welcome_win10_handler.cc
+++ b/chrome/browser/ui/webui/welcome_win10_handler.cc
@@ -5,16 +5,15 @@
#include "chrome/browser/ui/webui/welcome_win10_handler.h"
#include "base/bind.h"
-#include "base/memory/ptr_util.h"
+#include "base/values.h"
#include "chrome/browser/shell_integration.h"
+#include "chrome/browser/shell_integration_win.h"
#include "chrome/common/url_constants.h"
-#include "chrome/grit/generated_resources.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
-#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
-WelcomeWin10Handler::WelcomeWin10Handler() {
+WelcomeWin10Handler::WelcomeWin10Handler() : weak_ptr_factory_(this) {
// The check is started as early as possible because waiting for the page to
// be fully loaded is unnecessarily wasting time.
StartIsPinnedToTaskbarCheck();
@@ -53,7 +52,9 @@ void WelcomeWin10Handler::HandleGetPinnedToTaskbarState(
}
// Only wait for a small amount of time for the result. If the timer fires,
- // it will be assumed that Chrome is pinned to the taskbar.
+ // it will be assumed that Chrome is pinned to the taskbar. This is to make
+ // sure the instructions are never displayed in case it was impossible to
+ // determine the pinned state.
constexpr base::TimeDelta kPinnedToTaskbarTimeout =
base::TimeDelta::FromMilliseconds(200);
timer_.Start(FROM_HERE, kPinnedToTaskbarTimeout,
@@ -75,34 +76,32 @@ void WelcomeWin10Handler::HandleContinue(const base::ListValue* args) {
}
void WelcomeWin10Handler::StartIsPinnedToTaskbarCheck() {
- // Start the utility process that will handle the IsPinnedToTaskbar() call.
- client_ =
- base::MakeUnique<content::UtilityProcessMojoClient<mojom::ShellHandler>>(
- l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_SHELL_HANDLER_NAME));
-
// Assume that Chrome is pinned to the taskbar if an error occurs.
- client_->set_error_callback(
+ base::Closure error_callback =
base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined,
- base::Unretained(this), true));
- client_->set_disable_sandbox();
- client_->Start();
+ weak_ptr_factory_.GetWeakPtr(), true);
- client_->service()->IsPinnedToTaskbar(base::Bind(
- &WelcomeWin10Handler::OnIsPinnedToTaskbarResult, base::Unretained(this)));
+ shell_integration::win::GetIsPinnedToTaskbarState(
+ error_callback,
+ base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarResult,
+ weak_ptr_factory_.GetWeakPtr()));
}
void WelcomeWin10Handler::OnIsPinnedToTaskbarResult(bool succeeded,
bool is_pinned_to_taskbar) {
- OnIsPinnedToTaskbarDetermined(succeeded && is_pinned_to_taskbar);
+ // Assume that Chrome is pinned to the taskbar if an error occured.
+ OnIsPinnedToTaskbarDetermined(!succeeded || is_pinned_to_taskbar);
}
void WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined(
bool is_pinned_to_taskbar) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- // Reset the client and the timer to make sure this function only gets called
- // once.
- client_.reset();
+ // Early exit if the pinned_state was already determined.
+ if (pinned_state_result_)
+ return;
+
+ // Stop the timer if it's still running.
timer_.Stop();
pinned_state_result_ = is_pinned_to_taskbar;
« no previous file with comments | « chrome/browser/ui/webui/welcome_win10_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698