12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/gesture_prefs_observer_factory_aura.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector>
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/bind.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/bind_helpers.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_change_registrar.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h"
147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chrome_notification_types.h"
15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/profiles/incognito_helpers.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h"
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/content/browser_context_dependency_manager.h"
19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/pref_registry/pref_registry_syncable.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/notification_service.h"
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/overscroll_configuration.h"
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/common/renderer_preferences.h"
2468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ui/events/gestures/gesture_configuration.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using ui::GestureConfiguration;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct OverscrollPref {
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const char* pref_name;
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::OverscrollConfig config;
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const std::vector<OverscrollPref>& GetOverscrollPrefs() {
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CR_DEFINE_STATIC_LOCAL(std::vector<OverscrollPref>, overscroll_prefs, ());
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (overscroll_prefs.empty()) {
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    using namespace content;
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const OverscrollPref kOverscrollPrefs[] = {
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      { prefs::kOverscrollHorizontalThresholdComplete,
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE },
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      { prefs::kOverscrollVerticalThresholdComplete,
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        OVERSCROLL_CONFIG_VERT_THRESHOLD_COMPLETE },
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      { prefs::kOverscrollMinimumThresholdStart,
45424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN },
46424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      { prefs::kOverscrollMinimumThresholdStartTouchpad,
47424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD },
4858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch      { prefs::kOverscrollVerticalThresholdStart,
4958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch        OVERSCROLL_CONFIG_VERT_THRESHOLD_START },
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      { prefs::kOverscrollHorizontalResistThreshold,
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        OVERSCROLL_CONFIG_HORIZ_RESIST_AFTER },
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      { prefs::kOverscrollVerticalResistThreshold,
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        OVERSCROLL_CONFIG_VERT_RESIST_AFTER },
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    };
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    overscroll_prefs.assign(kOverscrollPrefs,
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                            kOverscrollPrefs + arraysize(kOverscrollPrefs));
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return overscroll_prefs;
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This class manages gesture configuration preferences.
62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class GesturePrefsObserver : public KeyedService {
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit GesturePrefsObserver(PrefService* prefs);
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~GesturePrefsObserver();
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
67a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // KeyedService implementation.
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Shutdown() OVERRIDE;
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Notification callback invoked when browser-side preferences
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // are updated and need to be pushed into ui::GesturePreferences.
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Update();
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Notification callback invoked when the fling deacceleration
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // gesture preferences are changed from chrome://gesture.
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Broadcasts the changes all renderers where they are used.
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void Notify();
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Notification helper to push overscroll preferences into
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // content.
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void UpdateOverscrollPrefs();
83b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PrefChangeRegistrar registrar_;
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PrefService* prefs_;
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(GesturePrefsObserver);
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The list of prefs we want to observe.
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Note that this collection of settings should correspond to the settings used
9268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// in ui/events/gestures/gesture_configuration.h
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char* kPrefsToObserve[] = {
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  prefs::kFlingMaxCancelToDownTimeInMs,
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  prefs::kFlingMaxTapGapTimeInMs,
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  prefs::kTabScrubActivationDelayInMS,
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  prefs::kMaxSeparationForGestureTouchesInPixels,
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  prefs::kSemiLongPressTimeInSeconds,
992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciconst char* kPrefsToRemove[] = {
1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    "gesture.fling_acceleration_curve_coefficient_0",
1031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    "gesture.fling_acceleration_curve_coefficient_1",
1041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    "gesture.fling_acceleration_curve_coefficient_2",
1051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    "gesture.fling_acceleration_curve_coefficient_3",
1061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    "flingcurve.touchpad_alpha",
1071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    "flingcurve.touchpad_beta",
1081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    "flingcurve.touchpad_gamma",
1091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    "flingcurve.touchscreen_alpha",
1101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    "flingcurve.touchscreen_beta",
1111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    "flingcurve.touchscreen_gamma",
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GesturePrefsObserver::GesturePrefsObserver(PrefService* prefs)
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : prefs_(prefs) {
1161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  for (size_t i = 0; i < arraysize(kPrefsToRemove); ++i) {
1171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    if (prefs->FindPreference(kPrefsToRemove[i]))
1181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      prefs->ClearPref(kPrefsToRemove[i]);
1191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
1201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  registrar_.Init(prefs);
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  registrar_.RemoveAll();
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::Closure callback = base::Bind(&GesturePrefsObserver::Update,
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      base::Unretained(this));
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::Closure notify_callback = base::Bind(&GesturePrefsObserver::Notify,
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                             base::Unretained(this));
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (size_t i = 0; i < arraysize(kPrefsToObserve); ++i)
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    registrar_.Add(kPrefsToObserve[i], callback);
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const std::vector<OverscrollPref>& overscroll_prefs = GetOverscrollPrefs();
1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (size_t i = 0; i < overscroll_prefs.size(); ++i)
1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    registrar_.Add(overscroll_prefs[i].pref_name, callback);
1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Update();
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GesturePrefsObserver::~GesturePrefsObserver() {}
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void GesturePrefsObserver::Shutdown() {
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  registrar_.RemoveAll();
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void GesturePrefsObserver::Update() {
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  GestureConfiguration::set_fling_max_cancel_to_down_time_in_ms(
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      prefs_->GetInteger(prefs::kFlingMaxCancelToDownTimeInMs));
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  GestureConfiguration::set_fling_max_tap_gap_time_in_ms(
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      prefs_->GetInteger(prefs::kFlingMaxTapGapTimeInMs));
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  GestureConfiguration::set_tab_scrub_activation_delay_in_ms(
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      prefs_->GetInteger(prefs::kTabScrubActivationDelayInMS));
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GestureConfiguration::set_semi_long_press_time_in_seconds(
1531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      prefs_->GetDouble(prefs::kSemiLongPressTimeInSeconds));
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GestureConfiguration::set_max_separation_for_gesture_touches_in_pixels(
1551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      prefs_->GetDouble(prefs::kMaxSeparationForGestureTouchesInPixels));
1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  UpdateOverscrollPrefs();
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void GesturePrefsObserver::UpdateOverscrollPrefs() {
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const std::vector<OverscrollPref>& overscroll_prefs = GetOverscrollPrefs();
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (size_t i = 0; i < overscroll_prefs.size(); ++i) {
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    content::SetOverscrollConfig(overscroll_prefs[i].config,
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        static_cast<float>(prefs_->GetDouble(overscroll_prefs[i].pref_name)));
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void GesturePrefsObserver::Notify() {
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Must do a notify to distribute the changes to all renderers.
1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::NotificationService* service =
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      content::NotificationService::current();
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  service->Notify(chrome::NOTIFICATION_BROWSER_FLING_CURVE_PARAMETERS_CHANGED,
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  content::Source<GesturePrefsObserver>(this),
1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  content::NotificationService::NoDetails());
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GesturePrefsObserverFactoryAura*
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GesturePrefsObserverFactoryAura::GetInstance() {
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return Singleton<GesturePrefsObserverFactoryAura>::get();
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GesturePrefsObserverFactoryAura::GesturePrefsObserverFactoryAura()
18690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    : BrowserContextKeyedServiceFactory(
18790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        "GesturePrefsObserverAura",
18890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        BrowserContextDependencyManager::GetInstance()) {}
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GesturePrefsObserverFactoryAura::~GesturePrefsObserverFactoryAura() {}
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
192a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)KeyedService* GesturePrefsObserverFactoryAura::BuildServiceInstanceFor(
193c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    content::BrowserContext* profile) const {
194c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return new GesturePrefsObserver(static_cast<Profile*>(profile)->GetPrefs());
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void GesturePrefsObserverFactoryAura::RegisterOverscrollPrefs(
198c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    user_prefs::PrefRegistrySyncable* registry) {
1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const std::vector<OverscrollPref>& overscroll_prefs = GetOverscrollPrefs();
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (size_t i = 0; i < overscroll_prefs.size(); ++i) {
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    registry->RegisterDoublePref(
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        overscroll_prefs[i].pref_name,
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        content::GetOverscrollConfig(overscroll_prefs[i].config),
205c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid GesturePrefsObserverFactoryAura::RegisterProfilePrefs(
210c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    user_prefs::PrefRegistrySyncable* registry) {
2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  registry->RegisterIntegerPref(
2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      prefs::kFlingMaxCancelToDownTimeInMs,
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      GestureConfiguration::fling_max_cancel_to_down_time_in_ms(),
214c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  registry->RegisterIntegerPref(
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      prefs::kFlingMaxTapGapTimeInMs,
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      GestureConfiguration::fling_max_tap_gap_time_in_ms(),
218c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  registry->RegisterIntegerPref(
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      prefs::kTabScrubActivationDelayInMS,
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      GestureConfiguration::tab_scrub_activation_delay_in_ms(),
222c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  registry->RegisterDoublePref(
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      prefs::kSemiLongPressTimeInSeconds,
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GestureConfiguration::semi_long_press_time_in_seconds(),
226c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  registry->RegisterDoublePref(
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      prefs::kMaxSeparationForGestureTouchesInPixels,
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GestureConfiguration::max_separation_for_gesture_touches_in_pixels(),
230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RegisterOverscrollPrefs(registry);
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
23490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)bool
23590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)GesturePrefsObserverFactoryAura::ServiceIsCreatedWithBrowserContext() const {
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create the observer as soon as the profile is created.
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
240c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)content::BrowserContext*
241c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)GesturePrefsObserverFactoryAura::GetBrowserContextToUse(
242c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    content::BrowserContext* context) const {
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Use same gesture preferences on incognito windows.
244c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return chrome::GetBrowserContextRedirectedInIncognito(context);
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool GesturePrefsObserverFactoryAura::ServiceIsNULLWhileTesting() const {
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Some tests replace the PrefService of the TestingProfile after the
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // GesturePrefsObserver has been created, which makes Shutdown()
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // remove the registrar from a non-existent PrefService.
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
253