OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extension_gcm_app_handler.h" | 5 #include "chrome/browser/extensions/extension_gcm_app_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // handler. This is because there might be a built-in app handler, like | 123 // handler. This is because there might be a built-in app handler, like |
124 // GCMAccountMapper, which is automatically added and removed by | 124 // GCMAccountMapper, which is automatically added and removed by |
125 // GCMDriverDesktop. | 125 // GCMDriverDesktop. |
126 // | 126 // |
127 // Also note that the GCM message routing will not be interruptted during | 127 // Also note that the GCM message routing will not be interruptted during |
128 // the update process since unloading and reloading extension are done in | 128 // the update process since unloading and reloading extension are done in |
129 // the single function ExtensionService::AddExtension. | 129 // the single function ExtensionService::AddExtension. |
130 AddDummyAppHandler(); | 130 AddDummyAppHandler(); |
131 | 131 |
132 base::ThreadTaskRunnerHandle::Get()->PostTask( | 132 base::ThreadTaskRunnerHandle::Get()->PostTask( |
133 FROM_HERE, base::Bind(&ExtensionGCMAppHandler::RemoveDummyAppHandler, | 133 FROM_HERE, |
134 weak_factory_.GetWeakPtr())); | 134 base::BindOnce(&ExtensionGCMAppHandler::RemoveDummyAppHandler, |
| 135 weak_factory_.GetWeakPtr())); |
135 } | 136 } |
136 | 137 |
137 // When the extention is being uninstalled, it will be unloaded first. We | 138 // When the extention is being uninstalled, it will be unloaded first. We |
138 // should not remove the app handler in this case and it will be handled | 139 // should not remove the app handler in this case and it will be handled |
139 // in OnExtensionUninstalled. | 140 // in OnExtensionUninstalled. |
140 if (reason != UnloadedExtensionInfo::REASON_UNINSTALL) | 141 if (reason != UnloadedExtensionInfo::REASON_UNINSTALL) |
141 RemoveAppHandler(extension->id()); | 142 RemoveAppHandler(extension->id()); |
142 } | 143 } |
143 | 144 |
144 void ExtensionGCMAppHandler::OnExtensionUninstalled( | 145 void ExtensionGCMAppHandler::OnExtensionUninstalled( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 GetGCMDriver()->Unregister( | 184 GetGCMDriver()->Unregister( |
184 app_id, | 185 app_id, |
185 base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted, | 186 base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted, |
186 weak_factory_.GetWeakPtr(), | 187 weak_factory_.GetWeakPtr(), |
187 app_id)); | 188 app_id)); |
188 | 189 |
189 // InstanceIDDriver::RemoveInstanceID will delete the InstanceID itself. | 190 // InstanceIDDriver::RemoveInstanceID will delete the InstanceID itself. |
190 // Postpone to do it outside this calling context to avoid any risk to | 191 // Postpone to do it outside this calling context to avoid any risk to |
191 // the caller. | 192 // the caller. |
192 base::ThreadTaskRunnerHandle::Get()->PostTask( | 193 base::ThreadTaskRunnerHandle::Get()->PostTask( |
193 FROM_HERE, base::Bind(&ExtensionGCMAppHandler::RemoveInstanceID, | 194 FROM_HERE, base::BindOnce(&ExtensionGCMAppHandler::RemoveInstanceID, |
194 weak_factory_.GetWeakPtr(), app_id)); | 195 weak_factory_.GetWeakPtr(), app_id)); |
195 } | 196 } |
196 | 197 |
197 void ExtensionGCMAppHandler::RemoveInstanceID(const std::string& app_id) { | 198 void ExtensionGCMAppHandler::RemoveInstanceID(const std::string& app_id) { |
198 GetInstanceIDDriver()->RemoveInstanceID(app_id); | 199 GetInstanceIDDriver()->RemoveInstanceID(app_id); |
199 } | 200 } |
200 | 201 |
201 void ExtensionGCMAppHandler::AddAppHandler(const std::string& app_id) { | 202 void ExtensionGCMAppHandler::AddAppHandler(const std::string& app_id) { |
202 GetGCMDriver()->AddAppHandler(app_id, this); | 203 GetGCMDriver()->AddAppHandler(app_id, this); |
203 } | 204 } |
204 | 205 |
205 void ExtensionGCMAppHandler::RemoveAppHandler(const std::string& app_id) { | 206 void ExtensionGCMAppHandler::RemoveAppHandler(const std::string& app_id) { |
206 GetGCMDriver()->RemoveAppHandler(app_id); | 207 GetGCMDriver()->RemoveAppHandler(app_id); |
207 } | 208 } |
208 | 209 |
209 } // namespace extensions | 210 } // namespace extensions |
OLD | NEW |