Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: content/public/browser/host_zoom_map.h

Issue 9416070: Move creation and ownership of HostZoomMap to content instead of having every embedder do this. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ 5 #ifndef CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_
6 #define CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ 6 #define CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/memory/ref_counted.h"
15 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
16 #include "content/public/browser/browser_thread.h"
17 15
18 namespace content { 16 namespace content {
19 17
18 class BrowserContext;
19 class ResourceContext;
20
20 // Maps hostnames to custom zoom levels. Written on the UI thread and read on 21 // Maps hostnames to custom zoom levels. Written on the UI thread and read on
21 // any thread. One instance per browser context. Must be created on the UI 22 // any thread. One instance per browser context. Must be created on the UI
22 // thread, and it'll delete itself on the UI thread as well. 23 // thread, and it'll delete itself on the UI thread as well.
23 class HostZoomMap 24 class HostZoomMap {
24 : public base::RefCountedThreadSafe<
25 HostZoomMap, content::BrowserThread::DeleteOnUIThread> {
26 public: 25 public:
27 CONTENT_EXPORT static HostZoomMap* Create(); 26 CONTENT_EXPORT static HostZoomMap* GetForBrowserContext(
27 BrowserContext* browser_context);
28 CONTENT_EXPORT static HostZoomMap* GetForResourceContext(
29 ResourceContext* resource_context);
28 30
29 // Copy the zoom levels from the given map. Can only be called on the UI 31 // Copy the zoom levels from the given map. Can only be called on the UI
30 // thread. 32 // thread.
31 virtual void CopyFrom(HostZoomMap* copy) = 0; 33 virtual void CopyFrom(HostZoomMap* copy) = 0;
32 34
33 // Returns the zoom level for the host or spec for a given url. The zoom 35 // Returns the zoom level for the host or spec for a given url. The zoom
34 // level is determined by the host portion of the URL, or (in the absence of 36 // level is determined by the host portion of the URL, or (in the absence of
35 // a host) the complete spec of the URL. In most cases, there is no custom 37 // a host) the complete spec of the URL. In most cases, there is no custom
36 // zoom level, and this returns the user's default zoom level. Otherwise, 38 // zoom level, and this returns the user's default zoom level. Otherwise,
37 // returns the saved zoom level, which may be positive (to zoom in) or 39 // returns the saved zoom level, which may be positive (to zoom in) or
38 // negative (to zoom out). 40 // negative (to zoom out).
39 // 41 //
40 // This may be called on any thread. 42 // This may be called on any thread.
41 virtual double GetZoomLevel(const std::string& host) const = 0; 43 virtual double GetZoomLevel(const std::string& host) const = 0;
42 44
43 // Sets the zoom level for the host or spec for a given url to |level|. If 45 // Sets the zoom level for the host or spec for a given url to |level|. If
44 // the level matches the current default zoom level, the host is erased 46 // the level matches the current default zoom level, the host is erased
45 // from the saved preferences; otherwise the new value is written out. 47 // from the saved preferences; otherwise the new value is written out.
46 // 48 //
47 // This should only be called on the UI thread. 49 // This should only be called on the UI thread.
48 virtual void SetZoomLevel(std::string host, double level) = 0; 50 virtual void SetZoomLevel(std::string host, double level) = 0;
49 51
50 // Get/Set the default zoom level for pages that don't override it. 52 // Get/Set the default zoom level for pages that don't override it.
51 virtual double GetDefaultZoomLevel() const = 0; 53 virtual double GetDefaultZoomLevel() const = 0;
52 virtual void SetDefaultZoomLevel(double level) = 0;; 54 virtual void SetDefaultZoomLevel(double level) = 0;;
53 55
54 protected: 56 protected:
55 virtual ~HostZoomMap() {} 57 virtual ~HostZoomMap() {}
56
57 private:
58 friend class base::RefCountedThreadSafe<
59 HostZoomMap, content::BrowserThread::DeleteOnUIThread>;
60 friend struct content::BrowserThread::DeleteOnThread<
61 content::BrowserThread::UI>;
62 friend class base::DeleteHelper<HostZoomMap>;
63 }; 58 };
64 59
65 } // namespace content 60 } // namespace content
66 61
67 #endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ 62 #endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698