OLD | NEW |
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/state_store.h" | 5 #include "chrome/browser/extensions/state_store.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 for (size_t i = 0; i < pending_tasks_.size(); ++i) | 61 for (size_t i = 0; i < pending_tasks_.size(); ++i) |
62 pending_tasks_[i].Run(); | 62 pending_tasks_[i].Run(); |
63 pending_tasks_.clear(); | 63 pending_tasks_.clear(); |
64 } | 64 } |
65 | 65 |
66 StateStore::StateStore(Profile* profile, | 66 StateStore::StateStore(Profile* profile, |
67 const base::FilePath& db_path, | 67 const base::FilePath& db_path, |
68 bool deferred_load) | 68 bool deferred_load) |
69 : db_path_(db_path), task_queue_(new DelayedTaskQueue()) { | 69 : db_path_(db_path), task_queue_(new DelayedTaskQueue()) { |
70 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, | 70 registrar_.Add(this, |
| 71 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, |
71 content::Source<Profile>(profile)); | 72 content::Source<Profile>(profile)); |
72 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 73 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
73 content::Source<Profile>(profile)); | 74 content::Source<Profile>(profile)); |
74 | 75 |
75 if (deferred_load) { | 76 if (deferred_load) { |
76 // Don't Init until the first page is loaded or the session restored. | 77 // Don't Init until the first page is loaded or the session restored. |
77 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 78 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
78 content::NotificationService:: | 79 content::NotificationService:: |
79 AllBrowserContextsAndSources()); | 80 AllBrowserContextsAndSources()); |
80 registrar_.Add(this, chrome::NOTIFICATION_SESSION_RESTORE_DONE, | 81 registrar_.Add(this, chrome::NOTIFICATION_SESSION_RESTORE_DONE, |
81 content::NotificationService:: | 82 content::NotificationService:: |
82 AllBrowserContextsAndSources()); | 83 AllBrowserContextsAndSources()); |
83 } else { | 84 } else { |
84 Init(); | 85 Init(); |
85 } | 86 } |
86 } | 87 } |
87 | 88 |
88 StateStore::StateStore(Profile* profile, scoped_ptr<ValueStore> value_store) | 89 StateStore::StateStore(Profile* profile, scoped_ptr<ValueStore> value_store) |
89 : store_(value_store.Pass()), task_queue_(new DelayedTaskQueue()) { | 90 : store_(value_store.Pass()), task_queue_(new DelayedTaskQueue()) { |
90 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, | 91 registrar_.Add(this, |
| 92 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, |
91 content::Source<Profile>(profile)); | 93 content::Source<Profile>(profile)); |
92 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 94 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
93 content::Source<Profile>(profile)); | 95 content::Source<Profile>(profile)); |
94 | 96 |
95 // This constructor is for testing. No need to delay Init. | 97 // This constructor is for testing. No need to delay Init. |
96 Init(); | 98 Init(); |
97 } | 99 } |
98 | 100 |
99 StateStore::~StateStore() { | 101 StateStore::~StateStore() { |
100 } | 102 } |
(...skipping 25 matching lines...) Expand all Loading... |
126 base::Bind(&ValueStoreFrontend::Remove, base::Unretained(&store_), | 128 base::Bind(&ValueStoreFrontend::Remove, base::Unretained(&store_), |
127 GetFullKey(extension_id, key))); | 129 GetFullKey(extension_id, key))); |
128 } | 130 } |
129 | 131 |
130 bool StateStore::IsInitialized() const { return task_queue_->ready(); } | 132 bool StateStore::IsInitialized() const { return task_queue_->ready(); } |
131 | 133 |
132 void StateStore::Observe(int type, | 134 void StateStore::Observe(int type, |
133 const content::NotificationSource& source, | 135 const content::NotificationSource& source, |
134 const content::NotificationDetails& details) { | 136 const content::NotificationDetails& details) { |
135 switch (type) { | 137 switch (type) { |
136 case chrome::NOTIFICATION_EXTENSION_INSTALLED: | 138 case chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED: |
137 RemoveKeysForExtension( | 139 RemoveKeysForExtension( |
138 content::Details<const InstalledExtensionInfo>(details)->extension-> | 140 content::Details<const InstalledExtensionInfo>(details)->extension-> |
139 id()); | 141 id()); |
140 break; | 142 break; |
141 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: | 143 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: |
142 RemoveKeysForExtension( | 144 RemoveKeysForExtension( |
143 content::Details<const Extension>(details)->id()); | 145 content::Details<const Extension>(details)->id()); |
144 break; | 146 break; |
145 case chrome::NOTIFICATION_SESSION_RESTORE_DONE: | 147 case chrome::NOTIFICATION_SESSION_RESTORE_DONE: |
146 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | 148 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
(...skipping 20 matching lines...) Expand all Loading... |
167 void StateStore::RemoveKeysForExtension(const std::string& extension_id) { | 169 void StateStore::RemoveKeysForExtension(const std::string& extension_id) { |
168 for (std::set<std::string>::iterator key = registered_keys_.begin(); | 170 for (std::set<std::string>::iterator key = registered_keys_.begin(); |
169 key != registered_keys_.end(); ++key) { | 171 key != registered_keys_.end(); ++key) { |
170 task_queue_->InvokeWhenReady( | 172 task_queue_->InvokeWhenReady( |
171 base::Bind(&ValueStoreFrontend::Remove, base::Unretained(&store_), | 173 base::Bind(&ValueStoreFrontend::Remove, base::Unretained(&store_), |
172 GetFullKey(extension_id, *key))); | 174 GetFullKey(extension_id, *key))); |
173 } | 175 } |
174 } | 176 } |
175 | 177 |
176 } // namespace extensions | 178 } // namespace extensions |
OLD | NEW |