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

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

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and review changes. Created 8 years, 5 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/extension_event_router.h" 9 #include "chrome/browser/extensions/extension_event_router.h"
10 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 const char kUpdatingState[] = "Updating"; 42 const char kUpdatingState[] = "Updating";
43 const char kNeedRestartState[] = "NeedRestart"; 43 const char kNeedRestartState[] = "NeedRestart";
44 44
45 // Event names. 45 // Event names.
46 const char kOnBrightnessChanged[] = "systemPrivate.onBrightnessChanged"; 46 const char kOnBrightnessChanged[] = "systemPrivate.onBrightnessChanged";
47 const char kOnVolumeChanged[] = "systemPrivate.onVolumeChanged"; 47 const char kOnVolumeChanged[] = "systemPrivate.onVolumeChanged";
48 const char kOnScreenUnlocked[] = "systemPrivate.onScreenUnlocked"; 48 const char kOnScreenUnlocked[] = "systemPrivate.onScreenUnlocked";
49 const char kOnWokeUp[] = "systemPrivate.onWokeUp"; 49 const char kOnWokeUp[] = "systemPrivate.onWokeUp";
50 50
51 // Dispatches an extension event with |args| 51 // Dispatches an extension event with |args|
52 void DispatchEvent(const std::string& event_name, const ListValue& args) { 52 void DispatchEvent(const std::string& event_name, base::Value* argument) {
53 Profile* profile = ProfileManager::GetDefaultProfile(); 53 Profile* profile = ProfileManager::GetDefaultProfile();
54 if (!profile) 54 if (!profile)
55 return; 55 return;
56 ExtensionEventRouter* extension_event_router = 56 ExtensionEventRouter* extension_event_router =
57 profile->GetExtensionEventRouter(); 57 profile->GetExtensionEventRouter();
58 if (!extension_event_router) 58 if (!extension_event_router)
59 return; 59 return;
60 std::string json_args; 60
61 base::JSONWriter::Write(&args, &json_args); 61 base::ListValue* list_args = new base::ListValue();
miket_OOO 2012/07/10 22:33:19 Just args! They must all be the same!
62 list_args->Append(argument);
62 extension_event_router->DispatchEventToRenderers( 63 extension_event_router->DispatchEventToRenderers(
63 event_name, json_args, NULL, GURL(), extensions::EventFilteringInfo()); 64 event_name, list_args, NULL, GURL(), extensions::EventFilteringInfo());
64 } 65 }
65 66
66 } // namespace 67 } // namespace
67 68
68 namespace extensions { 69 namespace extensions {
69 70
70 bool GetIncognitoModeAvailabilityFunction::RunImpl() { 71 bool GetIncognitoModeAvailabilityFunction::RunImpl() {
71 PrefService* prefs = profile_->GetPrefs(); 72 PrefService* prefs = profile_->GetPrefs();
72 int value = prefs->GetInteger(prefs::kIncognitoModeAvailability); 73 int value = prefs->GetInteger(prefs::kIncognitoModeAvailability);
73 EXTENSION_FUNCTION_VALIDATE( 74 EXTENSION_FUNCTION_VALIDATE(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 #endif 134 #endif
134 DictionaryValue* dict = new DictionaryValue(); 135 DictionaryValue* dict = new DictionaryValue();
135 dict->SetString(kStateKey, state); 136 dict->SetString(kStateKey, state);
136 dict->SetDouble(kDownloadProgressKey, download_progress); 137 dict->SetDouble(kDownloadProgressKey, download_progress);
137 result_.reset(dict); 138 result_.reset(dict);
138 139
139 return true; 140 return true;
140 } 141 }
141 142
142 void DispatchVolumeChangedEvent(double volume, bool is_volume_muted) { 143 void DispatchVolumeChangedEvent(double volume, bool is_volume_muted) {
143 ListValue args;
144 DictionaryValue* dict = new DictionaryValue(); 144 DictionaryValue* dict = new DictionaryValue();
145 dict->SetDouble(kVolumeKey, volume); 145 dict->SetDouble(kVolumeKey, volume);
146 dict->SetBoolean(kIsVolumeMutedKey, is_volume_muted); 146 dict->SetBoolean(kIsVolumeMutedKey, is_volume_muted);
147 args.Append(dict); 147 DispatchEvent(kOnVolumeChanged, dict);
miket_OOO 2012/07/10 22:33:19 aaarrrrgs!
148 DispatchEvent(kOnVolumeChanged, args);
149 } 148 }
150 149
151 void DispatchBrightnessChangedEvent(int brightness, bool user_initiated) { 150 void DispatchBrightnessChangedEvent(int brightness, bool user_initiated) {
152 ListValue args;
153 DictionaryValue* dict = new DictionaryValue(); 151 DictionaryValue* dict = new DictionaryValue();
154 dict->SetInteger(kBrightnessKey, brightness); 152 dict->SetInteger(kBrightnessKey, brightness);
155 dict->SetBoolean(kUserInitiatedKey, user_initiated); 153 dict->SetBoolean(kUserInitiatedKey, user_initiated);
156 args.Append(dict); 154 DispatchEvent(kOnBrightnessChanged, dict);
157 DispatchEvent(kOnBrightnessChanged, args);
158 } 155 }
159 156
160 void DispatchScreenUnlockedEvent() { 157 void DispatchScreenUnlockedEvent() {
161 ListValue args; 158 DispatchEvent(kOnScreenUnlocked, NULL);
162 DispatchEvent(kOnScreenUnlocked, args);
163 } 159 }
164 160
165 void DispatchWokeUpEvent() { 161 void DispatchWokeUpEvent() {
166 ListValue args; 162 DispatchEvent(kOnWokeUp, NULL);
167 DispatchEvent(kOnWokeUp, args);
168 } 163 }
169 164
170 } // namespace extensions 165 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698