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

Side by Side Diff: chrome/browser/host_zoom_map.cc

Issue 437077: Remember zoom on a per-host basis.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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
« no previous file with comments | « chrome/browser/host_zoom_map.h ('k') | chrome/browser/net/chrome_url_request_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 #include "chrome/browser/host_zoom_map.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/chrome_thread.h"
9 #include "chrome/browser/profile.h"
10 #include "chrome/common/pref_names.h"
11 #include "chrome/common/pref_service.h"
12
13 HostZoomMap::HostZoomMap(Profile* profile) : profile_(profile) {
14 const DictionaryValue* host_zoom_dictionary =
15 profile_->GetPrefs()->GetDictionary(prefs::kPerHostZoomLevels);
16 // Careful: The returned value could be NULL if the pref has never been set.
17 if (host_zoom_dictionary != NULL) {
18 for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys());
19 i != host_zoom_dictionary->end_keys(); ++i) {
20 std::wstring wide_host(*i);
21 int zoom_level = 0;
22 bool success = host_zoom_dictionary->GetIntegerWithoutPathExpansion(
23 wide_host, &zoom_level);
24 DCHECK(success);
25 host_zoom_levels_[WideToUTF8(wide_host)] = zoom_level;
26 }
27 }
28 }
29
30 // static
31 void HostZoomMap::RegisterUserPrefs(PrefService* prefs) {
32 prefs->RegisterDictionaryPref(prefs::kPerHostZoomLevels);
33 }
34
35 int HostZoomMap::GetZoomLevel(const std::string& host) const {
36 AutoLock auto_lock(lock_);
37 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host));
38 return (i == host_zoom_levels_.end()) ? 0 : i->second;
39 }
40
41 void HostZoomMap::SetZoomLevel(const std::string& host, int level) {
42 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
43 if (host.empty())
44 return;
45
46 {
47 AutoLock auto_lock(lock_);
48 if (level == 0)
49 host_zoom_levels_.erase(host);
50 else
51 host_zoom_levels_[host] = level;
52 }
53
54 // Persist new zoom level if we're not off the record.
55 if (!profile_->IsOffTheRecord()) {
56 DictionaryValue* host_zoom_dictionary =
57 profile_->GetPrefs()->GetMutableDictionary(prefs::kPerHostZoomLevels);
58 std::wstring wide_host(UTF8ToWide(host));
59 if (level == 0) {
60 host_zoom_dictionary->RemoveWithoutPathExpansion(wide_host, NULL);
61 } else {
62 host_zoom_dictionary->SetWithoutPathExpansion(wide_host,
63 Value::CreateIntegerValue(level));
64 }
65 }
66 }
67
68 HostZoomMap::~HostZoomMap() {
69 }
OLDNEW
« no previous file with comments | « chrome/browser/host_zoom_map.h ('k') | chrome/browser/net/chrome_url_request_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698