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

Unified Diff: chrome/browser/chromeos/arc/arc_settings_service.cc

Issue 2179803002: arc: Use location service consent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: discard unwanted change Created 4 years, 5 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/chromeos/arc/arc_auth_service.cc ('k') | chrome/browser/chromeos/arc/arc_support_host.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/arc/arc_settings_service.cc
diff --git a/chrome/browser/chromeos/arc/arc_settings_service.cc b/chrome/browser/chromeos/arc/arc_settings_service.cc
index 8c314d696674b442b6a38018c6fe1944a39d1a91..f4ff00f1492cc16549954cb58bbc07897ab6aebb 100644
--- a/chrome/browser/chromeos/arc/arc_settings_service.cc
+++ b/chrome/browser/chromeos/arc/arc_settings_service.cc
@@ -10,6 +10,7 @@
#include "base/json/json_writer.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
+#include "chrome/browser/chromeos/arc/arc_auth_service.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
@@ -63,7 +64,8 @@ namespace arc {
// about and sends the new values to Android to keep the state in sync.
class ArcSettingsServiceImpl
: public chromeos::system::TimezoneSettings::Observer,
- public device::BluetoothAdapter::Observer {
+ public device::BluetoothAdapter::Observer,
+ public ArcAuthService::Observer {
public:
explicit ArcSettingsServiceImpl(ArcBridgeService* arc_bridge_service);
~ArcSettingsServiceImpl() override;
@@ -72,13 +74,16 @@ class ArcSettingsServiceImpl
// Obtains the new pref value and sends it to Android.
void OnPrefChanged(const std::string& pref_name) const;
- // TimezoneSettings::Observer
+ // TimezoneSettings::Observer:
void TimezoneChanged(const icu::TimeZone& timezone) override;
- // BluetoothAdapter::Observer
+ // BluetoothAdapter::Observer:
void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
bool powered) override;
+ // ArcAuthService::Observer:
+ void OnInitialStart() override;
+
private:
// Registers to observe changes for Chrome settings we care about.
void StartObservingSettingsChanges();
@@ -86,8 +91,12 @@ class ArcSettingsServiceImpl
// Stops listening for Chrome settings changes.
void StopObservingSettingsChanges();
- // Retrives Chrome's state for the settings and send it to Android.
- void SyncAllPrefs() const;
+ // Retrieves Chrome's state for the settings that need to be synced on each
+ // Android boot and send it to Android.
+ void SyncRuntimeSettings() const;
+ // Send settings that need to be synced only on Android first start to
+ // Android.
+ void SyncInitialSettings() const;
void SyncFontSize() const;
void SyncLocale() const;
void SyncProxySettings() const;
@@ -96,6 +105,7 @@ class ArcSettingsServiceImpl
void SyncTimeZone() const;
void SyncUse24HourClock() const;
void SyncBackupEnabled() const;
+ void SyncLocationServiceEnabled() const;
void OnBluetoothAdapterInitialized(
scoped_refptr<device::BluetoothAdapter> adapter);
@@ -106,6 +116,10 @@ class ArcSettingsServiceImpl
// Returns the integer value of the pref. pref_name must exist.
int GetIntegerPref(const std::string& pref_name) const;
+ // Sends boolean pref broadcast to the delegate.
+ void SendBoolPrefSettingsBroadcast(const std::string& pref_name,
+ const std::string& action) const;
+
// Sends a broadcast to the delegate.
void SendSettingsBroadcast(const std::string& action,
const base::DictionaryValue& extras) const;
@@ -129,15 +143,20 @@ ArcSettingsServiceImpl::ArcSettingsServiceImpl(
ArcBridgeService* arc_bridge_service)
: arc_bridge_service_(arc_bridge_service), weak_factory_(this) {
StartObservingSettingsChanges();
- SyncAllPrefs();
+ SyncRuntimeSettings();
+ DCHECK(ArcAuthService::Get());
+ ArcAuthService::Get()->AddObserver(this);
}
ArcSettingsServiceImpl::~ArcSettingsServiceImpl() {
StopObservingSettingsChanges();
- if (bluetooth_adapter_) {
+ ArcAuthService* arc_auth_service = ArcAuthService::Get();
+ if (arc_auth_service)
+ arc_auth_service->RemoveObserver(this);
+
+ if (bluetooth_adapter_)
bluetooth_adapter_->RemoveObserver(this);
- }
}
void ArcSettingsServiceImpl::StartObservingSettingsChanges() {
@@ -175,7 +194,11 @@ void ArcSettingsServiceImpl::OnBluetoothAdapterInitialized(
AdapterPoweredChanged(adapter.get(), adapter->IsPowered());
}
-void ArcSettingsServiceImpl::SyncAllPrefs() const {
+void ArcSettingsServiceImpl::OnInitialStart() {
+ SyncInitialSettings();
+}
+
+void ArcSettingsServiceImpl::SyncRuntimeSettings() const {
SyncFontSize();
SyncLocale();
SyncProxySettings();
@@ -185,6 +208,11 @@ void ArcSettingsServiceImpl::SyncAllPrefs() const {
SyncUse24HourClock();
}
+void ArcSettingsServiceImpl::SyncInitialSettings() const {
+ SyncBackupEnabled();
+ SyncLocationServiceEnabled();
+}
+
void ArcSettingsServiceImpl::StopObservingSettingsChanges() {
registrar_.RemoveAll();
reporting_consent_subscription_.reset();
@@ -217,8 +245,6 @@ void ArcSettingsServiceImpl::OnPrefChanged(const std::string& pref_name) const {
SyncUse24HourClock();
} else if (pref_name == proxy_config::prefs::kProxy) {
SyncProxySettings();
- } else if (pref_name == prefs::kArcBackupRestoreEnabled) {
- SyncBackupEnabled();
Sergey Poromov 2016/08/02 15:20:41 Looks like because of removing these lines, backup
khmel 2016/08/02 16:22:44 This code does not make sense. kArcBackupRestoreEn
Sergey Poromov 2016/08/02 17:43:49 What if the pref changes after OptIn, because of p
} else {
LOG(ERROR) << "Unknown pref changed.";
}
@@ -252,17 +278,25 @@ void ArcSettingsServiceImpl::SyncFontSize() const {
extras);
}
-void ArcSettingsServiceImpl::SyncSpokenFeedbackEnabled() const {
- const PrefService::Preference* pref = registrar_.prefs()->FindPreference(
- prefs::kAccessibilitySpokenFeedbackEnabled);
+void ArcSettingsServiceImpl::SendBoolPrefSettingsBroadcast(
+ const std::string& pref_name,
+ const std::string& action) const {
+ const PrefService::Preference* pref =
+ registrar_.prefs()->FindPreference(pref_name);
DCHECK(pref);
bool enabled = false;
bool value_exists = pref->GetValue()->GetAsBoolean(&enabled);
DCHECK(value_exists);
base::DictionaryValue extras;
extras.SetBoolean("enabled", enabled);
- SendSettingsBroadcast(
- "org.chromium.arc.intent_helper.SET_SPOKEN_FEEDBACK_ENABLED", extras);
+ extras.SetBoolean("managed", !pref->IsUserModifiable());
+ SendSettingsBroadcast(action, extras);
+}
+
+void ArcSettingsServiceImpl::SyncSpokenFeedbackEnabled() const {
+ SendBoolPrefSettingsBroadcast(
+ prefs::kAccessibilitySpokenFeedbackEnabled,
+ "org.chromium.arc.intent_helper.SET_SPOKEN_FEEDBACK_ENABLED");
}
void ArcSettingsServiceImpl::SyncLocale() const {
@@ -367,17 +401,15 @@ void ArcSettingsServiceImpl::SyncProxySettings() const {
}
void ArcSettingsServiceImpl::SyncBackupEnabled() const {
- const PrefService::Preference* const pref =
- registrar_.prefs()->FindPreference(prefs::kArcBackupRestoreEnabled);
- DCHECK(pref);
- bool enabled = false;
- bool value_exists = pref->GetValue()->GetAsBoolean(&enabled);
- DCHECK(value_exists);
- base::DictionaryValue extras;
- extras.SetBoolean("enabled", enabled);
- extras.SetBoolean("managed", !pref->IsUserModifiable());
- SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_BACKUP_ENABLED",
- extras);
+ SendBoolPrefSettingsBroadcast(
+ prefs::kArcBackupRestoreEnabled,
+ "org.chromium.arc.intent_helper.SET_BACKUP_ENABLED");
+}
+
+void ArcSettingsServiceImpl::SyncLocationServiceEnabled() const {
+ SendBoolPrefSettingsBroadcast(
+ prefs::kArcLocationServiceEnabled,
+ "org.chromium.arc.intent_helper.SET_LOCATION_SERVICE_ENABLED");
}
void ArcSettingsServiceImpl::SendSettingsBroadcast(
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.cc ('k') | chrome/browser/chromeos/arc/arc_support_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698