| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
| 6 #define CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 6 #define CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/observer_list.h" |
| 13 #include "base/sequenced_task_runner_helpers.h" | 14 #include "base/sequenced_task_runner_helpers.h" |
| 14 #include "base/supports_user_data.h" | 15 #include "base/supports_user_data.h" |
| 15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 16 #include "content/public/browser/host_zoom_map.h" | 17 #include "content/public/browser/host_zoom_map.h" |
| 17 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 // HostZoomMap needs to be deleted on the UI thread because it listens | 23 // HostZoomMap needs to be deleted on the UI thread because it listens |
| (...skipping 27 matching lines...) Expand all Loading... |
| 50 void SetTemporaryZoomLevel(int render_process_id, | 51 void SetTemporaryZoomLevel(int render_process_id, |
| 51 int render_view_id, | 52 int render_view_id, |
| 52 double level); | 53 double level); |
| 53 | 54 |
| 54 // NotificationObserver implementation. | 55 // NotificationObserver implementation. |
| 55 virtual void Observe(int type, | 56 virtual void Observe(int type, |
| 56 const NotificationSource& source, | 57 const NotificationSource& source, |
| 57 const NotificationDetails& details) OVERRIDE; | 58 const NotificationDetails& details) OVERRIDE; |
| 58 | 59 |
| 59 private: | 60 private: |
| 61 friend class HostZoomMap::Observer; |
| 62 |
| 60 typedef std::map<std::string, double> HostZoomLevels; | 63 typedef std::map<std::string, double> HostZoomLevels; |
| 61 | 64 |
| 65 // Add and remove observers. Adding or removing multiple times has no effect. |
| 66 // The order in which notifications are sent to observers is undefined. |
| 67 // Clients must be sure to remove the observer before they go away. |
| 68 void AddObserver(HostZoomMap::Observer* observer); |
| 69 void RemoveObserver(HostZoomMap::Observer* observer); |
| 70 |
| 71 // A list of observers. Weak references. |
| 72 ObserverList<HostZoomMap::Observer> observers_; |
| 73 |
| 62 // Copy of the pref data, so that we can read it on the IO thread. | 74 // Copy of the pref data, so that we can read it on the IO thread. |
| 63 HostZoomLevels host_zoom_levels_; | 75 HostZoomLevels host_zoom_levels_; |
| 64 double default_zoom_level_; | 76 double default_zoom_level_; |
| 65 | 77 |
| 66 struct TemporaryZoomLevel { | 78 struct TemporaryZoomLevel { |
| 67 int render_process_id; | 79 int render_process_id; |
| 68 int render_view_id; | 80 int render_view_id; |
| 69 double zoom_level; | 81 double zoom_level; |
| 70 }; | 82 }; |
| 71 | 83 |
| 72 // Don't expect more than a couple of tabs that are using a temporary zoom | 84 // Don't expect more than a couple of tabs that are using a temporary zoom |
| 73 // level, so vector is fine for now. | 85 // level, so vector is fine for now. |
| 74 std::vector<TemporaryZoomLevel> temporary_zoom_levels_; | 86 std::vector<TemporaryZoomLevel> temporary_zoom_levels_; |
| 75 | 87 |
| 76 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and | 88 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and |
| 77 // |temporary_zoom_levels_| to guarantee thread safety. | 89 // |temporary_zoom_levels_| to guarantee thread safety. |
| 78 mutable base::Lock lock_; | 90 mutable base::Lock lock_; |
| 79 | 91 |
| 80 NotificationRegistrar registrar_; | 92 NotificationRegistrar registrar_; |
| 81 | 93 |
| 82 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); | 94 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); |
| 83 }; | 95 }; |
| 84 | 96 |
| 85 } // namespace content | 97 } // namespace content |
| 86 | 98 |
| 87 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 99 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
| OLD | NEW |