| 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 21 matching lines...) Expand all Loading... |
| 32 DelayedTaskQueue() : ready_(false) {} | 32 DelayedTaskQueue() : ready_(false) {} |
| 33 ~DelayedTaskQueue() {} | 33 ~DelayedTaskQueue() {} |
| 34 | 34 |
| 35 // Queues up a task for invoking once we're ready. Invokes immediately if | 35 // Queues up a task for invoking once we're ready. Invokes immediately if |
| 36 // we're already ready. | 36 // we're already ready. |
| 37 void InvokeWhenReady(base::Closure task); | 37 void InvokeWhenReady(base::Closure task); |
| 38 | 38 |
| 39 // Marks us ready, and invokes all pending tasks. | 39 // Marks us ready, and invokes all pending tasks. |
| 40 void SetReady(); | 40 void SetReady(); |
| 41 | 41 |
| 42 // Return whether or not the DelayedTaskQueue is |ready_|. | |
| 43 bool ready() const { return ready_; } | |
| 44 | |
| 45 private: | 42 private: |
| 46 bool ready_; | 43 bool ready_; |
| 47 std::vector<base::Closure> pending_tasks_; | 44 std::vector<base::Closure> pending_tasks_; |
| 48 }; | 45 }; |
| 49 | 46 |
| 50 void StateStore::DelayedTaskQueue::InvokeWhenReady(base::Closure task) { | 47 void StateStore::DelayedTaskQueue::InvokeWhenReady(base::Closure task) { |
| 51 if (ready_) { | 48 if (ready_) { |
| 52 task.Run(); | 49 task.Run(); |
| 53 } else { | 50 } else { |
| 54 pending_tasks_.push_back(task); | 51 pending_tasks_.push_back(task); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 GetFullKey(extension_id, key), base::Passed(&value))); | 117 GetFullKey(extension_id, key), base::Passed(&value))); |
| 121 } | 118 } |
| 122 | 119 |
| 123 void StateStore::RemoveExtensionValue(const std::string& extension_id, | 120 void StateStore::RemoveExtensionValue(const std::string& extension_id, |
| 124 const std::string& key) { | 121 const std::string& key) { |
| 125 task_queue_->InvokeWhenReady( | 122 task_queue_->InvokeWhenReady( |
| 126 base::Bind(&ValueStoreFrontend::Remove, base::Unretained(&store_), | 123 base::Bind(&ValueStoreFrontend::Remove, base::Unretained(&store_), |
| 127 GetFullKey(extension_id, key))); | 124 GetFullKey(extension_id, key))); |
| 128 } | 125 } |
| 129 | 126 |
| 130 bool StateStore::IsInitialized() const { return task_queue_->ready(); } | |
| 131 | |
| 132 void StateStore::Observe(int type, | 127 void StateStore::Observe(int type, |
| 133 const content::NotificationSource& source, | 128 const content::NotificationSource& source, |
| 134 const content::NotificationDetails& details) { | 129 const content::NotificationDetails& details) { |
| 135 switch (type) { | 130 switch (type) { |
| 136 case chrome::NOTIFICATION_EXTENSION_INSTALLED: | 131 case chrome::NOTIFICATION_EXTENSION_INSTALLED: |
| 137 RemoveKeysForExtension( | 132 RemoveKeysForExtension( |
| 138 content::Details<const InstalledExtensionInfo>(details)->extension-> | 133 content::Details<const InstalledExtensionInfo>(details)->extension-> |
| 139 id()); | 134 id()); |
| 140 break; | 135 break; |
| 141 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: | 136 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 167 void StateStore::RemoveKeysForExtension(const std::string& extension_id) { | 162 void StateStore::RemoveKeysForExtension(const std::string& extension_id) { |
| 168 for (std::set<std::string>::iterator key = registered_keys_.begin(); | 163 for (std::set<std::string>::iterator key = registered_keys_.begin(); |
| 169 key != registered_keys_.end(); ++key) { | 164 key != registered_keys_.end(); ++key) { |
| 170 task_queue_->InvokeWhenReady( | 165 task_queue_->InvokeWhenReady( |
| 171 base::Bind(&ValueStoreFrontend::Remove, base::Unretained(&store_), | 166 base::Bind(&ValueStoreFrontend::Remove, base::Unretained(&store_), |
| 172 GetFullKey(extension_id, *key))); | 167 GetFullKey(extension_id, *key))); |
| 173 } | 168 } |
| 174 } | 169 } |
| 175 | 170 |
| 176 } // namespace extensions | 171 } // namespace extensions |
| OLD | NEW |