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

Side by Side Diff: chrome/browser/extensions/api/alarms/alarm_manager.cc

Issue 171813010: Move ProfileKeyedAPI implementations to take BrowserContext in the constructor (part 1). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: browser_context_ Created 6 years, 10 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/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 21 matching lines...) Expand all
32 const char kRegisteredAlarms[] = "alarms"; 32 const char kRegisteredAlarms[] = "alarms";
33 const char kAlarmGranularity[] = "granularity"; 33 const char kAlarmGranularity[] = "granularity";
34 34
35 // The minimum period between polling for alarms to run. 35 // The minimum period between polling for alarms to run.
36 const base::TimeDelta kDefaultMinPollPeriod() { 36 const base::TimeDelta kDefaultMinPollPeriod() {
37 return base::TimeDelta::FromDays(1); 37 return base::TimeDelta::FromDays(1);
38 } 38 }
39 39
40 class DefaultAlarmDelegate : public AlarmManager::Delegate { 40 class DefaultAlarmDelegate : public AlarmManager::Delegate {
41 public: 41 public:
42 explicit DefaultAlarmDelegate(Profile* profile) : profile_(profile) {} 42 explicit DefaultAlarmDelegate(content::BrowserContext* context)
43 : browser_context_(context) {}
43 virtual ~DefaultAlarmDelegate() {} 44 virtual ~DefaultAlarmDelegate() {}
44 45
45 virtual void OnAlarm(const std::string& extension_id, 46 virtual void OnAlarm(const std::string& extension_id,
46 const Alarm& alarm) OVERRIDE { 47 const Alarm& alarm) OVERRIDE {
47 scoped_ptr<base::ListValue> args(new base::ListValue()); 48 scoped_ptr<base::ListValue> args(new base::ListValue());
48 args->Append(alarm.js_alarm->ToValue().release()); 49 args->Append(alarm.js_alarm->ToValue().release());
49 scoped_ptr<Event> event(new Event(alarms::OnAlarm::kEventName, 50 scoped_ptr<Event> event(new Event(alarms::OnAlarm::kEventName,
50 args.Pass())); 51 args.Pass()));
51 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( 52 ExtensionSystem::Get(browser_context_)
52 extension_id, event.Pass()); 53 ->event_router()
54 ->DispatchEventToExtension(extension_id, event.Pass());
53 } 55 }
54 56
55 private: 57 private:
56 Profile* profile_; 58 content::BrowserContext* browser_context_;
57 }; 59 };
58 60
59 // Creates a TimeDelta from a delay as specified in the API. 61 // Creates a TimeDelta from a delay as specified in the API.
60 base::TimeDelta TimeDeltaFromDelay(double delay_in_minutes) { 62 base::TimeDelta TimeDeltaFromDelay(double delay_in_minutes) {
61 return base::TimeDelta::FromMicroseconds( 63 return base::TimeDelta::FromMicroseconds(
62 delay_in_minutes * base::Time::kMicrosecondsPerMinute); 64 delay_in_minutes * base::Time::kMicrosecondsPerMinute);
63 } 65 }
64 66
65 std::vector<Alarm> AlarmsFromValue(const base::ListValue* list) { 67 std::vector<Alarm> AlarmsFromValue(const base::ListValue* list) {
66 std::vector<Alarm> alarms; 68 std::vector<Alarm> alarms;
(...skipping 21 matching lines...) Expand all
88 list->Append(alarm.release()); 90 list->Append(alarm.release());
89 } 91 }
90 return list.Pass(); 92 return list.Pass();
91 } 93 }
92 94
93 95
94 } // namespace 96 } // namespace
95 97
96 // AlarmManager 98 // AlarmManager
97 99
98 AlarmManager::AlarmManager(Profile* profile) 100 AlarmManager::AlarmManager(content::BrowserContext* context)
99 : profile_(profile), 101 : profile_(Profile::FromBrowserContext(context)),
100 clock_(new base::DefaultClock()), 102 clock_(new base::DefaultClock()),
101 delegate_(new DefaultAlarmDelegate(profile)) { 103 delegate_(new DefaultAlarmDelegate(context)) {
102 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 104 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
103 content::Source<Profile>(profile_)); 105 content::Source<Profile>(profile_));
104 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 106 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
105 content::Source<Profile>(profile_)); 107 content::Source<Profile>(profile_));
106 108
107 StateStore* storage = ExtensionSystem::Get(profile_)->state_store(); 109 StateStore* storage = ExtensionSystem::Get(profile_)->state_store();
108 if (storage) 110 if (storage)
109 storage->RegisterKey(kRegisteredAlarms); 111 storage->RegisterKey(kRegisteredAlarms);
110 } 112 }
111 113
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 if (create_info.period_in_minutes.get()) { 478 if (create_info.period_in_minutes.get()) {
477 js_alarm->period_in_minutes.reset( 479 js_alarm->period_in_minutes.reset(
478 new double(*create_info.period_in_minutes)); 480 new double(*create_info.period_in_minutes));
479 } 481 }
480 } 482 }
481 483
482 Alarm::~Alarm() { 484 Alarm::~Alarm() {
483 } 485 }
484 486
485 } // namespace extensions 487 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/alarms/alarm_manager.h ('k') | chrome/browser/extensions/api/api_resource_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698