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

Side by Side Diff: chrome/browser/extensions/api/alarms/alarm_manager.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/api/alarms/alarm_manager.h" 5 #include "chrome/browser/extensions/api/alarms/alarm_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 20 matching lines...) Expand all
31 // The minimum period between polling for alarms to run. 31 // The minimum period between polling for alarms to run.
32 const base::TimeDelta kDefaultMinPollPeriod = base::TimeDelta::FromMinutes(5); 32 const base::TimeDelta kDefaultMinPollPeriod = base::TimeDelta::FromMinutes(5);
33 33
34 class DefaultAlarmDelegate : public AlarmManager::Delegate { 34 class DefaultAlarmDelegate : public AlarmManager::Delegate {
35 public: 35 public:
36 explicit DefaultAlarmDelegate(Profile* profile) : profile_(profile) {} 36 explicit DefaultAlarmDelegate(Profile* profile) : profile_(profile) {}
37 virtual ~DefaultAlarmDelegate() {} 37 virtual ~DefaultAlarmDelegate() {}
38 38
39 virtual void OnAlarm(const std::string& extension_id, 39 virtual void OnAlarm(const std::string& extension_id,
40 const Alarm& alarm) { 40 const Alarm& alarm) {
41 ListValue args; 41 ListValue* args = new ListValue();
42 std::string json_args; 42 args->Append(alarm.js_alarm->ToValue().release());
43 args.Append(alarm.js_alarm->ToValue().release());
44 base::JSONWriter::Write(&args, &json_args);
45 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( 43 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension(
miket_OOO 2012/07/10 22:33:19 I'm guessing I'll see later on how DispatchEventTo
46 extension_id, kOnAlarmEvent, json_args, NULL, GURL()); 44 extension_id, kOnAlarmEvent, args, NULL, GURL());
47 } 45 }
48 46
49 private: 47 private:
50 Profile* profile_; 48 Profile* profile_;
51 }; 49 };
52 50
53 // Creates a TimeDelta from a delay as specified in the API. 51 // Creates a TimeDelta from a delay as specified in the API.
54 base::TimeDelta TimeDeltaFromDelay(double delay_in_minutes) { 52 base::TimeDelta TimeDeltaFromDelay(double delay_in_minutes) {
55 return base::TimeDelta::FromMicroseconds( 53 return base::TimeDelta::FromMicroseconds(
56 delay_in_minutes * base::Time::kMicrosecondsPerMinute); 54 delay_in_minutes * base::Time::kMicrosecondsPerMinute);
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 if (create_info.period_in_minutes.get()) { 377 if (create_info.period_in_minutes.get()) {
380 js_alarm->period_in_minutes.reset( 378 js_alarm->period_in_minutes.reset(
381 new double(*create_info.period_in_minutes)); 379 new double(*create_info.period_in_minutes));
382 } 380 }
383 } 381 }
384 382
385 Alarm::~Alarm() { 383 Alarm::~Alarm() {
386 } 384 }
387 385
388 } // namespace extensions 386 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698