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

Side by Side Diff: chrome/browser/chromeos/accessibility/magnification_manager.cc

Issue 11194011: Reverting this CL because it was committed before I gave the final LGTM. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
6
7 #include "ash/magnifier/magnification_controller.h"
8 #include "ash/shell.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/singleton.h"
11 #include "chrome/browser/api/prefs/pref_change_registrar.h"
12 #include "chrome/browser/api/prefs/pref_member.h"
13 #include "chrome/browser/chromeos/login/user_manager.h"
14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/pref_names.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_service.h"
23
24 namespace chromeos {
25
26 class MagnificationManagerImpl : public MagnificationManager,
27 public content::NotificationObserver {
28 public:
29 MagnificationManagerImpl() {
30 DCHECK(!instance_);
31 instance_ = this;
32
33 registrar_.Add(this,
34 chrome::NOTIFICATION_SESSION_STARTED,
35 content::NotificationService::AllSources());
36 registrar_.Add(this,
37 chrome::NOTIFICATION_PROFILE_CREATED,
38 content::NotificationService::AllSources());
39 registrar_.Add(this,
40 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE,
41 content::NotificationService::AllSources());
42
43 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
44 SetProfile(profile);
45 }
46 virtual ~MagnificationManagerImpl() {}
47
48 static MagnificationManagerImpl* GetInstance() {
49 return instance_;
50 }
51
52 // MagnificationManager implimentation:
53 bool IsEnabled() OVERRIDE {
54 return ash::Shell::GetInstance()->magnification_controller()->IsEnabled();
55 }
56
57 void SetEnabled(bool enabled) OVERRIDE {
58 ash::Shell::GetInstance()->magnification_controller()->SetEnabled(enabled);
59 }
60
61 private:
62 void SetProfile(Profile* profile) {
63 if (pref_change_registrar_) {
64 pref_change_registrar_->Remove(prefs::kScreenMagnifierEnabled, this);
65 pref_change_registrar_.reset();
66 }
67
68 if (profile) {
69 pref_change_registrar_.reset(new PrefChangeRegistrar);
70 pref_change_registrar_->Init(profile->GetPrefs());
71 pref_change_registrar_->Add(prefs::kScreenMagnifierEnabled, this);
72 }
73
74 profile_ = profile;
75 UpdateMagnifierStatus();
76 }
77
78 void UpdateMagnifierStatus() {
79 UserManager* manager = UserManager::Get();
80 if (!profile_) {
81 SetEnabled(false);
82 } else if (manager && !manager->IsSessionStarted()) {
83 SetEnabled(true);
84 } else {
85 PrefService* pref_service = profile_->GetPrefs();
86 bool enabled = pref_service->GetBoolean(prefs::kScreenMagnifierEnabled);
87 SetEnabled(enabled);
88 }
89 }
90
91 // content::NotificationObserver implimentation:
92 virtual void Observe(int type,
93 const content::NotificationSource& source,
94 const content::NotificationDetails& details) OVERRIDE {
95 switch (type) {
96 case chrome::NOTIFICATION_PREF_CHANGED: {
97 std::string pref = *content::Details<std::string>(details).ptr();
98 if (pref == prefs::kScreenMagnifierEnabled)
99 UpdateMagnifierStatus();
100 break;
101 }
102 case chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE:
103 case chrome::NOTIFICATION_SESSION_STARTED: {
104 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
105 SetProfile(profile);
106 break;
107 }
108 }
109 }
110
111 static MagnificationManagerImpl* instance_;
112
113 Profile* profile_;
114 content::NotificationRegistrar registrar_;
115 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
116
117 friend struct DefaultSingletonTraits<MagnificationManagerImpl>;
118 DISALLOW_COPY_AND_ASSIGN(MagnificationManagerImpl);
119 };
120
121 MagnificationManagerImpl* MagnificationManagerImpl::instance_ = NULL;
122
123 MagnificationManager* MagnificationManager::GetInstance() {
124 return MagnificationManagerImpl::GetInstance();
125 }
126
127 MagnificationManager* MagnificationManager::CreateInstance() {
128 // Makes sure that this is not called more than once.
129 CHECK(!GetInstance());
130
131 return new MagnificationManagerImpl();
132 }
133
134 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698