wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_HOST_ZOOM_LEVEL_CONTEXT_H_ |
| 6 | #define CONTENT_BROWSER_HOST_ZOOM_LEVEL_CONTEXT_H_ |
| 7 | |
| 8 | #include "base/macros.h" |
| 9 | #include "base/memory/ref_counted.h" |
| 10 | #include "base/memory/scoped_ptr.h" |
| 11 | #include "content/browser/host_zoom_map_impl.h" |
| 12 | #include "content/public/browser/zoom_level_delegate.h" |
| 13 | |
| 14 | class PrefService; |
| 15 | |
| 16 | namespace content { |
| 17 | struct HostZoomLevelContextDeleter; |
| 18 | |
| 19 | // This class manages a HostZoomMap and associates it with a ZoomLevelDelegate, |
| 20 | // if one is provided. It also serves to keep the zoom level machinery details |
| 21 | // separate from the owning StoragePartitionImpl. |
| 22 | class HostZoomLevelContext |
| 23 | : public base::RefCountedThreadSafe<HostZoomLevelContext, |
| 24 | HostZoomLevelContextDeleter> { |
| 25 | public: |
| 26 | explicit HostZoomLevelContext( |
| 27 | scoped_ptr<ZoomLevelDelegate> zoom_level_delegate); |
| 28 | |
| 29 | HostZoomMap* GetHostZoomMap() const { return host_zoom_map_impl_.get(); } |
| 30 | ZoomLevelDelegate* GetZoomLevelDelegate() const { |
| 31 | return zoom_level_delegate_.get(); |
| 32 | } |
| 33 | |
| 34 | protected: |
| 35 | virtual ~HostZoomLevelContext(); |
| 36 | |
| 37 | private: |
| 38 | friend class base::DeleteHelper<HostZoomLevelContext>; |
| 39 | friend class base::RefCountedThreadSafe<HostZoomLevelContext, |
| 40 | HostZoomLevelContextDeleter>; |
| 41 | friend struct HostZoomLevelContextDeleter; |
| 42 | |
| 43 | void DeleteOnCorrectThread() const; |
| 44 | |
| 45 | scoped_ptr<HostZoomMapImpl> host_zoom_map_impl_; |
| 46 | // Release the delegate before the HostZoomMap, in case it is carrying |
| 47 | // any HostZoomMap::Subscription pointers. |
| 48 | scoped_ptr<ZoomLevelDelegate> zoom_level_delegate_; |
| 49 | |
| 50 | DISALLOW_COPY_AND_ASSIGN(HostZoomLevelContext); |
| 51 | }; |
| 52 | |
| 53 | struct HostZoomLevelContextDeleter { |
| 54 | static void Destruct(const HostZoomLevelContext* context) { |
| 55 | context->DeleteOnCorrectThread(); |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | } // namespace content |
| 60 | |
| 61 | #endif // CONTENT_BROWSER_HOST_ZOOM_LEVEL_CONTEXT_H_ |