Logo Search packages:      
Sourcecode: chromium-browser version File versions  Download package


// Copyright (c) 2010 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.

// Maps hostnames to custom zoom levels.  Written on the UI thread and read on
// any thread.  One instance per profile.


#include <map>
#include <string>

#include "base/basictypes.h"
#include "base/lock.h"
#include "base/ref_counted.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"

class PrefService;
class Profile;

class HostZoomMap : public NotificationObserver,
                    public base::RefCountedThreadSafe<HostZoomMap> {
  explicit HostZoomMap(Profile* profile);

  static void RegisterUserPrefs(PrefService* prefs);

  // Returns the zoom level for a given hostname.  In most cases, there is no
  // custom zoom level, and this returns 0.  Otherwise, returns the saved zoom
  // level, which may be positive (to zoom in) or negative (to zoom out).
  // This may be called on any thread.
  int GetZoomLevel(const std::string& host) const;

  // Sets the zoom level for a given hostname to |level|.  If the level is 0,
  // the host is erased from the saved preferences; otherwise the new value is
  // written out.
  // This should only be called on the UI thread.
  void SetZoomLevel(const std::string& host, int level);

  // Resets all zoom levels.
  // This should only be called on the UI thread.
  void ResetToDefaults();

  // NotificationObserver implementation.
  virtual void Observe(NotificationType type,
                       const NotificationSource& source,
                       const NotificationDetails& details);

  friend class base::RefCountedThreadSafe<HostZoomMap>;

  typedef std::map<std::string, int> HostZoomLevels;


  // Reads the zoom levels from the preferences service.
  void Load();

  // Removes dependencies on the profile so we can live longer than
  // the profile without crashing.
  void Shutdown();

  // The profile we're associated with.
  Profile* profile_;

  // Copy of the pref data, so that we can read it on the IO thread.
  HostZoomLevels host_zoom_levels_;

  // Used around accesses to |host_zoom_levels_| to guarantee thread safety.
  mutable Lock lock_;

  // Whether we are currently updating preferences, this is used to ignore
  // notifications from the preference service that we triggered ourself.
  bool updating_preferences_;

  NotificationRegistrar registrar_;



Generated by  Doxygen 1.6.0   Back to index