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

Side by Side Diff: chrome/browser/extensions/system/system_api.cc

Issue 10911261: chromeos: Stop calling ProfileManager::GetDefaultProfile() from extension event dispatch functions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added function comments Created 8 years, 3 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 #include "chrome/browser/extensions/system/system_api.h" 5 #include "chrome/browser/extensions/system/system_api.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/event_router.h" 9 #include "chrome/browser/extensions/event_router.h"
10 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 15
15 #if defined(OS_CHROMEOS) 16 #if defined(OS_CHROMEOS)
16 #include "chromeos/dbus/dbus_thread_manager.h" 17 #include "chromeos/dbus/dbus_thread_manager.h"
17 #include "chromeos/dbus/update_engine_client.h" 18 #include "chromeos/dbus/update_engine_client.h"
18 #else 19 #else
19 #include "chrome/browser/upgrade_detector.h" 20 #include "chrome/browser/upgrade_detector.h"
(...skipping 22 matching lines...) Expand all
42 const char kUpdatingState[] = "Updating"; 43 const char kUpdatingState[] = "Updating";
43 const char kNeedRestartState[] = "NeedRestart"; 44 const char kNeedRestartState[] = "NeedRestart";
44 45
45 // Event names. 46 // Event names.
46 const char kOnBrightnessChanged[] = "systemPrivate.onBrightnessChanged"; 47 const char kOnBrightnessChanged[] = "systemPrivate.onBrightnessChanged";
47 const char kOnVolumeChanged[] = "systemPrivate.onVolumeChanged"; 48 const char kOnVolumeChanged[] = "systemPrivate.onVolumeChanged";
48 const char kOnScreenUnlocked[] = "systemPrivate.onScreenUnlocked"; 49 const char kOnScreenUnlocked[] = "systemPrivate.onScreenUnlocked";
49 const char kOnWokeUp[] = "systemPrivate.onWokeUp"; 50 const char kOnWokeUp[] = "systemPrivate.onWokeUp";
50 51
51 // Dispatches an extension event with |args| 52 // Dispatches an extension event with |args|
52 void DispatchEvent(const std::string& event_name, base::Value* argument) { 53 void DispatchEvent(Profile* profile,
53 Profile* profile = ProfileManager::GetDefaultProfile(); 54 const std::string& event_name,
54 if (!profile) 55 base::Value* argument) {
56 DCHECK(profile);
57
58 extensions::ExtensionSystem* extension_system =
59 extensions::ExtensionSystem::Get(profile);
60 if (!extension_system)
55 return; 61 return;
56 extensions::EventRouter* extension_event_router = 62 extensions::EventRouter* extension_event_router =
57 profile->GetExtensionEventRouter(); 63 extension_system->event_router();
58 if (!extension_event_router) 64 if (!extension_event_router)
59 return; 65 return;
60 66
61 scoped_ptr<base::ListValue> list_args(new base::ListValue()); 67 scoped_ptr<base::ListValue> list_args(new base::ListValue());
62 if (argument) { 68 if (argument) {
63 list_args->Append(argument); 69 list_args->Append(argument);
64 } 70 }
65 extension_event_router->DispatchEventToRenderers( 71 extension_event_router->DispatchEventToRenderers(
66 event_name, list_args.Pass(), NULL, GURL(), 72 event_name, list_args.Pass(), NULL, GURL(),
67 extensions::EventFilteringInfo()); 73 extensions::EventFilteringInfo());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 141 }
136 #endif 142 #endif
137 DictionaryValue* dict = new DictionaryValue(); 143 DictionaryValue* dict = new DictionaryValue();
138 dict->SetString(kStateKey, state); 144 dict->SetString(kStateKey, state);
139 dict->SetDouble(kDownloadProgressKey, download_progress); 145 dict->SetDouble(kDownloadProgressKey, download_progress);
140 SetResult(dict); 146 SetResult(dict);
141 147
142 return true; 148 return true;
143 } 149 }
144 150
145 void DispatchVolumeChangedEvent(double volume, bool is_volume_muted) { 151 void DispatchVolumeChangedEvent(Profile* profile,
152 double volume,
153 bool is_volume_muted) {
146 DictionaryValue* dict = new DictionaryValue(); 154 DictionaryValue* dict = new DictionaryValue();
147 dict->SetDouble(kVolumeKey, volume); 155 dict->SetDouble(kVolumeKey, volume);
148 dict->SetBoolean(kIsVolumeMutedKey, is_volume_muted); 156 dict->SetBoolean(kIsVolumeMutedKey, is_volume_muted);
149 DispatchEvent(kOnVolumeChanged, dict); 157 DispatchEvent(profile, kOnVolumeChanged, dict);
150 } 158 }
151 159
152 void DispatchBrightnessChangedEvent(int brightness, bool user_initiated) { 160 void DispatchBrightnessChangedEvent(Profile* profile,
161 int brightness,
162 bool user_initiated) {
153 DictionaryValue* dict = new DictionaryValue(); 163 DictionaryValue* dict = new DictionaryValue();
154 dict->SetInteger(kBrightnessKey, brightness); 164 dict->SetInteger(kBrightnessKey, brightness);
155 dict->SetBoolean(kUserInitiatedKey, user_initiated); 165 dict->SetBoolean(kUserInitiatedKey, user_initiated);
156 DispatchEvent(kOnBrightnessChanged, dict); 166 DispatchEvent(profile, kOnBrightnessChanged, dict);
157 } 167 }
158 168
159 void DispatchScreenUnlockedEvent() { 169 void DispatchScreenUnlockedEvent(Profile* profile) {
160 DispatchEvent(kOnScreenUnlocked, NULL); 170 DispatchEvent(profile, kOnScreenUnlocked, NULL);
161 } 171 }
162 172
163 void DispatchWokeUpEvent() { 173 void DispatchWokeUpEvent(Profile* profile) {
164 DispatchEvent(kOnWokeUp, NULL); 174 DispatchEvent(profile, kOnWokeUp, NULL);
165 } 175 }
166 176
167 } // namespace extensions 177 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698