OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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_prefs_store.h" |
| 13 |
| 14 class PrefService; |
| 15 |
| 16 namespace base { |
| 17 class FilePath; |
| 18 } |
| 19 |
| 20 namespace content { |
| 21 struct HostZoomLevelContextDeleter; |
| 22 |
| 23 // This class manages a HostZoomMap and, associates it with a PrefsStore, |
| 24 // if one is provided. It also serves to keep the zoom level machinery details |
| 25 // deparate from the owning StoragePartitionImpl. |
| 26 class HostZoomLevelContext |
| 27 : public base::RefCountedThreadSafe<HostZoomLevelContext, |
| 28 HostZoomLevelContextDeleter> { |
| 29 public: |
| 30 HostZoomLevelContext(scoped_ptr<ZoomLevelPrefsStore> zoom_level_prefs, |
| 31 const base::FilePath& file_path); |
| 32 |
| 33 HostZoomMap* GetHostZoomMap() const { return host_zoom_map_impl_.get(); } |
| 34 PrefService* GetZoomLevelPrefs() { |
| 35 return zoom_level_prefs_ ? zoom_level_prefs_->GetPrefs() : NULL; |
| 36 } |
| 37 |
| 38 protected: |
| 39 virtual ~HostZoomLevelContext(); |
| 40 |
| 41 private: |
| 42 friend class base::DeleteHelper<HostZoomLevelContext>; |
| 43 friend class base::RefCountedThreadSafe<HostZoomLevelContext, |
| 44 HostZoomLevelContextDeleter>; |
| 45 friend struct HostZoomLevelContextDeleter; |
| 46 |
| 47 void DeleteOnCorrectThread() const; |
| 48 |
| 49 scoped_ptr<HostZoomMapImpl> host_zoom_map_impl_; |
| 50 // The prefs_store pointer needs to be released before the destructor for the |
| 51 // HostZoomMapImpl is called, and so must be declared in this order. |
| 52 scoped_ptr<ZoomLevelPrefsStore> zoom_level_prefs_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(HostZoomLevelContext); |
| 55 }; |
| 56 |
| 57 struct HostZoomLevelContextDeleter { |
| 58 static void Destruct(const HostZoomLevelContext* context) { |
| 59 context->DeleteOnCorrectThread(); |
| 60 } |
| 61 }; |
| 62 |
| 63 } // namespace content |
| 64 |
| 65 #endif // CONTENT_BROWSER_HOST_ZOOM_LEVEL_CONTEXT_H_ |
OLD | NEW |