-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Nearby] Add 'Clear Prefs' button to chrome://nearby-internals.
Adds a 'Clear Prefs' button to the logging tab of chrome://nearby-internals, as follows: https://screenshot.googleplex.com/Sq39758XDgUw8NE which resets the Nearby feature, as follows: 1. before: https://screenshot.googleplex.com/7WoBN4GYggS5UPf, https://screenshot.googleplex.com/6ERnEmwWJCzEwYm 2. after: https://screenshot.googleplex.com/jaVKuB9nLrqFYfd and adds a log message to notify users that the prefs have been cleared. (cherry picked from commit 4c1213c) Fixed: 1147242 Change-Id: Ib666124b0c63df66eace9a8a0af26da8670cbccf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2817842 Commit-Queue: Juliet Levesque <julietlevesque@google.com> Reviewed-by: Josh Nohle <nohle@chromium.org> Reviewed-by: James Vecore <vecore@google.com> Cr-Original-Commit-Position: refs/heads/master@{#871501} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2826156 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Cr-Commit-Position: refs/branch-heads/4472@{#83} Cr-Branched-From: 3d60439-refs/heads/master@{#870763}
- Loading branch information
1 parent
e5e3646
commit bd892bb
Showing
8 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
chrome/browser/resources/nearby_internals/nearby_prefs_browser_proxy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import {addSingletonGetter} from 'chrome://resources/js/cr.m.js'; | ||
|
||
/** | ||
* JavaScript hooks into the native WebUI handler to communicate with C++ about | ||
* Nearby prefs. | ||
*/ | ||
export class NearbyPrefsBrowserProxy { | ||
/** | ||
* Tells C++ side to clear Nearby Prefs. | ||
*/ | ||
clearNearbyPrefs() { | ||
chrome.send('clearNearbyPrefs'); | ||
} | ||
} | ||
|
||
addSingletonGetter(NearbyPrefsBrowserProxy); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
chrome/browser/ui/webui/nearby_internals/nearby_internals_prefs_handler.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/webui/nearby_internals/nearby_internals_prefs_handler.h" | ||
#include "base/bind.h" | ||
#include "chrome/browser/nearby_sharing/common/nearby_share_prefs.h" | ||
#include "chrome/browser/nearby_sharing/logging/logging.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
|
||
namespace { | ||
|
||
const char kNearbySharingPrefPrefix[] = "nearby_sharing"; | ||
|
||
} // namespace | ||
|
||
NearbyInternalsPrefsHandler::NearbyInternalsPrefsHandler( | ||
content::BrowserContext* context) { | ||
Profile* profile = Profile::FromBrowserContext(context); | ||
pref_service_ = profile->GetPrefs(); | ||
} | ||
|
||
NearbyInternalsPrefsHandler::~NearbyInternalsPrefsHandler() = default; | ||
|
||
void NearbyInternalsPrefsHandler::RegisterMessages() { | ||
web_ui()->RegisterMessageCallback( | ||
"clearNearbyPrefs", | ||
base::BindRepeating(&NearbyInternalsPrefsHandler::HandleClearNearbyPrefs, | ||
base::Unretained(this))); | ||
} | ||
|
||
void NearbyInternalsPrefsHandler::OnJavascriptAllowed() {} | ||
|
||
void NearbyInternalsPrefsHandler::OnJavascriptDisallowed() {} | ||
|
||
void NearbyInternalsPrefsHandler::HandleClearNearbyPrefs( | ||
const base::ListValue* args) { | ||
// Turn Nearby feature off. | ||
pref_service_->SetBoolean(prefs::kNearbySharingEnabledPrefName, false); | ||
|
||
// Clear all Nearby related prefs. | ||
pref_service_->ClearPrefsWithPrefixSilently(kNearbySharingPrefPrefix); | ||
|
||
// Add log message so users who trigger the Clear Pref button on | ||
// chrome://nearby-internals know that the Nearby prefs have been cleared. | ||
NS_LOG(INFO) | ||
<< "Nearby Share has been disabled and Nearby prefs have been cleared."; | ||
} |
40 changes: 40 additions & 0 deletions
40
chrome/browser/ui/webui/nearby_internals/nearby_internals_prefs_handler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
#ifndef CHROME_BROWSER_UI_WEBUI_NEARBY_INTERNALS_NEARBY_INTERNALS_PREFS_HANDLER_H_ | ||
#define CHROME_BROWSER_UI_WEBUI_NEARBY_INTERNALS_NEARBY_INTERNALS_PREFS_HANDLER_H_ | ||
|
||
#include "base/memory/weak_ptr.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "content/public/browser/web_ui_message_handler.h" | ||
|
||
namespace content { | ||
class BrowserContext; | ||
} // namespace content | ||
|
||
// WebUIMessageHandler for Nearby Prefs to allow users to Clear Prefs from the | ||
// chrome://nearby-internals logging tab. | ||
class NearbyInternalsPrefsHandler : public content::WebUIMessageHandler { | ||
public: | ||
explicit NearbyInternalsPrefsHandler(content::BrowserContext* context); | ||
NearbyInternalsPrefsHandler(const NearbyInternalsPrefsHandler&) = delete; | ||
NearbyInternalsPrefsHandler& operator=(const NearbyInternalsPrefsHandler&) = | ||
delete; | ||
~NearbyInternalsPrefsHandler() override; | ||
|
||
// content::WebUIMessageHandler | ||
void RegisterMessages() override; | ||
void OnJavascriptAllowed() override; | ||
void OnJavascriptDisallowed() override; | ||
|
||
private: | ||
// Message handler callback that clears Nearby prefs in order to put the user | ||
// back into a state of before they have touched the feature. | ||
void HandleClearNearbyPrefs(const base::ListValue* args); | ||
|
||
PrefService* pref_service_ = nullptr; | ||
|
||
base::WeakPtrFactory<NearbyInternalsPrefsHandler> weak_ptr_factory_{this}; | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_WEBUI_NEARBY_INTERNALS_NEARBY_INTERNALS_PREFS_HANDLER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters